WIP: add missing handlers, services nd repositories
This commit is contained in:
@@ -1,82 +1,81 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/globals"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"kontor-api-echo/internal/globals"
|
||||
"kontor-api-echo/internal/models"
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaActorFileHandler struct {
|
||||
Service *service.MediaActorFileService
|
||||
}
|
||||
|
||||
func NewMediaActorFileHandler(db *gorm.DB) *MediaActorFileHandler {
|
||||
func NewMediaActorFileHandler(db *bun.DB) *MediaActorFileHandler {
|
||||
mediaActorFileHandler := &MediaActorFileHandler{
|
||||
Service: service.NewMediaActorFileService(repository.NewMediaActorFileRepository(db)),
|
||||
}
|
||||
return mediaActorFileHandler
|
||||
}
|
||||
|
||||
func (handler *MediaActorFileHandler) List(c *gin.Context) {
|
||||
media_actor_files, err := handler.Service.List(c.Request.Context())
|
||||
func (handler *MediaActorFileHandler) List(c *echo.Context) {
|
||||
media_actor_files, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaActorFilesToDtos(media_actor_files)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaActorFileHandler) Get(c *gin.Context) {
|
||||
func (handler *MediaActorFileHandler) Get(c *echo.Context) {
|
||||
id := c.Param("id")
|
||||
actor, err := handler.Service.Get(c.Request.Context(), id)
|
||||
actor, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "sport not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, actor)
|
||||
}
|
||||
|
||||
func (handler *MediaActorFileHandler) Add(c *gin.Context) {
|
||||
func (handler *MediaActorFileHandler) Add(c *echo.Context) {
|
||||
var input models.MediaActorFileAdd
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
if err := c.Bind(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
actorfile, err := handler.Service.Add(c.Request.Context(), input.MediaActorID, input.MediaFileID)
|
||||
actorfile, err := handler.Service.Add(c.Request().Context(), input.MediaActorID, input.MediaFileID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "lofi not added"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "lofi not added"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, actorfile)
|
||||
}
|
||||
|
||||
func (handler *MediaActorFileHandler) Delete(c *gin.Context) {
|
||||
func (handler *MediaActorFileHandler) Delete(c *echo.Context) {
|
||||
id := c.Param("id")
|
||||
err := handler.Service.Delete(c.Request.Context(), id)
|
||||
err := handler.Service.Delete(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "sport not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": "true"})
|
||||
c.JSON(http.StatusOK, map[string]string{"ok": "true"})
|
||||
}
|
||||
|
||||
func (handler *MediaActorFileHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
media_actor_files, err := handler.Service.List(c.Request.Context())
|
||||
func (handler *MediaActorFileHandler) ListPage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
media_actor_files, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "mediaactorfiles", gin.H{
|
||||
c.Render(http.StatusOK, "mediaactorfiles", map[string]string{
|
||||
"title": "Kontor MediaActorFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaActorFiles...",
|
||||
|
||||
Reference in New Issue
Block a user