Files
kontor/kontor-gin/internal/repository/sport.go
T

38 lines
864 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(context context.Context) ([]models.Sport, error) {
var sports []models.Sport
result := repository.db.Find(&sports)
slog.Info("SportRepository#FindAll", "count", result.RowsAffected)
return sports, nil
}
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
}