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"
)
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(
o []*repos.Scenario,
domain string,
@@ -21,27 +32,36 @@ func mapScenarios(
return res, nil
}
func mapScenario(
func mapScenarioLight(
o *repos.Scenario,
domain string,
) (*Scenario, error) {
story, err := mapStory(o.Scenario, domain)
if err != nil {
return nil, err
}
) *Scenario {
return &Scenario{
ID: o.ID,
Name: o.Name,
Description: o.Description,
Image: mapImage(o.Image, domain),
Story: story,
Story: nil,
Author: o.Author,
Status: o.Status,
UpdatedAt: o.UpdatedAt,
CreatedAt: o.CreatedAt,
PublishedAt: o.PublishedAt,
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) {
@@ -66,7 +86,7 @@ func convertStory(o *storytelling.Story) (string, error) {
}
func mapImage(image *string, domain string) *string {
if image == nil {
if image == nil || *image == "" {
u := domain + "question.png"
return &u
}
@@ -43,7 +43,7 @@ func (s *ScenarioService) GetScenariosByAuthorID(
if err != nil {
return nil, err
}
return mapScenarios(scenarios, s.domain)
return mapScenariosLight(scenarios, s.domain), nil
}
func (s *ScenarioService) GetScenarioByID(