update stories

This commit is contained in:
2026-07-24 17:40:47 +07:00
parent 37372cdd86
commit abdba686e7
3 changed files with 30 additions and 10 deletions
Binary file not shown.
@@ -6,6 +6,17 @@ import (
"evening_detective_server/internal/repos" "evening_detective_server/internal/repos"
) )
func mapScenariosLight(
o []*repos.Scenario,
domain string,
) []*Scenario {
res := make([]*Scenario, 0, len(o))
for _, item := range o {
res = append(res, mapScenarioLight(item, domain))
}
return res
}
func mapScenarios( func mapScenarios(
o []*repos.Scenario, o []*repos.Scenario,
domain string, domain string,
@@ -21,27 +32,36 @@ func mapScenarios(
return res, nil return res, nil
} }
func mapScenario( func mapScenarioLight(
o *repos.Scenario, o *repos.Scenario,
domain string, domain string,
) (*Scenario, error) { ) *Scenario {
story, err := mapStory(o.Scenario, domain)
if err != nil {
return nil, err
}
return &Scenario{ return &Scenario{
ID: o.ID, ID: o.ID,
Name: o.Name, Name: o.Name,
Description: o.Description, Description: o.Description,
Image: mapImage(o.Image, domain), Image: mapImage(o.Image, domain),
Story: story, Story: nil,
Author: o.Author, Author: o.Author,
Status: o.Status, Status: o.Status,
UpdatedAt: o.UpdatedAt, UpdatedAt: o.UpdatedAt,
CreatedAt: o.CreatedAt, CreatedAt: o.CreatedAt,
PublishedAt: o.PublishedAt, PublishedAt: o.PublishedAt,
IsDeleted: o.IsDeleted, IsDeleted: o.IsDeleted,
}, nil }
}
func mapScenario(
o *repos.Scenario,
domain string,
) (*Scenario, error) {
scenario := mapScenarioLight(o, domain)
story, err := mapStory(o.Scenario, domain)
if err != nil {
return nil, err
}
scenario.Story = story
return scenario, nil
} }
func mapStory(o string, domain string) (*storytelling.Story, error) { func mapStory(o string, domain string) (*storytelling.Story, error) {
@@ -66,7 +86,7 @@ func convertStory(o *storytelling.Story) (string, error) {
} }
func mapImage(image *string, domain string) *string { func mapImage(image *string, domain string) *string {
if image == nil { if image == nil || *image == "" {
u := domain + "question.png" u := domain + "question.png"
return &u return &u
} }
@@ -43,7 +43,7 @@ func (s *ScenarioService) GetScenariosByAuthorID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return mapScenarios(scenarios, s.domain) return mapScenariosLight(scenarios, s.domain), nil
} }
func (s *ScenarioService) GetScenarioByID( func (s *ScenarioService) GetScenarioByID(