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