generated from VLADIMIR/template
add scenarios methods
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package scenarios_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"evening_detective_server/internal/repos/scenarios_repo"
|
||||
)
|
||||
|
||||
type ScenarioService struct {
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo
|
||||
}
|
||||
|
||||
func NewScenarioService(
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo,
|
||||
) *ScenarioService {
|
||||
return &ScenarioService{
|
||||
scenariosRepo: scenariosRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ScenarioService) AddScenario(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
authorId int,
|
||||
) (int, error) {
|
||||
id, err := s.scenariosRepo.AddScenario(ctx, name, authorId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (s *ScenarioService) GetScenariosByAuthorID(
|
||||
ctx context.Context,
|
||||
authorId int,
|
||||
) ([]*Scenario, error) {
|
||||
scenarios, err := s.scenariosRepo.GetScenariosByAuthorID(ctx, authorId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapScenarios(scenarios)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) GetScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
) (*Scenario, error) {
|
||||
scenario, err := s.scenariosRepo.GetScenarioByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapScenario(scenario)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) UpdateScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
name string,
|
||||
description string,
|
||||
image string,
|
||||
) error {
|
||||
return s.scenariosRepo.UpdateScenarioByID(ctx, id, name, description, image)
|
||||
}
|
||||
|
||||
func (s *ScenarioService) DeleteScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
) error {
|
||||
return s.scenariosRepo.DeleteScenarioByID(ctx, id)
|
||||
}
|
||||
Reference in New Issue
Block a user