generated from VLADIMIR/template
add given applications
This commit is contained in:
@@ -14,6 +14,7 @@ func (s *story) GetStory(
|
|||||||
keys := map[string]struct{}{}
|
keys := map[string]struct{}{}
|
||||||
codesWithUseActions := map[string]struct{}{}
|
codesWithUseActions := map[string]struct{}{}
|
||||||
codesHidden := map[string]struct{}{}
|
codesHidden := map[string]struct{}{}
|
||||||
|
givenApplications := map[string]struct{}{}
|
||||||
for i, code := range codes {
|
for i, code := range codes {
|
||||||
var prevPlace *Place
|
var prevPlace *Place
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@@ -54,10 +55,11 @@ func (s *story) GetStory(
|
|||||||
story.Places = append(story.Places, s.buildNotFoundPlace(code))
|
story.Places = append(story.Places, s.buildNotFoundPlace(code))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
story.Places = append(
|
newPlace := s.mapPlace(place, nextPlace, codesWithUseActions, keys, givenApplications)
|
||||||
story.Places,
|
story.Places = append(story.Places, newPlace)
|
||||||
s.mapPlace(place, nextPlace, codesWithUseActions, keys),
|
for _, application := range newPlace.Applications {
|
||||||
)
|
givenApplications[application.Name] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return story
|
return story
|
||||||
}
|
}
|
||||||
@@ -116,11 +118,15 @@ func (s *story) mapPlace(
|
|||||||
nextPlace *Place,
|
nextPlace *Place,
|
||||||
codesWithUseActions map[string]struct{},
|
codesWithUseActions map[string]struct{},
|
||||||
keys map[string]struct{},
|
keys map[string]struct{},
|
||||||
|
givenApplications map[string]struct{},
|
||||||
) *Place {
|
) *Place {
|
||||||
var applications []*Application
|
var applications []*Application
|
||||||
if len(place.Applications) > 0 {
|
if len(place.Applications) > 0 {
|
||||||
applications = make([]*Application, 0, len(place.Applications))
|
applications = make([]*Application, 0, len(place.Applications))
|
||||||
for _, application := range place.Applications {
|
for _, application := range place.Applications {
|
||||||
|
if _, ok := givenApplications[application.Name]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
applications = append(
|
applications = append(
|
||||||
applications,
|
applications,
|
||||||
&Application{
|
&Application{
|
||||||
@@ -130,6 +136,10 @@ func (s *story) mapPlace(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(applications) == 0 {
|
||||||
|
applications = nil
|
||||||
|
}
|
||||||
|
|
||||||
var doors []*Door
|
var doors []*Door
|
||||||
_, useAction := codesWithUseActions[place.Code]
|
_, useAction := codesWithUseActions[place.Code]
|
||||||
if len(place.Doors) > 0 && !useAction {
|
if len(place.Doors) > 0 && !useAction {
|
||||||
@@ -161,6 +171,7 @@ func (s *story) mapPlace(
|
|||||||
if len(doors) == 0 {
|
if len(doors) == 0 {
|
||||||
doors = nil
|
doors = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Place{
|
return &Place{
|
||||||
Code: place.Code,
|
Code: place.Code,
|
||||||
Name: place.Name,
|
Name: place.Name,
|
||||||
|
|||||||
@@ -162,6 +162,45 @@ func Test_story_GetStory(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Улики не повторяются",
|
||||||
|
scenario: &Story{
|
||||||
|
Places: []*Place{
|
||||||
|
{
|
||||||
|
Code: "Ы",
|
||||||
|
Name: "Название точки",
|
||||||
|
Text: "Текст точки.",
|
||||||
|
Applications: []*Application{
|
||||||
|
{
|
||||||
|
Name: "Название улики",
|
||||||
|
Image: "image.png",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
codes: []string{"Ы", "Ы"},
|
||||||
|
want: &Story{
|
||||||
|
Places: []*Place{
|
||||||
|
{
|
||||||
|
Code: "Ы",
|
||||||
|
Name: "Название точки",
|
||||||
|
Text: "Текст точки.",
|
||||||
|
Applications: []*Application{
|
||||||
|
{
|
||||||
|
Name: "Название улики",
|
||||||
|
Image: "image.png",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Code: "Ы",
|
||||||
|
Name: "Название точки",
|
||||||
|
Text: "Текст точки.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Получение точки с действием",
|
name: "Получение точки с действием",
|
||||||
scenario: &Story{
|
scenario: &Story{
|
||||||
|
|||||||
Reference in New Issue
Block a user