generated from VLADIMIR/template
add file prefix
This commit is contained in:
@@ -6,10 +6,13 @@ import (
|
||||
"evening_detective_server/internal/repos"
|
||||
)
|
||||
|
||||
func mapScenarios(o []*repos.Scenario) ([]*Scenario, error) {
|
||||
func mapScenarios(
|
||||
o []*repos.Scenario,
|
||||
domain string,
|
||||
) ([]*Scenario, error) {
|
||||
res := make([]*Scenario, 0, len(o))
|
||||
for _, item := range o {
|
||||
scenario, err := mapScenario(item)
|
||||
scenario, err := mapScenario(item, domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -18,7 +21,10 @@ func mapScenarios(o []*repos.Scenario) ([]*Scenario, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func mapScenario(o *repos.Scenario) (*Scenario, error) {
|
||||
func mapScenario(
|
||||
o *repos.Scenario,
|
||||
domain string,
|
||||
) (*Scenario, error) {
|
||||
story, err := mapStory(o.Scenario)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -27,7 +33,7 @@ func mapScenario(o *repos.Scenario) (*Scenario, error) {
|
||||
ID: o.ID,
|
||||
Name: o.Name,
|
||||
Description: o.Description,
|
||||
Image: o.Image,
|
||||
Image: mapImage(o.Image, domain),
|
||||
Story: story,
|
||||
Author: o.Author,
|
||||
Status: o.Status,
|
||||
@@ -53,3 +59,12 @@ func convertStory(o *storytelling.Story) (string, error) {
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
func mapImage(image *string, domain string) *string {
|
||||
if image == nil {
|
||||
u := domain + "question.png"
|
||||
return &u
|
||||
}
|
||||
u := domain + *image
|
||||
return &u
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ import (
|
||||
|
||||
type ScenarioService struct {
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo
|
||||
domain string
|
||||
}
|
||||
|
||||
func NewScenarioService(
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo,
|
||||
domain string,
|
||||
) *ScenarioService {
|
||||
return &ScenarioService{
|
||||
scenariosRepo: scenariosRepo,
|
||||
domain: domain,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +42,7 @@ func (s *ScenarioService) GetScenariosByAuthorID(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapScenarios(scenarios)
|
||||
return mapScenarios(scenarios, s.domain)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) GetScenarioByID(
|
||||
@@ -50,7 +53,7 @@ func (s *ScenarioService) GetScenarioByID(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapScenario(scenario)
|
||||
return mapScenario(scenario, s.domain)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) UpdateScenarioByID(
|
||||
|
||||
Reference in New Issue
Block a user