ms-tester/internal/storage/language.go
Vyacheslav1557 81e75e5a9c fix:
2024-10-05 21:05:29 +05:00

29 lines
638 B
Go

package storage
import (
"context"
"git.sch9.ru/new_gate/models"
"git.sch9.ru/new_gate/ms-tester/internal/lib"
"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,
}
}
func (storage *LanguageStorage) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
if id <= int32(len(models.Languages)) {
return nil, lib.StorageError(nil, lib.ErrNotFound, "language not found")
}
return &models.Languages[id], nil
}