package repository import ( "context" "kontor-api-gin/internal/models" "log/slog" "gorm.io/gorm" ) type SportRepository struct { db *gorm.DB } func NewSportRepository(db *gorm.DB) *SportRepository { repo := &SportRepository{db: db} return repo } func (repository *SportRepository) FindAll(page int, limit int, context context.Context) (sports []models.Sport, total int64, err error) { offset := (page - 1) * limit err = repository.db. Model(&models.Sport{}). Count(&total). Limit(limit). Offset(offset). Order("id asc"). Find(&sports).Error if err != nil { return } slog.Info("SportRepository#FindAll", "total", total) return } func (repository *SportRepository) GetById(context context.Context, id string) (models.Sport, error) { var sport = models.Sport{ID: id} slog.Info("SportRepository#GetById", "id", id) result := repository.db.First(&sport) if result.Error != nil { slog.Info("SportRepository#GetById", "error", result.Error.Error()) } return sport, result.Error }