37 lines
900 B
Go
37 lines
900 B
Go
package cmd
|
|
|
|
import (
|
|
"kontor-api-gin/internal/api"
|
|
"log/slog"
|
|
"reflect"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
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")
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(syncCmd)
|
|
}
|