This commit is contained in:
@@ -33,6 +33,26 @@ func (handler *MediaActorHandler) List(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, dtos)
|
c.JSON(http.StatusOK, dtos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler *MediaActorHandler) Get(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
actor, err := handler.Service.Get(c.Request.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, actor)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *MediaActorHandler) Delete(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
err := handler.Service.Delete(c.Request.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"ok": "true"})
|
||||||
|
}
|
||||||
|
|
||||||
func (handler *MediaActorHandler) ListPage(c *gin.Context) {
|
func (handler *MediaActorHandler) ListPage(c *gin.Context) {
|
||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
user := session.Get(globals.UserKey)
|
user := session.Get(globals.UserKey)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"kontor-api-gin/internal/test/testutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
testutils.InitializeTestSuite(m)
|
||||||
|
}
|
||||||
@@ -25,3 +25,23 @@ func (repository *MediaActorRepository) FindAll(context context.Context) ([]mode
|
|||||||
|
|
||||||
return actors, nil
|
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) 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ func New(admin *handlers.AdminHandler, bookshelf *handlers.BookshelfHandler, com
|
|||||||
secured.GET("media/videos", media.MediaVideoHandler.List)
|
secured.GET("media/videos", media.MediaVideoHandler.List)
|
||||||
secured.GET("media/lofis", media.MediaLoFiHandler.List)
|
secured.GET("media/lofis", media.MediaLoFiHandler.List)
|
||||||
secured.GET("media/actors", media.MediaActorHandler.List)
|
secured.GET("media/actors", media.MediaActorHandler.List)
|
||||||
|
secured.GET("media/actors/:id", media.MediaActorHandler.Get)
|
||||||
|
secured.DELETE("media/actors/:id", media.MediaActorHandler.Delete)
|
||||||
secured.GET("media/actorfiles", media.MediaActorFileHandler.List)
|
secured.GET("media/actorfiles", media.MediaActorFileHandler.List)
|
||||||
}
|
}
|
||||||
return router
|
return router
|
||||||
|
|||||||
@@ -20,3 +20,13 @@ func (service *MediaActorService) List(context context.Context) ([]models.MediaA
|
|||||||
slog.Info("MediaActorService#List")
|
slog.Info("MediaActorService#List")
|
||||||
return service.repository.FindAll(context)
|
return service.repository.FindAll(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (service *MediaActorService) Get(context context.Context, id string) (models.MediaActor, error) {
|
||||||
|
slog.Info("MediaActorService#Get")
|
||||||
|
return service.repository.GetById(context, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaActorService) Delete(context context.Context, id string) error {
|
||||||
|
slog.Info("MediaActorService#Delete")
|
||||||
|
return service.repository.Delete(context, id)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetupTestDatabase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func PatchDatabase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TearDownTestDatabase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnpatchDatabase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitializeTestSuite(m *testing.M) {
|
||||||
|
// Initialize the test database
|
||||||
|
SetupTestDatabase()
|
||||||
|
// Patch the global database.DB to use the TestDB
|
||||||
|
PatchDatabase()
|
||||||
|
// Run all tests
|
||||||
|
code := m.Run()
|
||||||
|
// Teardown the database connection
|
||||||
|
TearDownTestDatabase()
|
||||||
|
// Unpatch the database
|
||||||
|
UnpatchDatabase()
|
||||||
|
// Exit with the test run status code
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user