generated from VLADIMIR/template
fix names
This commit is contained in:
@@ -17,8 +17,8 @@ import (
|
||||
// scenariosRepository — граница доступа к данным сценариев, реализуемая
|
||||
// *scenarios_repo.ScenariosRepo (интерфейс — для тестов без БД).
|
||||
type scenariosRepository interface {
|
||||
AddScenario(ctx context.Context, name string, authorId int) (int, error)
|
||||
GetScenariosByAuthorID(ctx context.Context, authorId int) ([]*repos.Scenario, error)
|
||||
AddScenario(ctx context.Context, name string, authorID int) (int, error)
|
||||
GetScenariosByAuthorID(ctx context.Context, authorID int) ([]*repos.Scenario, error)
|
||||
GetScenariosByStatus(ctx context.Context, status string) ([]*repos.Scenario, error)
|
||||
GetScenarioByID(ctx context.Context, id int) (*repos.Scenario, error)
|
||||
UpdateScenarioByID(ctx context.Context, id int, name string, description string, image string) error
|
||||
@@ -55,9 +55,9 @@ func NewScenarioService(
|
||||
func (s *ScenarioService) AddScenario(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
authorId int,
|
||||
authorID int,
|
||||
) (int, error) {
|
||||
id, err := s.scenariosRepo.AddScenario(ctx, name, authorId)
|
||||
id, err := s.scenariosRepo.AddScenario(ctx, name, authorID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -66,9 +66,9 @@ func (s *ScenarioService) AddScenario(
|
||||
|
||||
func (s *ScenarioService) GetScenariosByAuthorID(
|
||||
ctx context.Context,
|
||||
authorId int,
|
||||
authorID int,
|
||||
) ([]*Scenario, error) {
|
||||
scenarios, err := s.scenariosRepo.GetScenariosByAuthorID(ctx, authorId)
|
||||
scenarios, err := s.scenariosRepo.GetScenariosByAuthorID(ctx, authorID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -113,10 +113,10 @@ func (s *ScenarioService) UpdateScenarioByID(
|
||||
name string,
|
||||
description string,
|
||||
image string,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.scenariosRepo.UpdateScenarioByID(ctx, id, name, description, image)
|
||||
@@ -137,7 +137,7 @@ var ErrScenarioNotOwner = errors.New("Сценарий принадлежит д
|
||||
func (s *ScenarioService) getScenarioForChange(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) (*repos.Scenario, error) {
|
||||
scenario, err := s.scenariosRepo.GetScenarioByID(ctx, id)
|
||||
@@ -150,7 +150,7 @@ func (s *ScenarioService) getScenarioForChange(
|
||||
if isAdmin {
|
||||
return scenario, nil
|
||||
}
|
||||
if scenario.Author == nil || scenario.Author.ID != actorId {
|
||||
if scenario.Author == nil || scenario.Author.ID != actorID {
|
||||
return nil, ErrScenarioNotOwner
|
||||
}
|
||||
return scenario, nil
|
||||
@@ -160,10 +160,10 @@ func (s *ScenarioService) UpdateScenarioStatusByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
status string,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
scenario, err := s.getScenarioForChange(ctx, id, actorId, isAdmin)
|
||||
scenario, err := s.getScenarioForChange(ctx, id, actorID, isAdmin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -190,10 +190,10 @@ func (s *ScenarioService) UpdateScenarioStatusByID(
|
||||
func (s *ScenarioService) DeleteScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
// Guard в SQL защищает от гонки «чтение статуса → запись»: не-админ не
|
||||
@@ -212,10 +212,10 @@ func (s *ScenarioService) AddScenarioPlace(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
place *storytelling.Place,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -234,10 +234,10 @@ func (s *ScenarioService) UpdateScenarioPlace(
|
||||
id int,
|
||||
code string,
|
||||
place *storytelling.Place,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -257,10 +257,10 @@ func (s *ScenarioService) DeleteScenarioPlace(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
code string,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -277,8 +277,8 @@ func (s *ScenarioService) DeleteScenarioPlace(
|
||||
}
|
||||
|
||||
// UpdateScenarioBackground устанавливает фон; пустое значение снимает его с дела.
|
||||
func (s *ScenarioService) UpdateScenarioBackground(ctx context.Context, id int, background string, actorId int, isAdmin bool) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
func (s *ScenarioService) UpdateScenarioBackground(ctx context.Context, id int, background string, actorID int, isAdmin bool) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
if background != "" && file_storage.FileType(background) != "image" {
|
||||
@@ -297,10 +297,10 @@ func (s *ScenarioService) UpdateScenarioIntro(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
introduction *storytelling.Introduction,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -311,8 +311,8 @@ func (s *ScenarioService) UpdateScenarioIntro(
|
||||
return s.updateStory(ctx, id, story)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) UpdateScenarioConclusion(ctx context.Context, id int, conclusion *storytelling.Conclusion, actorId int, isAdmin bool) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
func (s *ScenarioService) UpdateScenarioConclusion(ctx context.Context, id int, conclusion *storytelling.Conclusion, actorID int, isAdmin bool) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -328,10 +328,10 @@ func (s *ScenarioService) AddScenarioQuestion(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
question *storytelling.Question,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -349,10 +349,10 @@ func (s *ScenarioService) UpdateScenarioQuestion(
|
||||
id int,
|
||||
code string,
|
||||
question *storytelling.Question,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -373,10 +373,10 @@ func (s *ScenarioService) DeleteScenarioQuestion(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
code string,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) error {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorId, isAdmin); err != nil {
|
||||
if _, err := s.getScenarioForChange(ctx, id, actorID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
story, err := s.getStory(ctx, id)
|
||||
@@ -404,10 +404,10 @@ func (s *ScenarioService) getStory(ctx context.Context, id int) (*storytelling.S
|
||||
func (s *ScenarioService) DownloadArchive(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
actorId int,
|
||||
actorID int,
|
||||
isAdmin bool,
|
||||
) ([]byte, string, error) {
|
||||
scenario, err := s.getScenarioForChange(ctx, id, actorId, isAdmin)
|
||||
scenario, err := s.getScenarioForChange(ctx, id, actorID, isAdmin)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -435,7 +435,7 @@ func (s *ScenarioService) DownloadArchive(
|
||||
func (s *ScenarioService) UploadArchive(
|
||||
ctx context.Context,
|
||||
data []byte,
|
||||
authorId int,
|
||||
authorID int,
|
||||
) (int, error) {
|
||||
bundle, err := s.scenarioArchive.Unpack(data)
|
||||
if err != nil {
|
||||
@@ -522,7 +522,7 @@ func (s *ScenarioService) UploadArchive(
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := s.scenariosRepo.AddScenario(ctx, scenario.Name, authorId)
|
||||
id, err := s.scenariosRepo.AddScenario(ctx, scenario.Name, authorID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func newFakeScenariosRepo() *fakeScenariosRepo {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorId int) (int, error) {
|
||||
func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorID int) (int, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if r.addErr != nil {
|
||||
@@ -177,18 +177,18 @@ func (r *fakeScenariosRepo) AddScenario(_ context.Context, name string, authorId
|
||||
ID: r.nextID,
|
||||
Name: name,
|
||||
Description: &description,
|
||||
Author: &repos.User{ID: authorId},
|
||||
Author: &repos.User{ID: authorID},
|
||||
Status: "draft",
|
||||
}
|
||||
return r.nextID, nil
|
||||
}
|
||||
|
||||
func (r *fakeScenariosRepo) GetScenariosByAuthorID(_ context.Context, authorId int) ([]*repos.Scenario, error) {
|
||||
func (r *fakeScenariosRepo) GetScenariosByAuthorID(_ context.Context, authorID int) ([]*repos.Scenario, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
var res []*repos.Scenario
|
||||
for _, s := range r.byID {
|
||||
if s.Author != nil && s.Author.ID == authorId {
|
||||
if s.Author != nil && s.Author.ID == authorID {
|
||||
res = append(res, s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user