generated from VLADIMIR/template
add places operations
This commit is contained in:
+37
-3
@@ -307,7 +307,18 @@ func (s *server) AddScenarioPlace(ctx context.Context, req *proto.AddScenarioPla
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
panic("unimplemented")
|
||||
err := s.scenarioService.AddScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
convertPlace(req.Place),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.AddScenarioPlaceRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.AddScenarioPlaceRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) UpdateScenarioPlace(ctx context.Context, req *proto.UpdateScenarioPlaceReq) (*proto.UpdateScenarioPlaceRsp, error) {
|
||||
@@ -316,7 +327,19 @@ func (s *server) UpdateScenarioPlace(ctx context.Context, req *proto.UpdateScena
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
panic("unimplemented")
|
||||
err := s.scenarioService.UpdateScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Code,
|
||||
convertPlace(req.Place),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.UpdateScenarioPlaceRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.UpdateScenarioPlaceRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScenarioPlaceReq) (*proto.DeleteScenarioPlaceRsp, error) {
|
||||
@@ -325,5 +348,16 @@ func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScena
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
panic("unimplemented")
|
||||
err := s.scenarioService.DeleteScenarioPlace(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Code,
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteScenarioPlaceRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.DeleteScenarioPlaceRsp{}, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"evening_detective_server/internal/modules/formatter_utils"
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/services/scenarios_service"
|
||||
proto "evening_detective_server/proto"
|
||||
@@ -105,3 +106,61 @@ func mapKey(o *storytelling.Key) *proto.Key {
|
||||
Name: o.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func convertPlace(o *proto.Place) *storytelling.Place {
|
||||
return &storytelling.Place{
|
||||
Code: o.Code,
|
||||
Name: formatter_utils.FormatString(o.Name),
|
||||
Text: formatter_utils.FormatText(o.Text),
|
||||
Image: o.Image,
|
||||
Hidden: o.Hidden,
|
||||
Applications: convertApplications(o.Applications),
|
||||
Doors: convertDoors(o.Doors),
|
||||
Keys: convertKeys(o.Keys),
|
||||
}
|
||||
}
|
||||
|
||||
func convertApplications(o []*proto.Application) []*storytelling.Application {
|
||||
res := make([]*storytelling.Application, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, convertApplication(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func convertDoors(o []*proto.Door) []*storytelling.Door {
|
||||
res := make([]*storytelling.Door, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, convertDoor(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func convertKeys(o []*proto.Key) []*storytelling.Key {
|
||||
res := make([]*storytelling.Key, 0, len(o))
|
||||
for _, item := range o {
|
||||
res = append(res, convertKey(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func convertApplication(o *proto.Application) *storytelling.Application {
|
||||
return &storytelling.Application{
|
||||
Name: formatter_utils.FormatString(o.Name),
|
||||
Image: o.Image,
|
||||
}
|
||||
}
|
||||
|
||||
func convertDoor(o *proto.Door) *storytelling.Door {
|
||||
return &storytelling.Door{
|
||||
Code: o.Code,
|
||||
Name: formatter_utils.FormatString(o.Name),
|
||||
Keys: convertKeys(o.Keys),
|
||||
}
|
||||
}
|
||||
|
||||
func convertKey(o *proto.Key) *storytelling.Key {
|
||||
return &storytelling.Key{
|
||||
Name: formatter_utils.FormatString(o.Name),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user