generated from VLADIMIR/template
add logic
This commit is contained in:
parent
e1b342d12c
commit
73838d7773
|
@ -2,6 +2,7 @@ package services
|
|||
|
||||
import (
|
||||
"evening_detective/internal/models"
|
||||
"evening_detective/internal/services/story_service"
|
||||
"evening_detective/proto"
|
||||
)
|
||||
|
||||
|
@ -32,3 +33,9 @@ func mapActionToProtoAction(action *models.Action) *proto.Action {
|
|||
Place: action.Place,
|
||||
}
|
||||
}
|
||||
|
||||
func mapApplicationToProtoApplication(application *story_service.Application) *proto.Application {
|
||||
return &proto.Application{
|
||||
Name: application.Name,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,13 @@ func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*pro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
place, err := s.storyService.GetPlace(req.Place)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actions := []*models.Action{
|
||||
{
|
||||
Place: req.Place,
|
||||
Place: place.Code,
|
||||
TeamID: team.ID,
|
||||
},
|
||||
}
|
||||
|
@ -79,6 +83,10 @@ func (s *Services) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.G
|
|||
return nil, err
|
||||
}
|
||||
newAction.Text = place.Text
|
||||
newAction.Applications = make([]*proto.Application, 0, len(place.Applications))
|
||||
for _, application := range place.Applications {
|
||||
newAction.Applications = append(newAction.Applications, mapApplicationToProtoApplication(application))
|
||||
}
|
||||
res = append(res, newAction)
|
||||
}
|
||||
return &proto.GetTeamRsp{Actions: res}, err
|
||||
|
|
|
@ -3,7 +3,9 @@ package story_service
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Story struct {
|
||||
|
@ -13,6 +15,11 @@ type Story struct {
|
|||
type Place struct {
|
||||
Code string `json:"code"`
|
||||
Text string `json:"text"`
|
||||
Applications []*Application `json:"applications"`
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type StoryService struct {
|
||||
|
@ -32,10 +39,16 @@ func NewStoryService() (*StoryService, error) {
|
|||
}
|
||||
|
||||
func (s *StoryService) GetPlace(code string) (*Place, error) {
|
||||
code = clearCode(code)
|
||||
for _, place := range s.story.Places {
|
||||
if place.Code == code {
|
||||
if clearCode(place.Code) == code {
|
||||
return place, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("place not found")
|
||||
return nil, errors.New(fmt.Sprintf("place not found: %s", code))
|
||||
}
|
||||
|
||||
func clearCode(code string) string {
|
||||
code = strings.ToLower(code)
|
||||
return strings.ReplaceAll(code, "-", "")
|
||||
}
|
||||
|
|
|
@ -5,9 +5,30 @@
|
|||
"text": "Вас приветствуют волонтеры, говорят что игорек где-то здесь, но точно они не знают.",
|
||||
"applications": [
|
||||
{
|
||||
"name": "Карта"
|
||||
"name": "Карта площадки"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "М-1",
|
||||
"text": "Ребята делают мод для майнкрафта, не стоит их беспокоить."
|
||||
},
|
||||
{
|
||||
"code": "О-1",
|
||||
"text": "Организаторы говорят что игорек убежал на пробежку и если поторопиться его можно успеть поймать.",
|
||||
"applications": [
|
||||
{
|
||||
"name": "Карта базы"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "Б-1",
|
||||
"text": "Тут его нет, вы чествуете только прохладный ветер."
|
||||
},
|
||||
{
|
||||
"code": "Б-2",
|
||||
"text": "А вот и он уже делает зарядку!"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue