ms-tester/internal/languages/repository/pg_repository.go

29 lines
652 B
Go
Raw Normal View History

2024-10-09 18:55:16 +00:00
package repository
import (
"context"
"git.sch9.ru/new_gate/models"
"git.sch9.ru/new_gate/ms-tester/pkg/utils"
"github.com/jmoiron/sqlx"
"go.uber.org/zap"
)
type LanguageRepository struct {
db *sqlx.DB
logger *zap.Logger
}
func NewLanguageRepository(db *sqlx.DB, logger *zap.Logger) *LanguageRepository {
return &LanguageRepository{
db: db,
logger: logger,
}
}
func (r *LanguageRepository) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
if id <= int32(len(models.Languages)) {
return nil, utils.StorageError(nil, utils.ErrNotFound, "languages not found")
}
return &models.Languages[id], nil
}