This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"kontor-api-gin/internal/helpers"
|
"kontor-api-gin/internal/helpers"
|
||||||
|
"kontor-api-gin/internal/models"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-stomp/stomp/v3"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"resty.dev/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var addLinksCmd = &cobra.Command{
|
var addLinksCmd = &cobra.Command{
|
||||||
@@ -17,14 +17,6 @@ var addLinksCmd = &cobra.Command{
|
|||||||
Long: "Add Links",
|
Long: "Add Links",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
conn, err := stomp.Dial("tcp", "localhost:61616",
|
|
||||||
stomp.ConnOpt.Login("artemis", "artemis"), // Provide username and password
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
slog.Info("failed to connect to Artemis: %s", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
defer conn.Disconnect()
|
|
||||||
|
|
||||||
fileName := args[0]
|
fileName := args[0]
|
||||||
slog.Info(fmt.Sprintf("add Links from %s", fileName))
|
slog.Info(fmt.Sprintf("add Links from %s", fileName))
|
||||||
@@ -33,18 +25,20 @@ var addLinksCmd = &cobra.Command{
|
|||||||
slog.Warn("add links failed", "error", err)
|
slog.Warn("add links failed", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
var login LoginResponse
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
b, jsonErr := json.Marshal(line)
|
lofiAdd := models.MediaLofiAdd{Url: line}
|
||||||
if jsonErr != nil {
|
client := resty.New()
|
||||||
slog.Info("Json encoding failed", "error", jsonErr.Error())
|
PostJSON(client, fmt.Sprintf("%s/%s/%s", server, "api", "login"), &login)
|
||||||
}
|
response, err := client.R().
|
||||||
err = conn.Send("media.link", "application/json", b)
|
SetBody(lofiAdd).
|
||||||
|
SetHeader("Accept", "application/json").
|
||||||
|
Post("http://localhost:8550/api/v1/media/lofi")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Info("send failed", "error", err.Error())
|
slog.Info("Add Lofi", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
slog.Info("Add Lofi", "status", response.StatusCode(), "body", response.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,41 @@ func (handler *MediaLoFiHandler) List(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, dtos)
|
c.JSON(http.StatusOK, dtos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler *MediaLoFiHandler) Get(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
lofi, err := handler.Service.Get(c.Request.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "Lofi not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, lofi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *MediaLoFiHandler) Add(c *gin.Context) {
|
||||||
|
var input models.MediaLofiAdd
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lofi, err := handler.Service.Add(c.Request.Context(), input.Url)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "lofi not added"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, lofi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *MediaLoFiHandler) Delete(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
err := handler.Service.Delete(c.Request.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "lofi not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"ok": "true"})
|
||||||
|
}
|
||||||
|
|
||||||
func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
user := session.Get(globals.UserKey)
|
user := session.Get(globals.UserKey)
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ func (media_lofi *MediaLoFi) TableName() string {
|
|||||||
return "media_lofi"
|
return "media_lofi"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MediaLofiAdd struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
type MediaLoFiDTO struct {
|
type MediaLoFiDTO 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"`
|
||||||
|
|||||||
@@ -25,3 +25,28 @@ func (repository *MediaLoFiRepository) FindAll(context context.Context) ([]model
|
|||||||
|
|
||||||
return lofis, nil
|
return lofis, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaLoFiRepository) GetById(context context.Context, id string) (models.MediaLoFi, error) {
|
||||||
|
var lofi = models.MediaLoFi{ID: id}
|
||||||
|
slog.Info("MediaLoFiRepository#GetById", "id", id)
|
||||||
|
result := repository.db.First(&lofi)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaLoFiRepository#GetById", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
return lofi, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaLoFiRepository) Add(context context.Context, url string) (models.MediaLoFi, error) {
|
||||||
|
slog.Info("MediaLoFiRepository#Add", "url", url)
|
||||||
|
panic("unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaLoFiRepository) Delete(context context.Context, id string) error {
|
||||||
|
var actor = models.MediaLoFi{ID: id}
|
||||||
|
slog.Info("MediaLoFiRepository#Delete", "id", id)
|
||||||
|
result := repository.db.Delete(&actor)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaLoFiRepository#Delete", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,13 +101,17 @@ func New(admin *handlers.AdminHandler, bookshelf *handlers.BookshelfHandler, com
|
|||||||
secured.GET("comics/storyarcs", comics.StoryArcHandler.List)
|
secured.GET("comics/storyarcs", comics.StoryArcHandler.List)
|
||||||
secured.GET("comics/comicworks", comics.ComicworkHandler.List)
|
secured.GET("comics/comicworks", comics.ComicworkHandler.List)
|
||||||
secured.GET("comics/issueworks", comics.IssueworkHandler.List)
|
secured.GET("comics/issueworks", comics.IssueworkHandler.List)
|
||||||
secured.GET("media/files", media.MediaFileHandler.List)
|
mediaGroup := secured.Group("/media")
|
||||||
secured.GET("media/videos", media.MediaVideoHandler.List)
|
mediaGroup.GET("/files", media.MediaFileHandler.List)
|
||||||
secured.GET("media/lofis", media.MediaLoFiHandler.List)
|
mediaGroup.GET("/videos", media.MediaVideoHandler.List)
|
||||||
secured.GET("media/actors", media.MediaActorHandler.List)
|
mediaGroup.GET("/lofis", media.MediaLoFiHandler.List)
|
||||||
secured.GET("media/actors/:id", media.MediaActorHandler.Get)
|
mediaGroup.POST("/lofis", media.MediaLoFiHandler.Add)
|
||||||
secured.DELETE("media/actors/:id", media.MediaActorHandler.Delete)
|
mediaGroup.GET("/lofis/:id", media.MediaLoFiHandler.Get)
|
||||||
secured.GET("media/actorfiles", media.MediaActorFileHandler.List)
|
mediaGroup.DELETE("/lofis", media.MediaLoFiHandler.Delete)
|
||||||
|
mediaGroup.GET("/actors", media.MediaActorHandler.List)
|
||||||
|
mediaGroup.GET("/actors/:id", media.MediaActorHandler.Get)
|
||||||
|
mediaGroup.DELETE("/actors/:id", media.MediaActorHandler.Delete)
|
||||||
|
mediaGroup.GET("/actorfiles", media.MediaActorFileHandler.List)
|
||||||
}
|
}
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,3 +20,18 @@ func (service *MediaLoFiService) List(context context.Context) ([]models.MediaLo
|
|||||||
slog.Info("MediaLoFiService#List")
|
slog.Info("MediaLoFiService#List")
|
||||||
return service.repository.FindAll(context)
|
return service.repository.FindAll(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (service *MediaLoFiService) Get(context context.Context, id string) (models.MediaLoFi, error) {
|
||||||
|
slog.Info("MediaLoFiService#Get")
|
||||||
|
return service.repository.GetById(context, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaLoFiService) Add(context context.Context, url string) (models.MediaLoFi, error) {
|
||||||
|
slog.Info("MediaLoFiService#Add")
|
||||||
|
return service.repository.Add(context, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *MediaLoFiService) Delete(context context.Context, id string) error {
|
||||||
|
slog.Info("MediaLoFiService#Delete")
|
||||||
|
return service.repository.Delete(context, id)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user