Files
kontor/kontor-gin/internal/repository/sport.go
T
Thomas Peetz 980eda29af
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
add tests for repository
2026-10-06 17:11:42 +02:00

46 lines
1015 B
Go

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
}