53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
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-contrib/slog"
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type MediaVideoHandler struct {
|
|
Service *service.MediaVideoService
|
|
}
|
|
|
|
func NewMediaVideoHandler(db *gorm.DB) *MediaVideoHandler {
|
|
handler := &MediaVideoHandler{Service: service.NewMediaVideoService(repository.NewMediaVideoRepository(db))}
|
|
return handler
|
|
}
|
|
|
|
func (handler *MediaVideoHandler) List(c *gin.Context) {
|
|
logger := slog.Get(c)
|
|
logger.Info("MediaVideoHandler#List")
|
|
videos, err := handler.Service.List(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
dtos := models.ConvertMediaVideosToDtos(videos)
|
|
c.JSON(http.StatusOK, dtos)
|
|
}
|
|
|
|
func (handler *MediaVideoHandler) ListPage(c *gin.Context) {
|
|
session := sessions.Default(c)
|
|
user := session.Get(globals.UserKey)
|
|
logger := slog.Get(c)
|
|
videos, err := handler.Service.List(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
|
|
data := globals.GetDefaultValues(user, "MediaVideos...")
|
|
data["title"] = "Kontor MediaVideos"
|
|
data["mediavideos"] = videos
|
|
|
|
c.HTML(http.StatusOK, "mediavideos", data)
|
|
}
|