generated from VLADIMIR/template
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"evening_detective_server/internal/modules/game_model"
|
|
"evening_detective_server/proto"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func mapGame(
|
|
o *game_model.Game,
|
|
) *proto.Game {
|
|
location := ""
|
|
if o.Location != nil {
|
|
location = *o.Location
|
|
}
|
|
var startedAt *timestamppb.Timestamp
|
|
if o.StartedAt != nil {
|
|
startedAt = timestamppb.New(*o.StartedAt)
|
|
}
|
|
var endedAt *timestamppb.Timestamp
|
|
if o.EndedAt != nil {
|
|
endedAt = timestamppb.New(*o.EndedAt)
|
|
}
|
|
|
|
teams := make([]*proto.Team, 0, len(o.Teams))
|
|
for _, team := range o.Teams {
|
|
teams = append(teams, mapTeamDetails(team))
|
|
}
|
|
return &proto.Game{
|
|
Id: int32(o.ID),
|
|
Name: o.Name,
|
|
Description: o.Description,
|
|
Location: location,
|
|
StartAt: timestamppb.New(o.StartAt),
|
|
Status: o.Status,
|
|
Format: o.Format,
|
|
Scenario: mapScenario(o.Scenario),
|
|
Teams: teams,
|
|
StartedAt: startedAt,
|
|
EndedAt: endedAt,
|
|
}
|
|
}
|
|
|
|
func mapGames(
|
|
o []*game_model.Game,
|
|
) []*proto.Game {
|
|
res := make([]*proto.Game, 0, len(o))
|
|
for _, item := range o {
|
|
res = append(res, mapGame(item))
|
|
}
|
|
return res
|
|
}
|