generated from VLADIMIR/template
clear
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"evening_detective/internal/modules/cleaner"
|
||||
"evening_detective/internal/modules/formatter"
|
||||
"evening_detective/internal/services/story_service/models"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
type StoryService struct {
|
||||
cleaner cleaner.ICleaner
|
||||
formatter formatter.IFormatter
|
||||
story *Story
|
||||
story *models.Story
|
||||
storyStorage IStoryStorage
|
||||
}
|
||||
|
||||
@@ -45,44 +46,44 @@ func (s *StoryService) Update(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StoryService) GetPlace(code string) *Place {
|
||||
func (s *StoryService) GetPlace(code string) *models.Place {
|
||||
if strings.HasPrefix(code, "[") || strings.HasSuffix(code, "]") {
|
||||
return NewClientErrorPlace(code)
|
||||
return models.NewClientErrorPlace(code)
|
||||
}
|
||||
clearCode := s.cleaner.ClearCode(code)
|
||||
for _, place := range s.story.Places {
|
||||
if s.cleaner.ClearCode(place.Code) == clearCode {
|
||||
applications := make([]*Application, 0, len(place.Applications))
|
||||
applications := make([]*models.Application, 0, len(place.Applications))
|
||||
for _, application := range place.Applications {
|
||||
name := s.cleaner.ClearText(application.Name)
|
||||
applications = append(
|
||||
applications,
|
||||
&Application{
|
||||
&models.Application{
|
||||
Name: name,
|
||||
},
|
||||
)
|
||||
}
|
||||
return NewPlace(
|
||||
return models.NewPlace(
|
||||
place.Code,
|
||||
place.Name,
|
||||
s.cleaner.ClearText(place.Text),
|
||||
WithPlaceApplication(applications...),
|
||||
WithPlaceHidden(place.Hidden),
|
||||
WithPlaceDoors(place.Doors...),
|
||||
models.WithPlaceApplication(applications...),
|
||||
models.WithPlaceHidden(place.Hidden),
|
||||
models.WithPlaceDoors(place.Doors...),
|
||||
)
|
||||
}
|
||||
}
|
||||
return NewNotFoundPlace(code)
|
||||
return models.NewNotFoundPlace(code)
|
||||
}
|
||||
|
||||
func (s *StoryService) GetPlaces(codes []string) []*Place {
|
||||
places := make([]*Place, 0, 100)
|
||||
func (s *StoryService) GetPlaces(codes []string) []*models.Place {
|
||||
places := make([]*models.Place, 0, 100)
|
||||
m := map[string]any{}
|
||||
for _, code := range codes {
|
||||
place := s.GetPlace(code)
|
||||
_, ok := m[place.Code]
|
||||
if place.Hidden && !ok {
|
||||
place = NewNotFoundPlace(place.Code)
|
||||
place = models.NewNotFoundPlace(place.Code)
|
||||
}
|
||||
places = append(places, place)
|
||||
for _, door := range place.Doors {
|
||||
@@ -118,11 +119,11 @@ func (s *StoryService) deletePlace(ctx context.Context, code string) error {
|
||||
func (s *StoryService) addPlace(ctx context.Context, node *GraphNode) error {
|
||||
s.story.Places = append(
|
||||
s.story.Places,
|
||||
NewPlace(
|
||||
models.NewPlace(
|
||||
node.Code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
models.WithPlaceApplication(s.getApplications(node)...),
|
||||
),
|
||||
)
|
||||
return s.Update(ctx)
|
||||
@@ -131,22 +132,22 @@ func (s *StoryService) addPlace(ctx context.Context, node *GraphNode) error {
|
||||
func (s *StoryService) updatePlace(ctx context.Context, code string, node *GraphNode) error {
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == code {
|
||||
s.story.Places[i] = NewPlace(
|
||||
s.story.Places[i] = models.NewPlace(
|
||||
node.Code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
models.WithPlaceApplication(s.getApplications(node)...),
|
||||
)
|
||||
return s.Update(ctx)
|
||||
}
|
||||
}
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == node.Code {
|
||||
s.story.Places[i] = NewPlace(
|
||||
s.story.Places[i] = models.NewPlace(
|
||||
code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
models.WithPlaceApplication(s.getApplications(node)...),
|
||||
)
|
||||
break
|
||||
}
|
||||
@@ -154,12 +155,12 @@ func (s *StoryService) updatePlace(ctx context.Context, code string, node *Graph
|
||||
return s.Update(ctx)
|
||||
}
|
||||
|
||||
func (s *StoryService) getApplications(node *GraphNode) []*Application {
|
||||
nodeApplications := make([]*Application, 0, len(node.Applications))
|
||||
func (s *StoryService) getApplications(node *GraphNode) []*models.Application {
|
||||
nodeApplications := make([]*models.Application, 0, len(node.Applications))
|
||||
for _, application := range node.Applications {
|
||||
nodeApplications = append(
|
||||
nodeApplications,
|
||||
&Application{
|
||||
&models.Application{
|
||||
Name: application.Name,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user