core/internal/port/internal/apimodel/village.go

41 lines
909 B
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 NewListVillagesResponse(res domain.ListVillagesWithRelationsResult) ListVillagesResponse {
versions := res.Villages()
resp := ListVillagesResponse{
Data: make([]Village, 0, len(versions)),
Cursor: Cursor{
Next: res.Next().Encode(),
Self: res.Self().Encode(),
},
}
for _, v := range versions {
resp.Data = append(resp.Data, NewVillage(v))
}
return resp
}