28 lines
499 B
Go
28 lines
499 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type BookRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewBookRepository(db *gorm.DB) *BookRepository {
|
|
repo := &BookRepository{db: db}
|
|
return repo
|
|
}
|
|
|
|
func (repository *BookRepository) FindAll(context context.Context) ([]models.Book, error) {
|
|
var books []models.Book
|
|
|
|
result := repository.db.Find(&books)
|
|
slog.Info("BookRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return books, nil
|
|
}
|