Files
kontor/kontor-gin/internal/cmd/sync.go
T
tpeetz bc88c694ee
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
add MediaLofi in kontor-gin (#97)
Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de>
Reviewed-on: #97
2026-10-09 16:26:11 +00:00

48 lines
1.2 KiB
Go

package cmd
import (
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"log/slog"
"reflect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Sync Kontor Database",
Long: "Sync Kontor Database",
// Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
slog.Info("sync kontor")
apiVersion := viper.GetString("api")
mainServer := config.Config.Server["main"]
if config.Verbose > 2 {
slog.Info("syncCmd#Run", "mainServer", mainServer)
}
localServer := config.Config.Server["local"]
sourceData, _ := api.GetData(mainServer, apiVersion)
targetData, _ := api.GetData(localServer, apiVersion)
if config.Verbose > 2 {
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)
case "players":
sourceData.Player.CompareIds(&targetData.Player)
}
}
},
}
func init() {
rootCmd.AddCommand(syncCmd)
}