diff --git a/cmd/evening_detective_server/main.go b/cmd/evening_detective_server/main.go index 4eb6c5c..d76207d 100644 --- a/cmd/evening_detective_server/main.go +++ b/cmd/evening_detective_server/main.go @@ -87,7 +87,7 @@ func main() { ) gameRepo := games_repo.NewGamesRepo(dbpool) teamRepo := teams_repo.NewTeamsRepo(dbpool) - storyteller := storytelling.NewStory() + storyteller := storytelling.NewStory(cleaner) actionsRepo := actions_repo.NewActionsRepo(dbpool) applicationsRepo := applications_repo.NewApplicationsRepo(dbpool) gameService := game_service.NewGameService( diff --git a/internal/modules/storytelling/dependency.go b/internal/modules/storytelling/dependency.go new file mode 100644 index 0000000..cf685c7 --- /dev/null +++ b/internal/modules/storytelling/dependency.go @@ -0,0 +1,5 @@ +package storytelling + +type ICleaner interface { + ClearCode(code string) string +} diff --git a/internal/modules/storytelling/story.go b/internal/modules/storytelling/story.go index 984bf0d..0e01f08 100644 --- a/internal/modules/storytelling/story.go +++ b/internal/modules/storytelling/story.go @@ -1,9 +1,15 @@ package storytelling -type story struct{} +type story struct { + cleaner ICleaner +} -func NewStory() IStory { - return &story{} +func NewStory( + cleaner ICleaner, +) IStory { + return &story{ + cleaner: cleaner, + } } func (s *story) GetStory( @@ -69,7 +75,7 @@ func (s *story) findPlace( code string, ) (*Place, bool) { for _, place := range scenario.Places { - if place.Code == code { + if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) { return place, true } } @@ -95,7 +101,7 @@ func (s *story) findResultPlace( } } for _, place := range scenario.Places { - if place.Code == code { + if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) { if place.Hidden && !open { return nil, false } diff --git a/internal/modules/storytelling/story_test.go b/internal/modules/storytelling/story_test.go index 03193e0..579cff6 100644 --- a/internal/modules/storytelling/story_test.go +++ b/internal/modules/storytelling/story_test.go @@ -1,6 +1,7 @@ package storytelling import ( + "evening_detective_server/internal/modules/cleaner" "testing" "github.com/stretchr/testify/assert" @@ -49,6 +50,28 @@ func Test_story_GetStory(t *testing.T) { }, }, }, + { + name: "Получение точки проверка регистра", + scenario: &Story{ + Places: []*Place{ + { + Code: "Ы-1", + Name: "Название точки", + Text: "Текст точки.", + }, + }, + }, + codes: []string{"ы1"}, + want: &Story{ + Places: []*Place{ + { + Code: "Ы-1", + Name: "Название точки", + Text: "Текст точки.", + }, + }, + }, + }, { name: "Получение 2 точек", scenario: &Story{ @@ -709,7 +732,7 @@ func Test_story_GetStory(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := NewStory().GetStory(tt.scenario, tt.codes) + got := NewStory(cleaner.NewCleaner()).GetStory(tt.scenario, tt.codes) assert.Equal(t, got, tt.want) }) } diff --git a/internal/services/scenarios_service/service.go b/internal/services/scenarios_service/service.go index 29d56d9..878802e 100644 --- a/internal/services/scenarios_service/service.go +++ b/internal/services/scenarios_service/service.go @@ -171,8 +171,7 @@ func (s *ScenarioService) getStory(ctx context.Context, id int) (*storytelling.S func (s *ScenarioService) updateStory(ctx context.Context, id int, story *storytelling.Story) error { mapCodes := map[string]struct{}{} for _, place := range story.Places { - code := s.cleaner.ClearCode(place.Code) - mapCodes[code] = struct{}{} + mapCodes[place.Code] = struct{}{} place.Image = strings.TrimPrefix(place.Image, s.domain) } if len(mapCodes) != len(story.Places) { @@ -181,11 +180,9 @@ func (s *ScenarioService) updateStory(ctx context.Context, id int, story *storyt cleanPlaces := make([]*storytelling.Place, 0, len(story.Places)) for _, place := range story.Places { - code := s.cleaner.ClearCode(place.Code) - if code == "" { + if place.Code == "" { continue } - place.Code = code cleanPlaces = append(cleanPlaces, place) } story.Places = cleanPlaces