add tysc handlers to kontor-gin
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/globals"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MediaLoFiHandler struct {
|
||||
Service *service.MediaLoFiService
|
||||
}
|
||||
|
||||
func NewMediaLoFiHandler(db *gorm.DB) *MediaLoFiHandler {
|
||||
mediaLoFiHandler := &MediaLoFiHandler{
|
||||
Service: service.NewMediaLoFiService(repository.NewMediaLoFiRepository(db)),
|
||||
}
|
||||
return mediaLoFiHandler
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) List(c *gin.Context) {
|
||||
lofis, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaLoFisToDtos(lofis)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
lofis, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "lofi", gin.H{
|
||||
"title": "Kontor MediaFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaFiles...",
|
||||
"lofis": lofis,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user