generated from VLADIMIR/template
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"evening_detective_server/internal/services/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),
|
|
Export: mapGameExport(o.Export),
|
|
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
|
|
}
|
|
|
|
func mapGameSummary(game *game_model.Game) *proto.Game {
|
|
location := ""
|
|
if game.Location != nil {
|
|
location = *game.Location
|
|
}
|
|
return &proto.Game{
|
|
ID: int32(game.ID),
|
|
Name: game.Name,
|
|
Description: game.Description,
|
|
Format: game.Format,
|
|
Location: location,
|
|
StartAt: timestamppb.New(game.StartAt),
|
|
Status: game.Status,
|
|
}
|
|
}
|
|
|
|
func mapGameSettings(game *game_model.Game) *proto.Game {
|
|
result := mapGame(game)
|
|
result.WifiName = game.WiFiName
|
|
result.WifiPassword = game.WiFiPassword
|
|
return result
|
|
}
|