2024-08-18 14:04:33 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-08-25 16:52:00 +00:00
|
|
|
"git.sch9.ru/new_gate/ms-tester/pkg/models"
|
2024-08-25 13:13:57 +00:00
|
|
|
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
2024-08-18 14:04:33 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LanguageStorage struct {
|
|
|
|
db *sqlx.DB
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLanguageStorage(db *sqlx.DB, logger *zap.Logger) *LanguageStorage {
|
|
|
|
return &LanguageStorage{
|
|
|
|
db: db,
|
|
|
|
logger: logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-25 16:20:14 +00:00
|
|
|
func (storage *LanguageStorage) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
|
|
|
|
if(id<=int32(len(models.Languages))) {
|
2024-08-25 13:13:57 +00:00
|
|
|
return nil,lib.StorageError(nil,lib.ErrNotFound,"language not found")
|
|
|
|
}
|
2024-08-25 16:20:14 +00:00
|
|
|
return &models.Languages[id], nil
|
2024-08-18 14:04:33 +00:00
|
|
|
}
|