add templates media_links.html and media_detail.html for kontor-gin
This commit is contained in:
@@ -15,7 +15,21 @@ func WriteJson(data *ExportData, fileName string) error {
|
|||||||
// Write bytes to file
|
// Write bytes to file
|
||||||
err = os.WriteFile(fileName, jsonData, 0644)
|
err = os.WriteFile(fileName, jsonData, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Info("Error writing file:", "Error", err)
|
slog.Info("Error writing file:", "Error", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadJson(data *ExportData, fileName string) error {
|
||||||
|
content, err := os.ReadFile(fileName)
|
||||||
|
if err != nil {
|
||||||
|
slog.Info("Error reading file", "Error", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(content, data); err != nil {
|
||||||
|
slog.Info("Error unmarshal json", "Error", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"kontor-api-gin/internal/api"
|
||||||
|
"kontor-api-gin/internal/config"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -13,6 +15,16 @@ var importCmd = &cobra.Command{
|
|||||||
// Args: cobra.ExactArgs(1),
|
// Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
slog.Info("import kontor")
|
slog.Info("import kontor")
|
||||||
|
slog.Info("Verbosity level", "level", config.Verbose)
|
||||||
|
data := api.ExportData{}
|
||||||
|
err := api.ReadJson(&data, config.FileName)
|
||||||
|
if err != nil {
|
||||||
|
slog.Info("Error importing data", "Error", err.Error())
|
||||||
|
}
|
||||||
|
slog.Info("importing MediaFiles", "count", len(data.MediaFile))
|
||||||
|
slog.Info("importing MediaLofis", "count", len(data.MediaLoFi))
|
||||||
|
slog.Info("importing MediaLofi", "media_lofi", data.MediaLoFi[0])
|
||||||
|
slog.Info("import kontor finished")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package globals
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,14 +14,28 @@ var (
|
|||||||
Date = "unset"
|
Date = "unset"
|
||||||
)
|
)
|
||||||
|
|
||||||
const UserKey = "user"
|
const (
|
||||||
|
UserKey = "user"
|
||||||
|
MediaFileLink = "/media/files"
|
||||||
|
MediaLofiLink = "/media/lofis"
|
||||||
|
MediaMusicLink = "/media/musics"
|
||||||
|
MediaVideoLink = "/media/videos"
|
||||||
|
MediaArticleLink = "/media/articles"
|
||||||
|
MediaActorLink = "/media/actors"
|
||||||
|
)
|
||||||
|
|
||||||
func GetDefaultValues(user interface{}, message string) gin.H {
|
func GetDefaultValues(user interface{}, message string) gin.H {
|
||||||
values := gin.H{
|
values := gin.H{
|
||||||
"title": "Kontor",
|
"title": "Kontor",
|
||||||
"version": fmt.Sprintf("%s %s", Version, Commit),
|
"version": fmt.Sprintf("%s %s", Version, Commit),
|
||||||
"message": message,
|
"message": message,
|
||||||
"user": user,
|
"user": user,
|
||||||
|
"media_file_link": MediaFileLink,
|
||||||
|
"media_lofi_link": MediaLofiLink,
|
||||||
|
"media_music_link": MediaMusicLink,
|
||||||
|
"media_video_link": MediaVideoLink,
|
||||||
|
"media_article_link": MediaArticleLink,
|
||||||
|
"media_actor_link": MediaActorLink,
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,21 +45,13 @@ func (handler *AuthHandler) LoginPage(c *gin.Context) {
|
|||||||
user := session.Get(globals.UserKey)
|
user := session.Get(globals.UserKey)
|
||||||
logger := slog.Get(c)
|
logger := slog.Get(c)
|
||||||
logger.Info("LoginPage", globals.UserKey, user)
|
logger.Info("LoginPage", globals.UserKey, user)
|
||||||
|
data := globals.GetDefaultValues(user, "Please logout first")
|
||||||
if user != nil {
|
if user != nil {
|
||||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
c.HTML(http.StatusBadRequest, "login", data)
|
||||||
"title": "Kontor Gin",
|
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "Please logout first",
|
|
||||||
"user": user,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "login", gin.H{
|
data["message"] = ""
|
||||||
"title": "Kontor Gin",
|
c.HTML(http.StatusOK, "login", data)
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "",
|
|
||||||
"user": user,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
||||||
@@ -67,12 +59,9 @@ func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
|||||||
user := session.Get(globals.UserKey)
|
user := session.Get(globals.UserKey)
|
||||||
logger := slog.Get(c)
|
logger := slog.Get(c)
|
||||||
logger.Info("LoginPost", "user", user)
|
logger.Info("LoginPost", "user", user)
|
||||||
|
data := globals.GetDefaultValues(user, "Please logout first")
|
||||||
if user != nil {
|
if user != nil {
|
||||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
c.HTML(http.StatusBadRequest, "login", data)
|
||||||
"title": "Kontor Gin",
|
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "Please logout first",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,29 +69,20 @@ func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
|||||||
password := c.PostForm("password")
|
password := c.PostForm("password")
|
||||||
|
|
||||||
if helpers.EmptyUserPass(username, password) {
|
if helpers.EmptyUserPass(username, password) {
|
||||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
data["message"] = "Parameters can't be empty"
|
||||||
"title": "Kontor Gin",
|
c.HTML(http.StatusBadRequest, "login", data)
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "Parameters can't be empty",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proile_id, err := handler.Service.LoginCheck(username, password)
|
proile_id, err := handler.Service.LoginCheck(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusUnauthorized, "login", gin.H{
|
data["message"] = "Incorrect username or password"
|
||||||
"title": "Kontor Gin",
|
c.HTML(http.StatusUnauthorized, "login", data)
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "Incorrect username or password",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session.Set(globals.UserKey, proile_id)
|
session.Set(globals.UserKey, proile_id)
|
||||||
if err := session.Save(); err != nil {
|
if err := session.Save(); err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "login", gin.H{
|
data["message"] = "Failed to save session"
|
||||||
"title": "Kontor Gin",
|
c.HTML(http.StatusInternalServerError, "login", data)
|
||||||
"version": "0.4.0",
|
|
||||||
"message": "Failed to save session",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Info("LoginPost: redirect to index")
|
logger.Info("LoginPost: redirect to index")
|
||||||
|
|||||||
@@ -71,8 +71,9 @@ func (handler *MediaFileHandler) ListPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
data := globals.GetDefaultValues(user, "MediaFiles...")
|
data := globals.GetDefaultValues(user, "MediaFiles...")
|
||||||
data["title"] = "Kontor MediaFiles"
|
data["title"] = "Kontor MediaFiles"
|
||||||
data["mediafiles"] = files
|
data["media_links"] = files
|
||||||
c.HTML(http.StatusOK, "mediafiles", data)
|
data["MediaLinksUrl"] = globals.MediaVideoLink
|
||||||
|
c.HTML(http.StatusOK, "media_links", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *MediaFileHandler) EditPage(c *gin.Context) {
|
func (handler *MediaFileHandler) EditPage(c *gin.Context) {
|
||||||
@@ -114,7 +115,7 @@ func (handler *MediaFileHandler) UpdatePage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
logger.Info("MediaFileHandler#UpdatePage", "media_file", media_file)
|
logger.Info("MediaFileHandler#UpdatePage", "media_file", media_file)
|
||||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaFileDTO())
|
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaFileDTO())
|
||||||
c.Redirect(http.StatusFound, "web/media-files")
|
c.Redirect(http.StatusFound, globals.MediaFileLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *MediaFileHandler) DeletePage(c *gin.Context) {
|
func (handler *MediaFileHandler) DeletePage(c *gin.Context) {
|
||||||
@@ -129,5 +130,5 @@ func (handler *MediaFileHandler) DeletePage(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Info("MediaFileHandler#DeletePage", "lofi", id)
|
logger.Info("MediaFileHandler#DeletePage", "lofi", id)
|
||||||
c.Redirect(http.StatusFound, "web/media-files")
|
c.Redirect(http.StatusFound, globals.MediaFileLink)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import (
|
|||||||
"kontor-api-gin/internal/repository"
|
"kontor-api-gin/internal/repository"
|
||||||
"kontor-api-gin/internal/service"
|
"kontor-api-gin/internal/service"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-contrib/slog"
|
"github.com/gin-contrib/slog"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -118,10 +120,11 @@ func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
logger.Info("MediaLoFiHandler#ListPage", "lofis count", len(lofis))
|
logger.Info("MediaLoFiHandler#ListPage", "lofis count", len(lofis))
|
||||||
data := globals.GetDefaultValues(user, "MediaFiles...")
|
data := globals.GetDefaultValues(user, "MediaFiles...")
|
||||||
data["lofis"] = lofis
|
data["media_links"] = lofis
|
||||||
data["isReview"] = review
|
data["isReview"] = review
|
||||||
data["isDownload"] = download
|
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) {
|
func (handler *MediaLoFiHandler) EditPage(c *gin.Context) {
|
||||||
@@ -129,16 +132,32 @@ func (handler *MediaLoFiHandler) EditPage(c *gin.Context) {
|
|||||||
user := session.Get(globals.UserKey)
|
user := session.Get(globals.UserKey)
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
logger := slog.Get(c)
|
logger := slog.Get(c)
|
||||||
lofi, err := handler.Service.Get(c.Request.Context(), id)
|
var lofi *models.MediaLoFi
|
||||||
if err != nil {
|
var err error
|
||||||
logger.Info("MediaLoFiHandler#EditPage", "error", err.Error())
|
if id == "" {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
// id is empty, adding is assumed
|
||||||
return
|
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)
|
logger.Info("MediaLoFiHandler#EditPage", "lofi", lofi)
|
||||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||||
data["lofi"] = lofi
|
data["media"] = lofi
|
||||||
c.HTML(http.StatusOK, "lofi_detail", data)
|
data["MediaLinksUrl"] = globals.MediaLofiLink
|
||||||
|
c.HTML(http.StatusOK, "media_detail", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *MediaLoFiHandler) ChangeReviewPage(c *gin.Context) {
|
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)
|
lofi, err := handler.Service.Get(c.Request.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info("MediaLoFiHandler#ChangeReviewPage", "error", err.Error())
|
logger.Info("MediaLoFiHandler#ChangeReviewPage", "error", err.Error())
|
||||||
c.Redirect(http.StatusNotFound, "/web/media-lofis")
|
c.Redirect(http.StatusNotFound, globals.MediaLofiLink)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lofi.Review = !lofi.Review
|
lofi.Review = !lofi.Review
|
||||||
@@ -165,7 +184,7 @@ func (handler *MediaLoFiHandler) ChangeReviewPage(c *gin.Context) {
|
|||||||
data := globals.GetDefaultValues(user, "MediaLofis...")
|
data := globals.GetDefaultValues(user, "MediaLofis...")
|
||||||
data["lofis"] = lofis
|
data["lofis"] = lofis
|
||||||
//c.HTML(http.StatusOK, "lofi", data)
|
//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) {
|
func (handler *MediaLoFiHandler) UpdatePage(c *gin.Context) {
|
||||||
@@ -191,7 +210,7 @@ func (handler *MediaLoFiHandler) UpdatePage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
logger.Info("MediaLoFiHandler#UpdatePage", "lofi", lofi)
|
logger.Info("MediaLoFiHandler#UpdatePage", "lofi", lofi)
|
||||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
//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) {
|
func (handler *MediaLoFiHandler) DeletePage(c *gin.Context) {
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
|
|||||||
logger.Info("MediaMusicHandler#ListPage", "MediaMusic count", len(musics))
|
logger.Info("MediaMusicHandler#ListPage", "MediaMusic count", len(musics))
|
||||||
data := globals.GetDefaultValues(user, "MediaMusic...")
|
data := globals.GetDefaultValues(user, "MediaMusic...")
|
||||||
data["media_links"] = musics
|
data["media_links"] = musics
|
||||||
data["MediaLinksUrl"] = "/web/media-musics"
|
data["MediaLinksUrl"] = globals.MediaMusicLink
|
||||||
data["isReview"] = review
|
data["isReview"] = review
|
||||||
data["isDownload"] = download
|
data["isDownload"] = download
|
||||||
c.HTML(http.StatusOK, "media_links", data)
|
c.HTML(http.StatusOK, "media_links", data)
|
||||||
@@ -164,7 +164,7 @@ func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
logger.Info("MediaMusicHandler#UpdatePage", "music", music)
|
logger.Info("MediaMusicHandler#UpdatePage", "music", music)
|
||||||
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
//handler.Service.Update(c.Request.Context(), form.ConvertFormToMediaLofiDTO())
|
||||||
c.Redirect(http.StatusFound, "web/media-musics")
|
c.Redirect(http.StatusFound, globals.MediaMusicLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
|
func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
|
||||||
@@ -179,5 +179,5 @@ func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Info("MediaMusicHandler#DeletePage", "music", id)
|
logger.Info("MediaMusicHandler#DeletePage", "music", id)
|
||||||
c.Redirect(http.StatusFound, "web/media-musics")
|
c.Redirect(http.StatusFound, globals.MediaMusicLink)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,70 @@ func (handler *MediaVideoHandler) ListPage(c *gin.Context) {
|
|||||||
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
|
logger.Info("MediaVideoHandler#ListPage", "videos count", len(videos))
|
||||||
data := globals.GetDefaultValues(user, "MediaVideos...")
|
data := globals.GetDefaultValues(user, "MediaVideos...")
|
||||||
data["title"] = "Kontor MediaVideos"
|
data["title"] = "Kontor MediaVideos"
|
||||||
data["mediavideos"] = videos
|
data["media_links"] = videos
|
||||||
|
data["MediaLinksUrl"] = globals.MediaVideoLink
|
||||||
c.HTML(http.StatusOK, "mediavideos", data)
|
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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,27 @@ func (media_video *MediaVideo) TableName() string {
|
|||||||
return "media_video"
|
return "media_video"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (media_music *MediaVideo) Update(update MediaVideoDTO) {
|
||||||
|
media_music.CreatedAt = update.CreatedAt.Time
|
||||||
|
media_music.UpdatedAt = time.Now()
|
||||||
|
media_music.Version = media_music.Version + 1
|
||||||
|
media_music.WebLink = update.WebLink
|
||||||
|
media_music.Review = update.Review
|
||||||
|
media_music.ShouldDownload = update.ShouldDownload
|
||||||
|
media_music.Title = update.Title
|
||||||
|
media_music.FileName = update.FileName
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaVideoForm struct {
|
||||||
|
Title string `form:"title" binding:"required"`
|
||||||
|
Url string `form:"url" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (form *MediaVideoForm) ConvertFormToMediaVideoDTO() MediaVideoDTO {
|
||||||
|
media_video := MediaVideoDTO{}
|
||||||
|
return media_video
|
||||||
|
}
|
||||||
|
|
||||||
type MediaVideoDTO struct {
|
type MediaVideoDTO struct {
|
||||||
ID string `json:"id" binding:"required"`
|
ID string `json:"id" binding:"required"`
|
||||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||||
|
|||||||
@@ -2,9 +2,14 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"kontor-api-gin/internal/helpers"
|
||||||
"kontor-api-gin/internal/models"
|
"kontor-api-gin/internal/models"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,3 +30,74 @@ func (repository *MediaVideoRepository) FindAll(context context.Context) ([]mode
|
|||||||
|
|
||||||
return videos, nil
|
return videos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaVideoRepository) GetById(context context.Context, id string) (*models.MediaVideo, error) {
|
||||||
|
var video = models.MediaVideo{ID: id}
|
||||||
|
slog.Info("MediaVideoRepository#GetById", "id", id)
|
||||||
|
result := repository.db.First(&video)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaVideoRepository#GetById", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
return &video, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaVideoRepository) Add(context context.Context, url string) (*models.MediaVideo, error) {
|
||||||
|
slog.Info("MediaVideoRepository#Add", "url", url)
|
||||||
|
webLink := helpers.StripUrl(url, "v")
|
||||||
|
var video models.MediaVideo
|
||||||
|
search_result := repository.db.Where("url = ?", webLink).First(&video)
|
||||||
|
if search_result.RowsAffected > 0 {
|
||||||
|
slog.Info("search for existing url", "result", search_result, "video", video)
|
||||||
|
return &video, nil
|
||||||
|
}
|
||||||
|
if errors.Is(search_result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
slog.Info("MediaVideoRepository#Add URL not found", "url", webLink)
|
||||||
|
video = models.MediaVideo{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
DeletedAt: nil,
|
||||||
|
Version: 0,
|
||||||
|
WebLink: webLink,
|
||||||
|
ShouldDownload: false,
|
||||||
|
Review: true,
|
||||||
|
Title: "",
|
||||||
|
FileName: "",
|
||||||
|
}
|
||||||
|
add_result := repository.db.Create(&video)
|
||||||
|
if add_result.Error != nil {
|
||||||
|
slog.Info("add new MediaVideo", "error", add_result.Error)
|
||||||
|
return nil, add_result.Error
|
||||||
|
}
|
||||||
|
slog.Info("add new MediaVideo", "music", video)
|
||||||
|
return &video, nil
|
||||||
|
}
|
||||||
|
if search_result.Error != nil {
|
||||||
|
return nil, search_result.Error
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("MediaVideoRepository#Add unknown error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaVideoRepository) Update(context context.Context, update models.MediaVideoDTO) (*models.MediaVideo, error) {
|
||||||
|
slog.Info("MediaVideoRepository#Update", "music", update)
|
||||||
|
var video = models.MediaVideo{ID: update.ID}
|
||||||
|
slog.Info("MediaVideoRepository#Update", "id", update.ID)
|
||||||
|
result := repository.db.First(&video)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaVideoRepository#Update", "error", result.Error.Error())
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
video.Update(update)
|
||||||
|
repository.db.Save(&video)
|
||||||
|
return &video, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaVideoRepository) Delete(context context.Context, id string) error {
|
||||||
|
var actor = models.MediaVideo{ID: id}
|
||||||
|
slog.Info("MediaVideoRepository#Delete", "id", id)
|
||||||
|
result := repository.db.Delete(&actor)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaVideoRepository#Delete", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,26 +55,30 @@ func New(admin *handlers.AdminHandler, bookshelf *handlers.BookshelfHandler, com
|
|||||||
comic.GET("/comics", comics.ComicHandler.ListPage)
|
comic.GET("/comics", comics.ComicHandler.ListPage)
|
||||||
comic.GET("/publishers", comics.PublisherHandler.ListPage)
|
comic.GET("/publishers", comics.PublisherHandler.ListPage)
|
||||||
|
|
||||||
m := router.Group("/web")
|
m := router.Group("/media")
|
||||||
m.Use(middleware.AuthRequired())
|
m.Use(middleware.AuthRequired())
|
||||||
m.GET("/actors", media.MediaActorHandler.ListPage)
|
m.GET("/actors", media.MediaActorHandler.ListPage)
|
||||||
m.GET("/actors/:id", media.MediaActorHandler.EditPage)
|
m.GET("/actors/:id", media.MediaActorHandler.EditPage)
|
||||||
m.GET("/actors/:id/edit", media.MediaActorHandler.EditPage)
|
m.POST("/actors/:id", media.MediaActorHandler.UpdatePage)
|
||||||
m.POST("/actors/:id/edit", media.MediaActorHandler.UpdatePage)
|
|
||||||
m.GET("/articles", media.MediaFileHandler.ListPage)
|
m.GET("/articles", media.MediaFileHandler.ListPage)
|
||||||
m.GET("/media-files", media.MediaFileHandler.ListPage)
|
m.GET("/files", media.MediaFileHandler.ListPage)
|
||||||
m.GET("/media-files/:id", media.MediaFileHandler.EditPage)
|
m.GET("/files/edit/:id", media.MediaFileHandler.EditPage)
|
||||||
m.POST("/media-files/:id", media.MediaFileHandler.UpdatePage)
|
m.POST("/files/edit/:id", media.MediaFileHandler.UpdatePage)
|
||||||
m.GET("/media-videos", media.MediaVideoHandler.ListPage)
|
m.GET("/files/delete/:id", media.MediaFileHandler.DeletePage)
|
||||||
m.GET("/media-lofis", media.MediaLoFiHandler.ListPage)
|
m.GET("/videos", media.MediaVideoHandler.ListPage)
|
||||||
m.GET("/media-lofis/:id/edit", media.MediaLoFiHandler.EditPage)
|
m.GET("/videos/edit/:id", media.MediaVideoHandler.EditPage)
|
||||||
m.POST("/media-lofis/:id/edit", media.MediaLoFiHandler.UpdatePage)
|
m.POST("/videos/edit/:id", media.MediaVideoHandler.UpdatePage)
|
||||||
m.GET("/media-lofis/:id/change-review", media.MediaLoFiHandler.ChangeReviewPage)
|
m.GET("/videos/delete/:id", media.MediaVideoHandler.DeletePage)
|
||||||
m.GET("/media-lofis/:id/delete", media.MediaLoFiHandler.DeletePage)
|
m.GET("/lofis", media.MediaLoFiHandler.ListPage)
|
||||||
m.GET("/media-musics", media.MediaMusicHandler.ListPage)
|
m.GET("/lofis/edit", media.MediaLoFiHandler.EditPage)
|
||||||
m.GET("/media-musics/:id", media.MediaMusicHandler.EditPage)
|
m.GET("/lofis/edit/:id", media.MediaLoFiHandler.EditPage)
|
||||||
m.POST("/media-musics/:id", media.MediaMusicHandler.UpdatePage)
|
m.POST("/lofis/edit/:id", media.MediaLoFiHandler.UpdatePage)
|
||||||
m.GET("/media-musics/:id/delete", media.MediaMusicHandler.DeletePage)
|
m.GET("/lofis/review/:id", media.MediaLoFiHandler.ChangeReviewPage)
|
||||||
|
m.GET("/lofis/delete/:id", media.MediaLoFiHandler.DeletePage)
|
||||||
|
m.GET("/musics", media.MediaMusicHandler.ListPage)
|
||||||
|
m.GET("/musics/edit/:id", media.MediaMusicHandler.EditPage)
|
||||||
|
m.POST("/musics/edit/:id", media.MediaMusicHandler.UpdatePage)
|
||||||
|
m.GET("/musics/delete/:id", media.MediaMusicHandler.DeletePage)
|
||||||
|
|
||||||
api := router.Group("/api")
|
api := router.Group("/api")
|
||||||
api.POST("/login", admin.AuthHandler.Login)
|
api.POST("/login", admin.AuthHandler.Login)
|
||||||
@@ -123,6 +127,10 @@ func New(admin *handlers.AdminHandler, bookshelf *handlers.BookshelfHandler, com
|
|||||||
mediaGroup.GET("/lofis/:id", media.MediaLoFiHandler.Get)
|
mediaGroup.GET("/lofis/:id", media.MediaLoFiHandler.Get)
|
||||||
mediaGroup.POST("/lofis/:id", media.MediaLoFiHandler.Update)
|
mediaGroup.POST("/lofis/:id", media.MediaLoFiHandler.Update)
|
||||||
mediaGroup.DELETE("/lofis/:id", media.MediaLoFiHandler.Delete)
|
mediaGroup.DELETE("/lofis/:id", media.MediaLoFiHandler.Delete)
|
||||||
|
mediaGroup.POST("/musics", media.MediaMusicHandler.Add)
|
||||||
|
mediaGroup.GET("/musics/:id", media.MediaMusicHandler.Get)
|
||||||
|
mediaGroup.POST("/musics/:id", media.MediaMusicHandler.Update)
|
||||||
|
mediaGroup.DELETE("/musics/:id", media.MediaMusicHandler.Delete)
|
||||||
mediaGroup.GET("/actors", media.MediaActorHandler.List)
|
mediaGroup.GET("/actors", media.MediaActorHandler.List)
|
||||||
mediaGroup.POST("/actors", media.MediaActorHandler.Add)
|
mediaGroup.POST("/actors", media.MediaActorHandler.Add)
|
||||||
mediaGroup.GET("/actors/:id", media.MediaActorHandler.Get)
|
mediaGroup.GET("/actors/:id", media.MediaActorHandler.Get)
|
||||||
|
|||||||
@@ -20,3 +20,23 @@ func (service *MediaVideoService) List(context context.Context) ([]models.MediaV
|
|||||||
slog.Info("MediaVideoService#List")
|
slog.Info("MediaVideoService#List")
|
||||||
return service.repository.FindAll(context)
|
return service.repository.FindAll(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (service *MediaVideoService) Get(context context.Context, id string) (*models.MediaVideo, error) {
|
||||||
|
slog.Info("MediaVideoService#Get")
|
||||||
|
return service.repository.GetById(context, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaVideoService) Add(context context.Context, url string) (*models.MediaVideo, error) {
|
||||||
|
slog.Info("MediaVideoService#Add")
|
||||||
|
return service.repository.Add(context, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaVideoService) Update(context context.Context, music models.MediaVideoDTO) (*models.MediaVideo, error) {
|
||||||
|
slog.Info("MediaVideoService#Update")
|
||||||
|
return service.repository.Update(context, music)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaVideoService) Delete(context context.Context, id string) error {
|
||||||
|
slog.Info("MediaVideoService#Delete")
|
||||||
|
return service.repository.Delete(context, id)
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,12 +21,12 @@
|
|||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="navbarWebMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Media</a>
|
<a class="nav-link dropdown-toggle" href="#" id="navbarWebMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Media</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarWebMenuLink">
|
<div class="dropdown-menu" aria-labelledby="navbarWebMenuLink">
|
||||||
<a class="dropdown-item" href="/web/media-files">Media Files</a>
|
<a class="dropdown-item" href="{{.media_file_link}}">Media Files</a>
|
||||||
<a class="dropdown-item" href="/web/actors">Media Actors</a>
|
<a class="dropdown-item" href="{{.media_actor_link}}">Media Actors</a>
|
||||||
<a class="dropdown-item" href="/web/media-lofis">Media Lofi</a>
|
<a class="dropdown-item" href="{{.media_lofi_link}}">Media Lofi</a>
|
||||||
<a class="dropdown-item" href="/web/media-musics">Media Music</a>
|
<a class="dropdown-item" href="{{.media_music_link}}">Media Music</a>
|
||||||
<a class="dropdown-item" href="/web/media-videos">Media Videos</a>
|
<a class="dropdown-item" href="{{.media_video_link}}">Media Videos</a>
|
||||||
<a class="dropdown-item" href="/web/articles">Artikel</a>
|
<a class="dropdown-item" href="{{.media_article_link}}">Artikel</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{ if .user }}
|
{{ if .user }}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
{{ define "media_detail" }}
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="de">
|
||||||
|
{{ template "head" . }}
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{{ template "navbar" . }}
|
||||||
|
<main>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<h1>{{.message}}</h1>
|
||||||
|
<p>Hier steht der wesentliche Inhalt der Seite.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<aside class="bg-light p-3">
|
||||||
|
<h3>Seitenbereich</h3>
|
||||||
|
<p>Optionale Sidebar oder Zusatzinformationen.</p>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
{{ if .Errors }}
|
||||||
|
<div class="notification is-danger">{{ .Errors }}</div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<form action="{{ .MediaLinksUrl }}/edit/{{.media.ID}}" method="POST">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="inputWeblink" class="col-sm-2 -col-form-label">URL</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="inputWeblink" name="weblink" value="{{.media.WebLink}}"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="inputTitle" class="col-sm-2 -col-form-label">Title</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="inputTitle" name="title" value="{{.media.Title}}"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<button class="btn btn-primary" type="submit">Update</button>
|
||||||
|
<button class="btn" type="button" onclick="window.history.back()">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{{ template "footer" . }}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
{{ end }}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<input type="checkbox" name="download" {{ if .ShouldDownload }}checked{{ end }}>Download
|
<input type="checkbox" name="download" {{ if .ShouldDownload }}checked{{ end }}>Download
|
||||||
</label>
|
</label>
|
||||||
<button type="submit">Search</button>
|
<button type="submit">Search</button>
|
||||||
<div class="pill-nav"><a href="{{ .MediaLinksUrl }}/add">Add MediaFile</a></div>
|
<div class="pill-nav"><a href="{{ .MediaLinksUrl }}/edit">Add {{.title}}</a></div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{{ range .media_links }}
|
{{ range .media_links }}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><a href="{{ .MediaLinksUrl }}/{{.ID}}">{{.Title}}</a></th>
|
<th scope="row"><a href="{{ $.MediaLinksUrl }}/edit/{{.ID}}">{{.Title}}</a></th>
|
||||||
{{ if .WebLink }}
|
{{ if .WebLink }}
|
||||||
<td><a href="{{.WebLink}}">{{.WebLink}}</a></td>
|
<td><a href="{{.WebLink}}">{{.WebLink}}</a></td>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
@@ -54,9 +54,9 @@
|
|||||||
<img src="/public/icons/cross.png" alt="true" width="24" height="24">
|
<img src="/public/icons/cross.png" alt="true" width="24" height="24">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</td>
|
</td>
|
||||||
<td><a href="{{ .MediaLinksUrl }}/{{.ID}}" class="btn btn-outline-primary btn-sm active" role="button"
|
<td><a href="{{ $.MediaLinksUrl }}/edit/{{.ID}}" class="btn btn-outline-primary btn-sm active" role="button"
|
||||||
aria-pressed="true">Edit</a></td>
|
aria-pressed="true">Edit</a></td>
|
||||||
<td><a href="{ .MediaLinksUrl }/{{.ID}}/delete" class="btn btn-outline-danger btn-sm active"
|
<td><a href="{ $.MediaLinksUrl }/delete/{{.ID}}" class="btn btn-outline-danger btn-sm active"
|
||||||
role="button" aria-pressed="true">Delete</a></td>
|
role="button" aria-pressed="true">Delete</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user