This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user