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