60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package apimodel
|
|
|
|
import (
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
|
)
|
|
|
|
func NewVillage(withRelations domain.VillageWithRelations) Village {
|
|
v := withRelations.Village()
|
|
return Village{
|
|
Bonus: v.Bonus(),
|
|
Continent: v.Continent(),
|
|
CreatedAt: v.CreatedAt(),
|
|
FullName: v.FullName(),
|
|
Id: v.ID(),
|
|
Name: v.Name(),
|
|
Points: v.Points(),
|
|
ProfileUrl: v.ProfileURL().String(),
|
|
X: v.X(),
|
|
Y: v.Y(),
|
|
Player: NewNullPlayerMeta(withRelations.Player()),
|
|
}
|
|
}
|
|
|
|
func NewVillageMeta(withRelations domain.VillageMetaWithRelations) VillageMeta {
|
|
v := withRelations.Village()
|
|
return VillageMeta{
|
|
Continent: v.Continent(),
|
|
FullName: v.FullName(),
|
|
Id: v.ID(),
|
|
Player: NewNullPlayerMeta(withRelations.Player()),
|
|
ProfileUrl: v.ProfileURL().String(),
|
|
X: v.X(),
|
|
Y: v.Y(),
|
|
}
|
|
}
|
|
|
|
func NewListVillagesResponse(res domain.ListVillagesWithRelationsResult) ListVillagesResponse {
|
|
villages := res.Villages()
|
|
|
|
resp := ListVillagesResponse{
|
|
Data: make([]Village, 0, len(villages)),
|
|
Cursor: Cursor{
|
|
Next: res.Next().Encode(),
|
|
Self: res.Self().Encode(),
|
|
},
|
|
}
|
|
|
|
for _, v := range villages {
|
|
resp.Data = append(resp.Data, NewVillage(v))
|
|
}
|
|
|
|
return resp
|
|
}
|
|
|
|
func NewGetVillageResponse(v domain.VillageWithRelations) GetVillageResponse {
|
|
return GetVillageResponse{
|
|
Data: NewVillage(v),
|
|
}
|
|
}
|