update kontor-echo
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"kontor-api-echo/internal/models"
|
||||
"log/slog"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaActorRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func (repository *MediaActorRepository) Import(dtos models.MediaActorDTOList) {
|
||||
slog.Info("MediaActorRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "video", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.MediaActor{ID: dto.ID}
|
||||
result_existing := repository.db.First(&existing_item)
|
||||
if result_existing.Error != nil {
|
||||
slog.Info("check existing id: not found - inserting")
|
||||
result := repository.db.Create(&model)
|
||||
if result.Error != nil {
|
||||
slog.Info("error during import", "error", result.Error.Error())
|
||||
}
|
||||
} else {
|
||||
slog.Info("check existing id: found - updating")
|
||||
result := repository.db.Save(&model)
|
||||
if result.Error != nil {
|
||||
slog.Info("error during updating", "error", result.Error.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewMediaActorRepository(db *bun.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
|
||||
}
|
||||
Reference in New Issue
Block a user