41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package apimodel
|
|
|
|
import (
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
|
oapitypes "github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
func NewTribeSnapshot(withRelations domain.TribeSnapshotWithRelations) TribeSnapshot {
|
|
tc := withRelations.TribeSnapshot()
|
|
return TribeSnapshot{
|
|
AllPoints: tc.AllPoints(),
|
|
Date: oapitypes.Date{Time: tc.Date()},
|
|
Dominance: tc.Dominance(),
|
|
Id: tc.ID(),
|
|
NumMembers: tc.NumMembers(),
|
|
NumVillages: tc.NumVillages(),
|
|
OpponentsDefeated: NewTribeOpponentsDefeated(tc.OD()),
|
|
Points: tc.Points(),
|
|
Rank: tc.Rank(),
|
|
Tribe: NewTribeMeta(withRelations.Tribe()),
|
|
}
|
|
}
|
|
|
|
func NewListTribeSnapshotsResponse(res domain.ListTribeSnapshotsWithRelationsResult) ListTribeSnapshotsResponse {
|
|
tcs := res.TribeSnapshots()
|
|
|
|
resp := ListTribeSnapshotsResponse{
|
|
Data: make([]TribeSnapshot, 0, len(tcs)),
|
|
Cursor: Cursor{
|
|
Next: res.Next().Encode(),
|
|
Self: res.Self().Encode(),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
resp.Data = append(resp.Data, NewTribeSnapshot(tc))
|
|
}
|
|
|
|
return resp
|
|
}
|