generated from VLADIMIR/template
add scenarios methods
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/services/scenarios_service"
|
||||
proto "evening_detective_server/proto"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func mapScenarios(o []*scenarios_service.Scenario) []*proto.Scenario {
|
||||
res := make([]*proto.Scenario, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, mapScenario(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapScenario(o *scenarios_service.Scenario) *proto.Scenario {
|
||||
var publishedAt *timestamppb.Timestamp
|
||||
if o.PublishedAt != nil {
|
||||
publishedAt = timestamppb.New(*o.PublishedAt)
|
||||
}
|
||||
return &proto.Scenario{
|
||||
Id: int32(o.ID),
|
||||
Name: o.Name,
|
||||
Description: o.Description,
|
||||
Image: o.Image,
|
||||
Story: mapStory(o.Story),
|
||||
Author: mapUser(o.Author),
|
||||
UpdatedAt: timestamppb.New(o.UpdatedAt),
|
||||
CreatedAt: timestamppb.New(o.CreatedAt),
|
||||
PublishedAt: publishedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func mapStory(o *storytelling.Story) *proto.Story {
|
||||
return &proto.Story{
|
||||
Places: mapPlaces(o.Places),
|
||||
}
|
||||
}
|
||||
|
||||
func mapPlaces(o []*storytelling.Place) []*proto.Place {
|
||||
res := make([]*proto.Place, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, mapPlace(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapPlace(o *storytelling.Place) *proto.Place {
|
||||
return &proto.Place{
|
||||
Code: o.Code,
|
||||
Name: o.Name,
|
||||
Text: o.Text,
|
||||
Image: o.Image,
|
||||
Hidden: o.Hidden,
|
||||
Applications: mapApplications(o.Applications),
|
||||
Doors: mapDoors(o.Doors),
|
||||
Keys: mapKeys(o.Keys),
|
||||
}
|
||||
}
|
||||
|
||||
func mapApplications(o []*storytelling.Application) []*proto.Application {
|
||||
res := make([]*proto.Application, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, mapApplication(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapDoors(o []*storytelling.Door) []*proto.Door {
|
||||
res := make([]*proto.Door, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, mapDoor(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapKeys(o []*storytelling.Key) []*proto.Key {
|
||||
res := make([]*proto.Key, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, mapKey(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapApplication(o *storytelling.Application) *proto.Application {
|
||||
return &proto.Application{
|
||||
Name: o.Name,
|
||||
Image: o.Image,
|
||||
}
|
||||
}
|
||||
|
||||
func mapDoor(o *storytelling.Door) *proto.Door {
|
||||
return &proto.Door{
|
||||
Code: o.Code,
|
||||
Name: o.Name,
|
||||
Keys: mapKeys(o.Keys),
|
||||
}
|
||||
}
|
||||
|
||||
func mapKey(o *storytelling.Key) *proto.Key {
|
||||
return &proto.Key{
|
||||
Name: o.Name,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user