generated from VLADIMIR/template
add game
This commit is contained in:
@@ -3,6 +3,7 @@ package scenarios_service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"evening_detective_server/internal/modules/cleaner"
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/repos/scenarios_repo"
|
||||
"strings"
|
||||
@@ -10,15 +11,18 @@ import (
|
||||
|
||||
type ScenarioService struct {
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo
|
||||
cleaner cleaner.ICleaner
|
||||
domain string
|
||||
}
|
||||
|
||||
func NewScenarioService(
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo,
|
||||
cleaner cleaner.ICleaner,
|
||||
domain string,
|
||||
) *ScenarioService {
|
||||
return &ScenarioService{
|
||||
scenariosRepo: scenariosRepo,
|
||||
cleaner: cleaner,
|
||||
domain: domain,
|
||||
}
|
||||
}
|
||||
@@ -167,7 +171,8 @@ 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 {
|
||||
mapCodes[place.Code] = struct{}{}
|
||||
code := s.cleaner.ClearCode(place.Code)
|
||||
mapCodes[code] = struct{}{}
|
||||
place.Image = strings.TrimPrefix(place.Image, s.domain)
|
||||
}
|
||||
if len(mapCodes) != len(story.Places) {
|
||||
@@ -176,9 +181,11 @@ func (s *ScenarioService) updateStory(ctx context.Context, id int, story *storyt
|
||||
|
||||
cleanPlaces := make([]*storytelling.Place, 0, len(story.Places))
|
||||
for _, place := range story.Places {
|
||||
if place.Code == "" {
|
||||
code := s.cleaner.ClearCode(place.Code)
|
||||
if code == "" {
|
||||
continue
|
||||
}
|
||||
place.Code = code
|
||||
cleanPlaces = append(cleanPlaces, place)
|
||||
}
|
||||
story.Places = cleanPlaces
|
||||
|
||||
Reference in New Issue
Block a user