This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -39,6 +41,37 @@ type MediaLoFiDTO struct {
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
type MediaLoFiDTOList []MediaLoFiDTO
|
||||
|
||||
func (source *MediaLoFiDTOList) CompareIds(target *MediaLoFiDTOList) (missing, obsolete []string) {
|
||||
sources := make(map[string]MediaLoFiDTO, len(*source))
|
||||
targets := make(map[string]MediaLoFiDTO, len(*target))
|
||||
for _, source := range *source {
|
||||
sources[source.ID] = source
|
||||
}
|
||||
for _, target := range *target {
|
||||
targets[target.ID] = target
|
||||
}
|
||||
// iterate source IDs
|
||||
for id := range sources {
|
||||
if _, ok := targets[id]; ok {
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
missing = append(missing, id)
|
||||
}
|
||||
}
|
||||
for id := range targets {
|
||||
if _, ok := sources[id]; ok {
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
obsolete = append(obsolete, id)
|
||||
}
|
||||
}
|
||||
slog.Info("CompareIds", "missing", len(missing), "obsolete", len(obsolete))
|
||||
slog.Debug("CompareIds", "missing", missing, "obsolete", obsolete)
|
||||
return missing, obsolete
|
||||
}
|
||||
|
||||
func ConvertMediaLoFisToDtos(media_lofis []MediaLoFi) []MediaLoFiDTO {
|
||||
dtos := make([]MediaLoFiDTO, len(media_lofis))
|
||||
for i, media_lofi := range media_lofis {
|
||||
|
||||
@@ -46,14 +46,14 @@ func (playerList *PlayerDTOList) CompareIds(target *PlayerDTOList) (missing, obs
|
||||
// iterate source IDs
|
||||
for id := range sources {
|
||||
if _, ok := targets[id]; ok {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
missing = append(missing, id)
|
||||
}
|
||||
}
|
||||
for id := range targets {
|
||||
if _, ok := sources[id]; ok {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
obsolete = append(obsolete, id)
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ func (sportList *SportDTOList) CompareIds(target *SportDTOList) (missing, obsole
|
||||
// iterate source IDs
|
||||
for id := range sources {
|
||||
if _, ok := targets[id]; ok {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
missing = append(missing, id)
|
||||
}
|
||||
}
|
||||
for id := range targets {
|
||||
if _, ok := sources[id]; ok {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
obsolete = append(obsolete, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user