add templates media_links.html and media_detail.html for kontor-gin
This commit is contained in:
@@ -6,10 +6,12 @@ import (
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -118,10 +120,11 @@ func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
||||
}
|
||||
logger.Info("MediaLoFiHandler#ListPage", "lofis count", len(lofis))
|
||||
data := globals.GetDefaultValues(user, "MediaFiles...")
|
||||
data["lofis"] = lofis
|
||||
data["media_links"] = lofis
|
||||
data["isReview"] = review
|
||||
data["isDownload"] = download
|
||||
c.HTML(http.StatusOK, "lofi", data)
|
||||
data["MediaLinksUrl"] = globals.MediaLofiLink
|
||||
c.HTML(http.StatusOK, "media_links", data)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) EditPage(c *gin.Context) {
|
||||
@@ -129,16 +132,32 @@ func (handler *MediaLoFiHandler) EditPage(c *gin.Context) {
|
||||
user := session.Get(globals.UserKey)
|
||||
id := c.Param("id")
|
||||
logger := slog.Get(c)
|
||||
lofi, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaLoFiHandler#EditPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
var lofi *models.MediaLoFi
|
||||
var err error
|
||||
if id == "" {
|
||||
// id is empty, adding is assumed
|
||||
lofi = &models.MediaLoFi{
|
||||
ID: uuid.NewString(),
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
Version: 0,
|
||||
Review: true,
|
||||
ShouldDownload: true,
|
||||
}
|
||||
} else {
|
||||
// id is set, fetch MediaLofi by ID
|
||||
lofi, err = handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaLoFiHandler#EditPage", "error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
logger.Info("MediaLoFiHandler#EditPage", "lofi", lofi)
|
||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||
data["lofi"] = lofi
|
||||
c.HTML(http.StatusOK, "lofi_detail", data)
|
||||
data["media"] = lofi
|
||||
data["MediaLinksUrl"] = globals.MediaLofiLink
|
||||
c.HTML(http.StatusOK, "media_detail", data)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) ChangeReviewPage(c *gin.Context) {
|
||||
@@ -147,7 +166,7 @@ func (handler *MediaLoFiHandler) ChangeReviewPage(c *gin.Context) {
|
||||
lofi, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
logger.Info("MediaLoFiHandler#ChangeReviewPage", "error", err.Error())
|
||||
c.Redirect(http.StatusNotFound, "/web/media-lofis")
|
||||
c.Redirect(http.StatusNotFound, globals.MediaLofiLink)
|
||||
return
|
||||
}
|
||||
lofi.Review = !lofi.Review
|
||||
@@ -165,7 +184,7 @@ func (handler *MediaLoFiHandler) ChangeReviewPage(c *gin.Context) {
|
||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||
data["lofis"] = lofis
|
||||
//c.HTML(http.StatusOK, "lofi", data)
|
||||
c.Redirect(http.StatusCreated, "/web/media-lofis")
|
||||
c.Redirect(http.StatusCreated, globals.MediaLofiLink)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) UpdatePage(c *gin.Context) {
|
||||
@@ -191,7 +210,7 @@ func (handler *MediaLoFiHandler) UpdatePage(c *gin.Context) {
|
||||
}
|
||||
logger.Info("MediaLoFiHandler#UpdatePage", "lofi", lofi)
|
||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
||||
c.Redirect(http.StatusFound, "web/media-lofis")
|
||||
c.Redirect(http.StatusFound, globals.MediaLofiLink)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) DeletePage(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user