This commit is contained in:
@@ -19,96 +19,85 @@ var exportCmd = &cobra.Command{
|
||||
slog.Info("export kontor")
|
||||
slog.Info("Verbosity level", "level", verbose)
|
||||
var login LoginResponse
|
||||
|
||||
client := resty.New()
|
||||
_, err := client.R().
|
||||
SetBody(Login{
|
||||
Email: "thomas.peetz@thpeetz.de",
|
||||
Password: "admin",
|
||||
}).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&login).
|
||||
Post("http://127.0.0.1:8550/api/login")
|
||||
if err != nil {
|
||||
slog.Info("Health", "error", err.Error())
|
||||
}
|
||||
slog.Info("health", "token", login.Token)
|
||||
PostJSON(client, "http://127.0.0.1:8550/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"`
|
||||
Comic []models.ComicDTO `json:"comic"`
|
||||
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"`
|
||||
}
|
||||
|
||||
var sports []models.SportDTO
|
||||
_, err = client.R().
|
||||
SetAuthToken(login.Token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&sports).
|
||||
Get("http://127.0.0.1:8550/api/v1/tysc/sports")
|
||||
if err != nil {
|
||||
slog.Info("sports", "error", err.Error())
|
||||
}
|
||||
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
|
||||
)
|
||||
|
||||
var players []models.PlayerDTO
|
||||
_, err = client.R().
|
||||
SetAuthToken(login.Token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&players).
|
||||
Get("http://127.0.0.1:8550/api/v1/tysc/players")
|
||||
if err != nil {
|
||||
slog.Info("players", "error", err.Error())
|
||||
registry := map[string]any{
|
||||
"http://127.0.0.1:8550/api/v1/tysc/sports": &sports,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/players": &players,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/teams": &teams,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/positions": &positions,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/roosters": &roosters,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/vendors": &vendors,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/cardsets": &cardsets,
|
||||
"http://127.0.0.1:8550/api/v1/tysc/cards": &cards,
|
||||
"http://127.0.0.1:8550/api/v1/comics/artists": &artists,
|
||||
"http://127.0.0.1:8550/api/v1/comics/publishers": &publishers,
|
||||
"http://127.0.0.1:8550/api/v1/comics/worktypes": &worktypes,
|
||||
"http://127.0.0.1:8550/api/v1/comics/comics": &comics,
|
||||
"http://127.0.0.1:8550/api/v1/comics/volumes": &volumes,
|
||||
"http://127.0.0.1:8550/api/v1/comics/storyarcs": &storyarcs,
|
||||
"http://127.0.0.1:8550/api/v1/comics/issues": &issues,
|
||||
}
|
||||
|
||||
var teams []models.TeamDTO
|
||||
_, err = client.R().
|
||||
SetAuthToken(login.Token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&teams).
|
||||
Get("http://127.0.0.1:8550/api/v1/tysc/teams")
|
||||
if err != nil {
|
||||
slog.Info("teams", "error", err.Error())
|
||||
for url, value := range registry {
|
||||
GetJSON(client, login.Token, url, value)
|
||||
}
|
||||
|
||||
var positions []models.PositionDTO
|
||||
_, err = client.R().
|
||||
SetAuthToken(login.Token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&positions).
|
||||
Get("http://127.0.0.1:8550/api/v1/tysc/positions")
|
||||
if err != nil {
|
||||
slog.Info("teams", "error", err.Error())
|
||||
}
|
||||
|
||||
var comics []models.ComicDTO
|
||||
_, err = client.R().
|
||||
SetAuthToken(login.Token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&comics).
|
||||
Get("http://127.0.0.1:8550/api/v1/comics/comics")
|
||||
if err != nil {
|
||||
slog.Info("comics", "error", err.Error())
|
||||
}
|
||||
// slog.Info("comics", "res", comics)
|
||||
|
||||
data := ExportData{
|
||||
Sport: sports,
|
||||
Player: players,
|
||||
Team: teams,
|
||||
Position: positions,
|
||||
Rooster: []models.RoosterDTO{},
|
||||
Vendor: []models.VendorDTO{},
|
||||
CardSet: []models.CardSetDTO{},
|
||||
Card: []models.CardDTO{},
|
||||
Comic: comics,
|
||||
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,
|
||||
}
|
||||
defer client.Close()
|
||||
jsonData, err := json.MarshalIndent(data, "", " ")
|
||||
jsonData, err := json.MarshalIndent(export, "", " ")
|
||||
if err != nil {
|
||||
slog.Info("JSON MarshalIndent failed", "Error:", err)
|
||||
}
|
||||
@@ -121,6 +110,32 @@ var exportCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func GetJSON(client *resty.Client, token string, url string, v any) {
|
||||
_, err := client.R().
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Get(url)
|
||||
if err != nil {
|
||||
slog.Info(url, "error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func PostJSON(client *resty.Client, url string, v any) {
|
||||
_, err := client.R().
|
||||
SetBody(Login{
|
||||
Email: "thomas.peetz@thpeetz.de",
|
||||
Password: "admin",
|
||||
}).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Post(url)
|
||||
if err != nil {
|
||||
slog.Info("Health", "error", err.Error())
|
||||
}
|
||||
slog.Info(url, "token", v)
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(exportCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user