bc88c694ee
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de> Reviewed-on: #97
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type MediaFileRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewMediaFileRepository(db *gorm.DB) *MediaFileRepository {
|
|
repo := &MediaFileRepository{db: db}
|
|
return repo
|
|
}
|
|
|
|
func (repository *MediaFileRepository) FindAll(context context.Context) ([]models.MediaFile, error) {
|
|
var files []models.MediaFile
|
|
|
|
result := repository.db.Find(&files)
|
|
slog.Info("MediaFileRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return files, nil
|
|
}
|
|
|
|
func (repository *MediaFileRepository) GetById(context context.Context, id string) (*models.MediaFile, error) {
|
|
var file = models.MediaFile{ID: id}
|
|
slog.Info("MediaFileRepository#GetById", "id", id)
|
|
result := repository.db.First(&file)
|
|
if result.Error != nil {
|
|
slog.Info("MediaFileRepository#GetById", "error", result.Error.Error())
|
|
return nil, result.Error
|
|
}
|
|
return &file, result.Error
|
|
}
|
|
|
|
func (repository *MediaFileRepository) Add(context context.Context, url string) (*models.MediaFile, error) {
|
|
slog.Info("MediaFileRepository#Add", "url", url)
|
|
return nil, fmt.Errorf("unimplemented method MediaFileRepository#Add")
|
|
}
|
|
|
|
func (repository *MediaFileRepository) Delete(context context.Context, id string) error {
|
|
var file = models.MediaFile{ID: id}
|
|
slog.Info("MediaFileRepository#Delete", "id", id)
|
|
result := repository.db.Delete(&file)
|
|
if result.Error != nil {
|
|
slog.Info("MediaFileRepository#Delete", "error", result.Error.Error())
|
|
}
|
|
return result.Error
|
|
}
|