54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type MediaActorRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewMediaActorRepository(db *gorm.DB) *MediaActorRepository {
|
|
repo := &MediaActorRepository{db: db}
|
|
return repo
|
|
}
|
|
|
|
func (repository *MediaActorRepository) FindAll(context context.Context) ([]models.MediaActor, error) {
|
|
var actors []models.MediaActor
|
|
|
|
result := repository.db.Find(&actors)
|
|
slog.Info("MediaActorRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return actors, nil
|
|
}
|
|
|
|
func (repository *MediaActorRepository) GetById(context context.Context, id string) (*models.MediaActor, error) {
|
|
var actor = models.MediaActor{ID: id}
|
|
slog.Info("MediaActorRepository#GetById", "id", id)
|
|
result := repository.db.First(&actor)
|
|
if result.Error != nil {
|
|
slog.Info("SportRepository#GetById", "error", result.Error.Error())
|
|
}
|
|
return &actor, result.Error
|
|
}
|
|
|
|
func (repository *MediaActorRepository) Add(context context.Context, url string) (*models.MediaActor, error) {
|
|
slog.Info("MediaActorRepository#Add", "url", url)
|
|
return nil, fmt.Errorf("unimplemented method MediaFileRepository#Add")
|
|
}
|
|
|
|
func (repository *MediaActorRepository) Delete(context context.Context, id string) error {
|
|
var actor = models.MediaActor{ID: id}
|
|
slog.Info("MediaActorRepository#Delete", "id", id)
|
|
result := repository.db.Delete(&actor)
|
|
if result.Error != nil {
|
|
slog.Info("SportRepository#Delete", "error", result.Error.Error())
|
|
}
|
|
return result.Error
|
|
}
|