Files
kontor/kontor-gin/internal/handlers/mediavideo.go
T
Thomas Peetz 05555a7750
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 11m53s
Gitea Actions Demo / build-and-test (push) Failing after 16m45s
add method to set default values for handler
2026-10-25 01:24:19 +02:00

51 lines
1.3 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)
videos, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
data := globals.GetDefaultValues(user, "MediaFiles...")
data["title"] = "Kontor MediaFiles"
data["mediavideos"] = videos
c.HTML(http.StatusOK, "mediavideos", data)
}