WIP: add missing handlers, services nd repositories
This commit is contained in:
@@ -12,19 +12,17 @@ type AdminHandler struct {
|
||||
TokenHandler *TokenHandler
|
||||
MailAccountHandler *MailAccountHandler
|
||||
MailHandler *MailHandler
|
||||
Secret []byte
|
||||
}
|
||||
|
||||
func NewAdminHandler(db *bun.DB, secret []byte) *AdminHandler {
|
||||
func NewAdminHandler(db *bun.DB) *AdminHandler {
|
||||
adminHandler := &AdminHandler{
|
||||
AuthHandler: &AuthHandler{Service: service.NewAuthService(repository.NewProfileRepository(db), secret)},
|
||||
AuthHandler: NewAuthHandler(db),
|
||||
ProfileHandler: NewProfileHandler(db),
|
||||
PermissionHandler: &PermissionHandler{Service: service.NewPermissionService(repository.NewPermissionRepository(db))},
|
||||
PermissionHandler: NewPermissionHandler(db),
|
||||
AssignmentHandler: NewAssignmentHandler(db),
|
||||
TokenHandler: NewTokenHandler(db),
|
||||
MailAccountHandler: NewMailAccountHandler(db),
|
||||
MailHandler: NewMailHandler(db),
|
||||
Secret: secret,
|
||||
}
|
||||
return adminHandler
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/models"
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type AssignmentHandler struct {
|
||||
Service *service.AssignmentService
|
||||
}
|
||||
|
||||
func NewAssignmentHandler(db *bun.DB) *AssignmentHandler {
|
||||
handler := &AssignmentHandler{Service: service.NewAssignmentService(repository.NewAssignmentRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *AssignmentHandler) List(c *echo.Context) {
|
||||
assignments, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertAssignmentsToDtos(assignments)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -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...",
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
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/labstack/echo/v5"
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
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"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -170,8 +169,8 @@ func (handler *MediaLoFiHandler) ChangeReviewPage(c *echo.Context) {
|
||||
lofi.Review = !lofi.Review
|
||||
handler.Service.Update(c.Request().Context(), lofi.ConvertMediaLoFiToDTO())
|
||||
logger.Info("MediaLoFiHandler#ChangeReviewPage", "lofi", lofi)
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
lofis, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
logger.Info("MediaLoFiHandler#ChangeReviewPage", "error", err.Error())
|
||||
@@ -199,7 +198,7 @@ func (handler *MediaLoFiHandler) UpdatePage(c *echo.Context) {
|
||||
var form models.MediaLoFiForm
|
||||
if err := c.Bind(&form); err != nil {
|
||||
logger.Info("MediaLoFiHandler#UpdatePage", "error", err.Error())
|
||||
c.Render(http.StatusBadRequest, "lofi_detail", map[string]string{
|
||||
c.Render(http.StatusBadRequest, "lofi_detail", map[string]any{
|
||||
"Form": form,
|
||||
"Errors": err.Error(),
|
||||
"user": user,
|
||||
|
||||
@@ -1,108 +1,106 @@
|
||||
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-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaMusicHandler struct {
|
||||
Service *service.MediaMusicService
|
||||
}
|
||||
|
||||
func NewMediaMusicHandler(db *gorm.DB) *MediaMusicHandler {
|
||||
func NewMediaMusicHandler(db *bun.DB) *MediaMusicHandler {
|
||||
mediaMusicHandler := &MediaMusicHandler{
|
||||
Service: service.NewMediaMusicService(repository.NewMediaMusicRepository(db)),
|
||||
}
|
||||
return mediaMusicHandler
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) List(c *gin.Context) {
|
||||
musics, err := handler.Service.List(c.Request.Context())
|
||||
func (handler *MediaMusicHandler) List(c *echo.Context) {
|
||||
musics, 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.ConvertMediaMusicsToDtos(musics)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) Get(c *gin.Context) {
|
||||
func (handler *MediaMusicHandler) Get(c *echo.Context) {
|
||||
id := c.Param("id")
|
||||
music, err := handler.Service.Get(c.Request.Context(), id)
|
||||
music, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not found"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, music)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) Add(c *gin.Context) {
|
||||
func (handler *MediaMusicHandler) Add(c *echo.Context) {
|
||||
var input models.MediaLofiAdd
|
||||
|
||||
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
|
||||
}
|
||||
music, err := handler.Service.Add(c.Request.Context(), input.Url)
|
||||
music, err := handler.Service.Add(c.Request().Context(), input.Url)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not added"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not added"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, music)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) Update(c *gin.Context) {
|
||||
func (handler *MediaMusicHandler) Update(c *echo.Context) {
|
||||
var input models.MediaMusicDTO
|
||||
|
||||
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
|
||||
}
|
||||
music, err := handler.Service.Update(c.Request.Context(), input)
|
||||
music, err := handler.Service.Update(c.Request().Context(), input)
|
||||
if err != nil {
|
||||
logger := slog.Get(c)
|
||||
logger := c.Logger()
|
||||
logger.Info("MediaMusicHandler#Update", "error", err.Error())
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "MediaMusic not updated"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not updated"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, music)
|
||||
}
|
||||
func (handler *MediaMusicHandler) Delete(c *gin.Context) {
|
||||
func (handler *MediaMusicHandler) 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": "MediaMusic not found"})
|
||||
c.JSON(http.StatusNotFound, map[string]string{"error": "MediaMusic not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": "true"})
|
||||
c.JSON(http.StatusOK, map[string]string{"ok": "true"})
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
func (handler *MediaMusicHandler) ListPage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
logger := c.Logger()
|
||||
var (
|
||||
review bool
|
||||
download bool
|
||||
)
|
||||
paramReview, existsReview := c.GetQuery("review")
|
||||
if existsReview {
|
||||
paramReview, err := echo.QueryParam[string](c, "review")
|
||||
if err == nil {
|
||||
if paramReview == "on" {
|
||||
review = true
|
||||
} else {
|
||||
review = false
|
||||
}
|
||||
}
|
||||
paramDownload, existsDownload := c.GetQuery("should_download")
|
||||
if existsDownload {
|
||||
paramDownload, err := echo.QueryParam[string](c, "should_download")
|
||||
if err == nil {
|
||||
if paramDownload == "on" {
|
||||
download = true
|
||||
} else {
|
||||
@@ -110,10 +108,10 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
musics, err := handler.Service.List(c.Request.Context())
|
||||
musics, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
logger.Info("MediaMusicHandler#ListPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaMusicHandler#ListPage", "MediaMusic count", len(musics))
|
||||
@@ -122,44 +120,44 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
|
||||
data["MediaLinksUrl"] = globals.MediaMusicLink
|
||||
data["isReview"] = review
|
||||
data["isDownload"] = download
|
||||
c.HTML(http.StatusOK, "media_links", data)
|
||||
c.Render(http.StatusOK, "media_links", data)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) EditPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
func (handler *MediaMusicHandler) EditPage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
music, err := handler.Service.Get(c.Request.Context(), id)
|
||||
logger := c.Logger()
|
||||
music, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaMusicHandler#EditPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaMusicHandler#EditPage", "music", music)
|
||||
data := globals.GetDefaultValues(user, "MediaMusic...")
|
||||
data["lofi"] = music
|
||||
c.HTML(http.StatusOK, "lofi_detail", data)
|
||||
c.Render(http.StatusOK, "lofi_detail", data)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
func (handler *MediaMusicHandler) UpdatePage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
music, err := handler.Service.Get(c.Request.Context(), id)
|
||||
logger := c.Logger()
|
||||
music, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaMusicHandler#UpdatePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
var form models.MediaMusicForm
|
||||
if err := c.ShouldBind(&form); err != nil {
|
||||
if err := c.Bind(&form); err != nil {
|
||||
logger.Info("MediaMusicHandler#UpdatePage", "error", err.Error())
|
||||
data := globals.GetDefaultValues(user, "MediaMusic...")
|
||||
data["Form"] = form
|
||||
data["Errors"] = err.Error()
|
||||
c.HTML(http.StatusBadRequest, "lofi_detail", data)
|
||||
c.Render(http.StatusBadRequest, "lofi_detail", data)
|
||||
return
|
||||
}
|
||||
logger.Info("MediaMusicHandler#UpdatePage", "music", music)
|
||||
@@ -167,15 +165,15 @@ func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
|
||||
c.Redirect(http.StatusFound, globals.MediaMusicLink)
|
||||
}
|
||||
|
||||
func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
|
||||
func (handler *MediaMusicHandler) DeletePage(c *echo.Context) {
|
||||
// session := sessions.Default(c)
|
||||
// user := session.Get(globals.UserKey)
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
err := handler.Service.Delete(c.Request.Context(), id)
|
||||
logger := c.Logger()
|
||||
err := handler.Service.Delete(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaMusicHandler#DeletePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaMusicHandler#DeletePage", "music", id)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/globals"
|
||||
"kontor-api-echo/internal/models"
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaVideoHandler struct {
|
||||
Service *service.MediaVideoService
|
||||
}
|
||||
|
||||
func NewMediaVideoHandler(db *bun.DB) *MediaVideoHandler {
|
||||
handler := &MediaVideoHandler{Service: service.NewMediaVideoService(repository.NewMediaVideoRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) List(c *echo.Context) {
|
||||
logger := c.Logger()
|
||||
logger.Info("MediaVideoHandler#List")
|
||||
videos, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaVideosToDtos(videos)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) ListPage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
logger := c.Logger()
|
||||
videos, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
|
||||
data := globals.GetDefaultValues(user, "MediaVideos...")
|
||||
data["title"] = "Kontor MediaVideos"
|
||||
data["media_links"] = videos
|
||||
data["MediaLinksUrl"] = globals.MediaVideoLink
|
||||
c.Render(http.StatusOK, "media_links", data)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) EditPage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
id := c.Param("id")
|
||||
logger := c.Logger()
|
||||
video, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#EditPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#EditPage", "lofi", video)
|
||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||
data["lofi"] = video
|
||||
c.Render(http.StatusOK, "lofi_detail", data)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) UpdatePage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
id := c.Param("id")
|
||||
logger := c.Logger()
|
||||
video, err := handler.Service.Get(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
var form models.MediaVideoForm
|
||||
if err := c.Bind(&form); err != nil {
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
|
||||
c.Render(http.StatusBadRequest, "lofi_detail", map[string]any{
|
||||
"Form": form,
|
||||
"Errors": err.Error(),
|
||||
"user": user,
|
||||
})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "lofi", video)
|
||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
||||
c.Redirect(http.StatusFound, globals.MediaVideoLink)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) DeletePage(c *echo.Context) {
|
||||
cookie, err := c.Cookie(globals.UserKey)
|
||||
user := cookie.Value
|
||||
id := c.Param("id")
|
||||
logger := c.Logger()
|
||||
err = handler.Service.Delete(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#DeletePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#DeletePage", "video", id)
|
||||
c.Render(http.StatusOK, "lofi_delete", map[string]string{
|
||||
"title": "Kontor MediaFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaFiles...",
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
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["media_links"] = videos
|
||||
data["MediaLinksUrl"] = globals.MediaVideoLink
|
||||
c.HTML(http.StatusOK, "media_links", data)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) EditPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
video, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#EditPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#EditPage", "lofi", video)
|
||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||
data["lofi"] = video
|
||||
c.HTML(http.StatusOK, "lofi_detail", data)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) UpdatePage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
video, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
var form models.MediaVideoForm
|
||||
if err := c.ShouldBind(&form); err != nil {
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "error", err.Error())
|
||||
c.HTML(http.StatusBadRequest, "lofi_detail", gin.H{
|
||||
"Form": form,
|
||||
"Errors": err.Error(),
|
||||
"user": user,
|
||||
})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#UpdatePage", "lofi", video)
|
||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
||||
c.Redirect(http.StatusFound, globals.MediaVideoLink)
|
||||
}
|
||||
|
||||
func (handler *MediaVideoHandler) DeletePage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
err := handler.Service.Delete(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaVideoHandler#DeletePage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
logger.Info("MediaVideoHandler#DeletePage", "video", id)
|
||||
c.HTML(http.StatusOK, "lofi_delete", gin.H{
|
||||
"title": "Kontor MediaFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaFiles...",
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type PermissionHandler struct {
|
||||
Service *service.PermissionService
|
||||
}
|
||||
|
||||
func NewPermissionHandler(db *bun.DB) *PermissionHandler {
|
||||
handler := &PermissionHandler{Service: service.NewPermissionService(repository.NewPermissionRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *PermissionHandler) List(c *echo.Context) {
|
||||
permissions, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, permissions)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/models"
|
||||
"kontor-api-echo/internal/repository"
|
||||
"kontor-api-echo/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type ProfileHandler struct {
|
||||
Service *service.ProfileService
|
||||
}
|
||||
|
||||
func NewProfileHandler(db *bun.DB) *ProfileHandler {
|
||||
handler := &ProfileHandler{Service: service.NewProfileService(repository.NewProfileRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *ProfileHandler) List(c *echo.Context) {
|
||||
profiles, err := handler.Service.List(c.Request().Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertProfilesToDtos(profiles)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
Reference in New Issue
Block a user