From c15106dc2d4a769930c078419cc9553335bc35b3 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Fri, 10 Jul 2026 01:45:31 +0700 Subject: [PATCH] add given applications --- internal/modules/storytelling/story.go | 19 +++++++--- internal/modules/storytelling/story_test.go | 39 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/internal/modules/storytelling/story.go b/internal/modules/storytelling/story.go index 8001fce..984bf0d 100644 --- a/internal/modules/storytelling/story.go +++ b/internal/modules/storytelling/story.go @@ -14,6 +14,7 @@ func (s *story) GetStory( keys := map[string]struct{}{} codesWithUseActions := map[string]struct{}{} codesHidden := map[string]struct{}{} + givenApplications := map[string]struct{}{} for i, code := range codes { var prevPlace *Place if i > 0 { @@ -54,10 +55,11 @@ func (s *story) GetStory( story.Places = append(story.Places, s.buildNotFoundPlace(code)) continue } - story.Places = append( - story.Places, - s.mapPlace(place, nextPlace, codesWithUseActions, keys), - ) + newPlace := s.mapPlace(place, nextPlace, codesWithUseActions, keys, givenApplications) + story.Places = append(story.Places, newPlace) + for _, application := range newPlace.Applications { + givenApplications[application.Name] = struct{}{} + } } return story } @@ -116,11 +118,15 @@ func (s *story) mapPlace( nextPlace *Place, codesWithUseActions map[string]struct{}, keys map[string]struct{}, + givenApplications map[string]struct{}, ) *Place { var applications []*Application if len(place.Applications) > 0 { applications = make([]*Application, 0, len(place.Applications)) for _, application := range place.Applications { + if _, ok := givenApplications[application.Name]; ok { + continue + } applications = append( applications, &Application{ @@ -130,6 +136,10 @@ func (s *story) mapPlace( ) } } + if len(applications) == 0 { + applications = nil + } + var doors []*Door _, useAction := codesWithUseActions[place.Code] if len(place.Doors) > 0 && !useAction { @@ -161,6 +171,7 @@ func (s *story) mapPlace( if len(doors) == 0 { doors = nil } + return &Place{ Code: place.Code, Name: place.Name, diff --git a/internal/modules/storytelling/story_test.go b/internal/modules/storytelling/story_test.go index 156c1af..03193e0 100644 --- a/internal/modules/storytelling/story_test.go +++ b/internal/modules/storytelling/story_test.go @@ -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: "Получение точки с действием", scenario: &Story{