This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kontor-api-gin/internal/models"
|
||||
"log/slog"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type RoosterRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewRoosterRepository(db *gorm.DB) *RoosterRepository {
|
||||
repo := &RoosterRepository{db: db}
|
||||
return repo
|
||||
}
|
||||
|
||||
func (repository *RoosterRepository) FindAll(context context.Context) ([]models.Rooster, error) {
|
||||
var roosters []models.Rooster
|
||||
|
||||
result := repository.db.Find(&roosters)
|
||||
slog.Info("RoosterRepository#FindAll", "count", result.RowsAffected)
|
||||
|
||||
return roosters, nil
|
||||
}
|
||||
|
||||
func (repository *RoosterRepository) GetById(context context.Context, id string) (models.Rooster, error) {
|
||||
var rooster = models.Rooster{ID: id}
|
||||
slog.Info("RoosterRepository#GetById", "id", id)
|
||||
result := repository.db.First(&rooster)
|
||||
if result.Error != nil {
|
||||
slog.Info("RoosterRepository#GetById", "error", result.Error.Error())
|
||||
}
|
||||
return rooster, result.Error
|
||||
}
|
||||
Reference in New Issue
Block a user