completed adding MediaLofi for kontor-gin
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
@@ -2,9 +2,14 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"kontor-api-gin/internal/models"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -26,19 +31,51 @@ func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]model
|
||||
return lofis, nil
|
||||
}
|
||||
|
||||
func (repository *MediaLoFiRepository) GetById(context context.Context, id string) (models.MediaLoFi, error) {
|
||||
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
|
||||
return &lofi, result.Error
|
||||
}
|
||||
|
||||
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (models.MediaLoFi, error) {
|
||||
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (*models.MediaLoFi, error) {
|
||||
slog.Info("MediaLoFiRepository#Add", "url", url)
|
||||
panic("unimplemented")
|
||||
webLink := helpers.StripUrl(url, "v")
|
||||
var lofi models.MediaLoFi
|
||||
search_result := repository.db.Where("url = ?", webLink).First(&lofi)
|
||||
if search_result.RowsAffected > 0 {
|
||||
slog.Info("search for existing url", "result", search_result, "lofi", lofi)
|
||||
return &lofi, nil
|
||||
}
|
||||
if errors.Is(search_result.Error, gorm.ErrRecordNotFound) {
|
||||
slog.Info("MediaLoFiRepository#Add URL not found", "url", webLink)
|
||||
lofi = models.MediaLoFi{
|
||||
ID: uuid.NewString(),
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
DeletedAt: nil,
|
||||
Version: 0,
|
||||
WebLink: webLink,
|
||||
ShouldDownload: false,
|
||||
Review: true,
|
||||
Title: "",
|
||||
FileName: "",
|
||||
}
|
||||
add_result := repository.db.Create(&lofi)
|
||||
if add_result.Error != nil {
|
||||
slog.Info("add new MediaLofi", "error", add_result.Error)
|
||||
return nil, add_result.Error
|
||||
}
|
||||
slog.Info("add new MediaLofi", "lofi", lofi)
|
||||
return &lofi, nil
|
||||
}
|
||||
if search_result.Error != nil {
|
||||
return nil, search_result.Error
|
||||
}
|
||||
return nil, fmt.Errorf("MediaLoFiRepository#Add unknown error")
|
||||
}
|
||||
|
||||
func (repository *MediaLoFiRepository) Delete(context context.Context, id string) error {
|
||||
|
||||
Reference in New Issue
Block a user