WIP: add missing handlers, services nd repositories
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
@@ -49,8 +50,12 @@ func NewMediaLoFiRepository(db *bun.DB) *MediaLoFiRepository {
|
||||
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)
|
||||
err := repository.db.NewSelect().Model(&lofis).Scan(context)
|
||||
if err != nil {
|
||||
slog.Info(err.Error())
|
||||
return nil, echo.ErrInternalServerError
|
||||
}
|
||||
slog.Info("MediaLoFiRepository#FindAll", "count", len(lofis))
|
||||
|
||||
return lofis, nil
|
||||
}
|
||||
@@ -58,11 +63,12 @@ func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]model
|
||||
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())
|
||||
err := repository.db.NewSelect().Model(&lofi).Where("id = ?", id).Scan(context)
|
||||
if err != nil {
|
||||
slog.Info("MediaLoFiRepository#GetById", "error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return &lofi, result.Error
|
||||
return &lofi, err
|
||||
}
|
||||
|
||||
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (*models.MediaLoFi, error) {
|
||||
@@ -117,11 +123,10 @@ func (repository *MediaLoFiRepository) Update(context context.Context, update mo
|
||||
}
|
||||
|
||||
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())
|
||||
_, err := repository.db.NewDelete().Model((*models.MediaLoFi)(nil)).Where("id = ?", id).Exec(context)
|
||||
if err != nil {
|
||||
slog.Info("MediaLoFiRepository#Delete", "error", err.Error())
|
||||
}
|
||||
return result.Error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user