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
|
||||
err = os.WriteFile(fileName, jsonData, 0644)
|
||||
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 nil
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/api"
|
||||
"kontor-api-gin/internal/config"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -13,6 +15,16 @@ var importCmd = &cobra.Command{
|
||||
// Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
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 (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -13,14 +14,28 @@ var (
|
||||
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 {
|
||||
values := gin.H{
|
||||
"title": "Kontor",
|
||||
"version": fmt.Sprintf("%s %s", Version, Commit),
|
||||
"message": message,
|
||||
"user": user,
|
||||
"title": "Kontor",
|
||||
"version": fmt.Sprintf("%s %s", Version, Commit),
|
||||
"message": message,
|
||||
"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
|
||||
}
|
||||
|
||||
@@ -45,21 +45,13 @@ func (handler *AuthHandler) LoginPage(c *gin.Context) {
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPage", globals.UserKey, user)
|
||||
data := globals.GetDefaultValues(user, "Please logout first")
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Please logout first",
|
||||
"user": user,
|
||||
})
|
||||
c.HTML(http.StatusBadRequest, "login", data)
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "",
|
||||
"user": user,
|
||||
})
|
||||
data["message"] = ""
|
||||
c.HTML(http.StatusOK, "login", data)
|
||||
}
|
||||
|
||||
func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
||||
@@ -67,12 +59,9 @@ func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPost", "user", user)
|
||||
data := globals.GetDefaultValues(user, "Please logout first")
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Please logout first",
|
||||
})
|
||||
c.HTML(http.StatusBadRequest, "login", data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,29 +69,20 @@ func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
||||
password := c.PostForm("password")
|
||||
|
||||
if helpers.EmptyUserPass(username, password) {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Parameters can't be empty",
|
||||
})
|
||||
data["message"] = "Parameters can't be empty"
|
||||
c.HTML(http.StatusBadRequest, "login", data)
|
||||
}
|
||||
|
||||
proile_id, err := handler.Service.LoginCheck(username, password)
|
||||
if err != nil {
|
||||
c.HTML(http.StatusUnauthorized, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Incorrect username or password",
|
||||
})
|
||||
data["message"] = "Incorrect username or password"
|
||||
c.HTML(http.StatusUnauthorized, "login", data)
|
||||
}
|
||||
|
||||
session.Set(globals.UserKey, proile_id)
|
||||
if err := session.Save(); err != nil {
|
||||
c.HTML(http.StatusInternalServerError, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Failed to save session",
|
||||
})
|
||||
data["message"] = "Failed to save session"
|
||||
c.HTML(http.StatusInternalServerError, "login", data)
|
||||
return
|
||||
}
|
||||
logger.Info("LoginPost: redirect to index")
|
||||
|
||||
@@ -71,8 +71,9 @@ func (handler *MediaFileHandler) ListPage(c *gin.Context) {
|
||||
}
|
||||
data := globals.GetDefaultValues(user, "MediaFiles...")
|
||||
data["title"] = "Kontor MediaFiles"
|
||||
data["mediafiles"] = files
|
||||
c.HTML(http.StatusOK, "mediafiles", data)
|
||||
data["media_links"] = files
|
||||
data["MediaLinksUrl"] = globals.MediaVideoLink
|
||||
c.HTML(http.StatusOK, "media_links", data)
|
||||
}
|
||||
|
||||
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)
|
||||
//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) {
|
||||
@@ -129,5 +130,5 @@ func (handler *MediaFileHandler) DeletePage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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/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) {
|
||||
|
||||
@@ -119,7 +119,7 @@ func (handler *MediaMusicHandler) ListPage(c *gin.Context) {
|
||||
logger.Info("MediaMusicHandler#ListPage", "MediaMusic count", len(musics))
|
||||
data := globals.GetDefaultValues(user, "MediaMusic...")
|
||||
data["media_links"] = musics
|
||||
data["MediaLinksUrl"] = "/web/media-musics"
|
||||
data["MediaLinksUrl"] = globals.MediaMusicLink
|
||||
data["isReview"] = review
|
||||
data["isDownload"] = download
|
||||
c.HTML(http.StatusOK, "media_links", data)
|
||||
@@ -164,7 +164,7 @@ func (handler *MediaMusicHandler) UpdatePage(c *gin.Context) {
|
||||
}
|
||||
logger.Info("MediaMusicHandler#UpdatePage", "music", music)
|
||||
//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) {
|
||||
@@ -179,5 +179,5 @@ func (handler *MediaMusicHandler) DeletePage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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))
|
||||
data := globals.GetDefaultValues(user, "MediaVideos...")
|
||||
data["title"] = "Kontor MediaVideos"
|
||||
data["mediavideos"] = videos
|
||||
|
||||
c.HTML(http.StatusOK, "mediavideos", data)
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,6 +24,27 @@ func (media_video *MediaVideo) TableName() string {
|
||||
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 {
|
||||
ID string `json:"id" binding:"required"`
|
||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||
|
||||
@@ -2,9 +2,14 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"kontor-api-gin/internal/models"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -25,3 +30,74 @@ func (repository *MediaVideoRepository) FindAll(context context.Context) ([]mode
|
||||
|
||||
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("/publishers", comics.PublisherHandler.ListPage)
|
||||
|
||||
m := router.Group("/web")
|
||||
m := router.Group("/media")
|
||||
m.Use(middleware.AuthRequired())
|
||||
m.GET("/actors", media.MediaActorHandler.ListPage)
|
||||
m.GET("/actors/:id", media.MediaActorHandler.EditPage)
|
||||
m.GET("/actors/:id/edit", media.MediaActorHandler.EditPage)
|
||||
m.POST("/actors/:id/edit", media.MediaActorHandler.UpdatePage)
|
||||
m.POST("/actors/:id", media.MediaActorHandler.UpdatePage)
|
||||
m.GET("/articles", media.MediaFileHandler.ListPage)
|
||||
m.GET("/media-files", media.MediaFileHandler.ListPage)
|
||||
m.GET("/media-files/:id", media.MediaFileHandler.EditPage)
|
||||
m.POST("/media-files/:id", media.MediaFileHandler.UpdatePage)
|
||||
m.GET("/media-videos", media.MediaVideoHandler.ListPage)
|
||||
m.GET("/media-lofis", media.MediaLoFiHandler.ListPage)
|
||||
m.GET("/media-lofis/:id/edit", media.MediaLoFiHandler.EditPage)
|
||||
m.POST("/media-lofis/:id/edit", media.MediaLoFiHandler.UpdatePage)
|
||||
m.GET("/media-lofis/:id/change-review", media.MediaLoFiHandler.ChangeReviewPage)
|
||||
m.GET("/media-lofis/:id/delete", media.MediaLoFiHandler.DeletePage)
|
||||
m.GET("/media-musics", media.MediaMusicHandler.ListPage)
|
||||
m.GET("/media-musics/:id", media.MediaMusicHandler.EditPage)
|
||||
m.POST("/media-musics/:id", media.MediaMusicHandler.UpdatePage)
|
||||
m.GET("/media-musics/:id/delete", media.MediaMusicHandler.DeletePage)
|
||||
m.GET("/files", media.MediaFileHandler.ListPage)
|
||||
m.GET("/files/edit/:id", media.MediaFileHandler.EditPage)
|
||||
m.POST("/files/edit/:id", media.MediaFileHandler.UpdatePage)
|
||||
m.GET("/files/delete/:id", media.MediaFileHandler.DeletePage)
|
||||
m.GET("/videos", media.MediaVideoHandler.ListPage)
|
||||
m.GET("/videos/edit/:id", media.MediaVideoHandler.EditPage)
|
||||
m.POST("/videos/edit/:id", media.MediaVideoHandler.UpdatePage)
|
||||
m.GET("/videos/delete/:id", media.MediaVideoHandler.DeletePage)
|
||||
m.GET("/lofis", media.MediaLoFiHandler.ListPage)
|
||||
m.GET("/lofis/edit", media.MediaLoFiHandler.EditPage)
|
||||
m.GET("/lofis/edit/:id", media.MediaLoFiHandler.EditPage)
|
||||
m.POST("/lofis/edit/:id", media.MediaLoFiHandler.UpdatePage)
|
||||
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.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.POST("/lofis/:id", media.MediaLoFiHandler.Update)
|
||||
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.POST("/actors", media.MediaActorHandler.Add)
|
||||
mediaGroup.GET("/actors/:id", media.MediaActorHandler.Get)
|
||||
|
||||
@@ -20,3 +20,23 @@ func (service *MediaVideoService) List(context context.Context) ([]models.MediaV
|
||||
slog.Info("MediaVideoService#List")
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user