29 lines
652 B
Go
29 lines
652 B
Go
|
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
|
||
|
}
|