53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type MediaLoFiRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewMediaLoFiRepository(db *gorm.DB) *MediaLoFiRepository {
|
|
repo := &MediaLoFiRepository{db: db}
|
|
return repo
|
|
}
|
|
|
|
func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]models.MediaLoFi, error) {
|
|
var lofis []models.MediaLoFi
|
|
|
|
result := repository.db.Find(&lofis)
|
|
slog.Info("MediaLoFiRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return lofis, nil
|
|
}
|
|
|
|
func (repository *MediaLoFiRepository) GetById(context context.Context, id string) (models.MediaLoFi, error) {
|
|
var lofi = models.MediaLoFi{ID: id}
|
|
slog.Info("MediaLoFiRepository#GetById", "id", id)
|
|
result := repository.db.First(&lofi)
|
|
if result.Error != nil {
|
|
slog.Info("MediaLoFiRepository#GetById", "error", result.Error.Error())
|
|
}
|
|
return lofi, result.Error
|
|
}
|
|
|
|
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (models.MediaLoFi, error) {
|
|
slog.Info("MediaLoFiRepository#Add", "url", url)
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (repository *MediaLoFiRepository) Delete(context context.Context, id string) error {
|
|
var actor = models.MediaLoFi{ID: id}
|
|
slog.Info("MediaLoFiRepository#Delete", "id", id)
|
|
result := repository.db.Delete(&actor)
|
|
if result.Error != nil {
|
|
slog.Info("MediaLoFiRepository#Delete", "error", result.Error.Error())
|
|
}
|
|
return result.Error
|
|
}
|