generated from VLADIMIR/template
fix codes
This commit is contained in:
@@ -87,7 +87,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
gameRepo := games_repo.NewGamesRepo(dbpool)
|
gameRepo := games_repo.NewGamesRepo(dbpool)
|
||||||
teamRepo := teams_repo.NewTeamsRepo(dbpool)
|
teamRepo := teams_repo.NewTeamsRepo(dbpool)
|
||||||
storyteller := storytelling.NewStory()
|
storyteller := storytelling.NewStory(cleaner)
|
||||||
actionsRepo := actions_repo.NewActionsRepo(dbpool)
|
actionsRepo := actions_repo.NewActionsRepo(dbpool)
|
||||||
applicationsRepo := applications_repo.NewApplicationsRepo(dbpool)
|
applicationsRepo := applications_repo.NewApplicationsRepo(dbpool)
|
||||||
gameService := game_service.NewGameService(
|
gameService := game_service.NewGameService(
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package storytelling
|
||||||
|
|
||||||
|
type ICleaner interface {
|
||||||
|
ClearCode(code string) string
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package storytelling
|
package storytelling
|
||||||
|
|
||||||
type story struct{}
|
type story struct {
|
||||||
|
cleaner ICleaner
|
||||||
|
}
|
||||||
|
|
||||||
func NewStory() IStory {
|
func NewStory(
|
||||||
return &story{}
|
cleaner ICleaner,
|
||||||
|
) IStory {
|
||||||
|
return &story{
|
||||||
|
cleaner: cleaner,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *story) GetStory(
|
func (s *story) GetStory(
|
||||||
@@ -69,7 +75,7 @@ func (s *story) findPlace(
|
|||||||
code string,
|
code string,
|
||||||
) (*Place, bool) {
|
) (*Place, bool) {
|
||||||
for _, place := range scenario.Places {
|
for _, place := range scenario.Places {
|
||||||
if place.Code == code {
|
if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) {
|
||||||
return place, true
|
return place, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +101,7 @@ func (s *story) findResultPlace(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, place := range scenario.Places {
|
for _, place := range scenario.Places {
|
||||||
if place.Code == code {
|
if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) {
|
||||||
if place.Hidden && !open {
|
if place.Hidden && !open {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package storytelling
|
package storytelling
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"evening_detective_server/internal/modules/cleaner"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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 точек",
|
name: "Получение 2 точек",
|
||||||
scenario: &Story{
|
scenario: &Story{
|
||||||
@@ -709,7 +732,7 @@ func Test_story_GetStory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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)
|
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 {
|
func (s *ScenarioService) updateStory(ctx context.Context, id int, story *storytelling.Story) error {
|
||||||
mapCodes := map[string]struct{}{}
|
mapCodes := map[string]struct{}{}
|
||||||
for _, place := range story.Places {
|
for _, place := range story.Places {
|
||||||
code := s.cleaner.ClearCode(place.Code)
|
mapCodes[place.Code] = struct{}{}
|
||||||
mapCodes[code] = struct{}{}
|
|
||||||
place.Image = strings.TrimPrefix(place.Image, s.domain)
|
place.Image = strings.TrimPrefix(place.Image, s.domain)
|
||||||
}
|
}
|
||||||
if len(mapCodes) != len(story.Places) {
|
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))
|
cleanPlaces := make([]*storytelling.Place, 0, len(story.Places))
|
||||||
for _, place := range story.Places {
|
for _, place := range story.Places {
|
||||||
code := s.cleaner.ClearCode(place.Code)
|
if place.Code == "" {
|
||||||
if code == "" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
place.Code = code
|
|
||||||
cleanPlaces = append(cleanPlaces, place)
|
cleanPlaces = append(cleanPlaces, place)
|
||||||
}
|
}
|
||||||
story.Places = cleanPlaces
|
story.Places = cleanPlaces
|
||||||
|
|||||||
Reference in New Issue
Block a user