This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/JanikL/go-artemis/artemis"
|
||||
"github.com/go-stomp/stomp/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
var addLinkCmd = &cobra.Command{
|
||||
Use: "add-link",
|
||||
Short: "Add Link",
|
||||
@@ -14,8 +20,22 @@ var addLinkCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
slog.Info("add-link kontor started")
|
||||
sender := artemis.Sender{Addr: "localhost:61616", Dest: "add-link", Enc: artemis.EncodingJson}
|
||||
err := sender.Send("{ \"url\": \"https://example.com\" }")
|
||||
conn, err := stomp.Dial("tcp", "localhost:61616",
|
||||
stomp.ConnOpt.Login("artemis", "artemis"), // Provide username and password
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect to Artemis: %s", err)
|
||||
}
|
||||
defer conn.Disconnect()
|
||||
|
||||
// sender := artemis.Sender{Addr: "localhost:61616", Dest: "add-link", Enc: artemis.EncodingJson}
|
||||
link := &Link{Url: args[0]}
|
||||
b, jsonErr := json.Marshal(link)
|
||||
if jsonErr != nil {
|
||||
slog.Info("Json encoding failed", "error", jsonErr.Error())
|
||||
}
|
||||
err = conn.Send("/queue/add-link", "application/json", b)
|
||||
|
||||
if err != nil {
|
||||
slog.Info("send failed", "error", err.Error())
|
||||
}
|
||||
|
||||
@@ -1,18 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/go-stomp/stomp/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var addLinksCmd = &cobra.Command{
|
||||
Use: "add-links",
|
||||
Use: "add-links [file]",
|
||||
Short: "Add Links",
|
||||
Long: "Add Links",
|
||||
// Args: cobra.ExactArgs(1),
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
slog.Info("add Links")
|
||||
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]
|
||||
slog.Info(fmt.Sprintf("add Links from %s", fileName))
|
||||
lines, err := helpers.LinesInFile(fileName)
|
||||
if err != nil {
|
||||
slog.Warn("add links failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, line := range lines {
|
||||
b, jsonErr := json.Marshal(line)
|
||||
if jsonErr != nil {
|
||||
slog.Info("Json encoding failed", "error", jsonErr.Error())
|
||||
}
|
||||
err = conn.Send("media.link", "application/json", b)
|
||||
|
||||
if err != nil {
|
||||
slog.Info("send failed", "error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/api"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -32,172 +30,13 @@ var exportCmd = &cobra.Command{
|
||||
client := resty.New()
|
||||
PostJSON(client, fmt.Sprintf("%s/%s/%s", server, "api", "login"), &login)
|
||||
|
||||
type ExportData struct {
|
||||
Sport []models.SportDTO `json:"sport"`
|
||||
Player []models.PlayerDTO `json:"player"`
|
||||
Team []models.TeamDTO `json:"team"`
|
||||
Position []models.PositionDTO `json:"field_position"`
|
||||
Rooster []models.RoosterDTO `json:"rooster"`
|
||||
Vendor []models.VendorDTO `json:"vendor"`
|
||||
CardSet []models.CardSetDTO `json:"card_set"`
|
||||
Card []models.CardDTO `json:"card"`
|
||||
Artist []models.ArtistDTO `json:"artist"`
|
||||
Publisher []models.PublisherDTO `json:"publisher"`
|
||||
Worktype []models.WorkTypeDTO `json:"worktype"`
|
||||
Comic []models.ComicDTO `json:"comic"`
|
||||
Volume []models.VolumeDTO `json:"volume"`
|
||||
StoryArc []models.StoryArcDTO `json:"story_arc"`
|
||||
Issue []models.IssueDTO `json:"issue"`
|
||||
TradePaperback []models.TradePaperbackDTO `json:"trade_paperback"`
|
||||
ComicWork []models.ComicworkDTO `json:"comic_work"`
|
||||
IssueWork []models.IssueworkDTO `json:"issue_work"`
|
||||
Article []models.ArticleDTO `json:"article"`
|
||||
BookshelfPublisher []models.BookshelfPublisherDTO `json:"bookshelf_publisher"`
|
||||
Book []models.BookDTO `json:"book"`
|
||||
Author []models.AuthorDTO `json:"author"`
|
||||
ArticleAuthor []models.ArticleAuthorDTO `json:"article_author"`
|
||||
BookAuthor []models.BookAuthorDTO `json:"book_author"`
|
||||
MediaArticle []models.MediaArticleDTO `json:"media_article"`
|
||||
MediaVideo []models.MediaVideoDTO `json:"media_video"`
|
||||
MediaLoFi []models.MediaLoFiDTO `json:"media_lofi"`
|
||||
MediaFile []models.MediaFileDTO `json:"media_file"`
|
||||
MediaActor []models.MediaActorDTO `json:"media_actor"`
|
||||
MediaActorFile []models.MediaActorFileDTO `json:"media_actor_file"`
|
||||
Profile []models.ProfileDTO `json:"profile"`
|
||||
Permission []models.PermissionDTO `json:"permission"`
|
||||
Assignment []models.AssignmentDTO `json:"assignment"`
|
||||
Token []models.TokenDTO `json:"token"`
|
||||
MailAccount []models.MailAccountDTO `json:"mail_account"`
|
||||
Mail []models.MailDTO `json:"mail"`
|
||||
}
|
||||
|
||||
var (
|
||||
sports []models.SportDTO
|
||||
players []models.PlayerDTO
|
||||
teams []models.TeamDTO
|
||||
positions []models.PositionDTO
|
||||
roosters []models.RoosterDTO
|
||||
vendors []models.VendorDTO
|
||||
cardsets []models.CardSetDTO
|
||||
cards []models.CardDTO
|
||||
artists []models.ArtistDTO
|
||||
publishers []models.PublisherDTO
|
||||
worktypes []models.WorkTypeDTO
|
||||
comics []models.ComicDTO
|
||||
volumes []models.VolumeDTO
|
||||
storyarcs []models.StoryArcDTO
|
||||
issues []models.IssueDTO
|
||||
tradepaperbacks []models.TradePaperbackDTO
|
||||
comicworks []models.ComicworkDTO
|
||||
issueworks []models.IssueworkDTO
|
||||
articles []models.ArticleDTO
|
||||
bookshelf_publishers []models.BookshelfPublisherDTO
|
||||
books []models.BookDTO
|
||||
autors []models.AuthorDTO
|
||||
article_authors []models.ArticleAuthorDTO
|
||||
book_authors []models.BookAuthorDTO
|
||||
mediaarticles []models.MediaArticleDTO
|
||||
mediavideos []models.MediaVideoDTO
|
||||
mediaactors []models.MediaActorDTO
|
||||
mediaactorfiles []models.MediaActorFileDTO
|
||||
mediafiles []models.MediaFileDTO
|
||||
medialofis []models.MediaLoFiDTO
|
||||
profiles []models.ProfileDTO
|
||||
permissions []models.PermissionDTO
|
||||
assignments []models.AssignmentDTO
|
||||
tokens []models.TokenDTO
|
||||
mailaccounts []models.MailAccountDTO
|
||||
mail []models.MailDTO
|
||||
)
|
||||
|
||||
registry := map[string]any{
|
||||
"tysc/sports": &sports,
|
||||
"tysc/players": &players,
|
||||
"tysc/teams": &teams,
|
||||
"tysc/positions": &positions,
|
||||
"tysc/roosters": &roosters,
|
||||
"tysc/vendors": &vendors,
|
||||
"tysc/cardsets": &cardsets,
|
||||
"tysc/cards": &cards,
|
||||
"comics/artists": &artists,
|
||||
"comics/publishers": &publishers,
|
||||
"comics/worktypes": &worktypes,
|
||||
"comics/comics": &comics,
|
||||
"comics/volumes": &volumes,
|
||||
"comics/storyarcs": &storyarcs,
|
||||
"comics/issues": &issues,
|
||||
"comics/tradepaperbacks": &tradepaperbacks,
|
||||
"comics/comicworks": &comicworks,
|
||||
"comics/issueworks": &issueworks,
|
||||
"bookshelf/articles": &articles,
|
||||
"bookshelf/publishers": &bookshelf_publishers,
|
||||
"bookshelf/books": &books,
|
||||
"bookshelf/authors": &autors,
|
||||
"bookshelf/articleauthors": &article_authors,
|
||||
"bookshelf/bookauthors": &book_authors,
|
||||
"media/articles": &mediaarticles,
|
||||
"media/videos": &mediavideos,
|
||||
"media/actors": &mediaactors,
|
||||
"media/files": &mediafiles,
|
||||
"media/actorfiles": &mediaactorfiles,
|
||||
"media/lofis": &medialofis,
|
||||
"user/profiles": &profiles,
|
||||
"user/permissions": &permissions,
|
||||
"user/assignments": &assignments,
|
||||
"user/tokens": &tokens,
|
||||
"admin/mailaccounts": &mailaccounts,
|
||||
"user/mail": &mail,
|
||||
}
|
||||
for path, value := range registry {
|
||||
for path, value := range api.Registry {
|
||||
GetJSON(client, login.Token, fmt.Sprintf("%s/%s/%s", server, apiVersion, path), value)
|
||||
}
|
||||
export := ExportData{
|
||||
Sport: sports,
|
||||
Player: players,
|
||||
Team: teams,
|
||||
Position: positions,
|
||||
Rooster: roosters,
|
||||
Vendor: vendors,
|
||||
CardSet: cardsets,
|
||||
Card: cards,
|
||||
Artist: artists,
|
||||
Publisher: publishers,
|
||||
Worktype: worktypes,
|
||||
Comic: comics,
|
||||
Volume: volumes,
|
||||
StoryArc: storyarcs,
|
||||
Issue: issues,
|
||||
TradePaperback: tradepaperbacks,
|
||||
ComicWork: comicworks,
|
||||
IssueWork: issueworks,
|
||||
Article: articles,
|
||||
BookshelfPublisher: bookshelf_publishers,
|
||||
Book: books,
|
||||
Author: autors,
|
||||
ArticleAuthor: article_authors,
|
||||
BookAuthor: book_authors,
|
||||
MediaArticle: mediaarticles,
|
||||
MediaVideo: mediavideos,
|
||||
MediaActor: mediaactors,
|
||||
MediaActorFile: mediaactorfiles,
|
||||
MediaFile: mediafiles,
|
||||
MediaLoFi: medialofis,
|
||||
Profile: profiles,
|
||||
Permission: permissions,
|
||||
Assignment: assignments,
|
||||
Token: tokens,
|
||||
MailAccount: mailaccounts,
|
||||
Mail: mail,
|
||||
}
|
||||
defer client.Close()
|
||||
jsonData, err := json.MarshalIndent(export, "", " ")
|
||||
export, _ := api.GetData(server, apiVersion)
|
||||
err := api.WriteJson(export, filename)
|
||||
if err != nil {
|
||||
slog.Info("JSON MarshalIndent failed", "Error:", err)
|
||||
}
|
||||
// Write bytes to file
|
||||
err = os.WriteFile(filename, jsonData, 0644)
|
||||
if err != nil {
|
||||
slog.Info("Error writing file:", "Error", err)
|
||||
slog.Info("WriteJon failed", "Error:", err)
|
||||
}
|
||||
slog.Info("export kontor finished")
|
||||
},
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/api"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -13,6 +15,19 @@ var syncCmd = &cobra.Command{
|
||||
// Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
slog.Info("sync kontor")
|
||||
sourceData, _ := api.GetData(server, apiVersion)
|
||||
targetData, _ := api.GetData("https://kontor-gin.thpeetz.de", apiVersion)
|
||||
slog.Info("Size of targetData", "size", reflect.TypeOf(targetData).Size())
|
||||
// find missing items in target and collect items not available in source
|
||||
for table, item_list := range sourceData.GetMap() {
|
||||
slog.Info("iterate sourceData", "table", table, "count", reflect.TypeOf(item_list).Size())
|
||||
switch table {
|
||||
case "sports":
|
||||
sourceData.Sport.CompareIds(&targetData.Sport)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user