generated from VLADIMIR/template
fix codes
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package storytelling
|
||||
|
||||
type ICleaner interface {
|
||||
ClearCode(code string) string
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user