diff --git a/internal/services/contest.go b/internal/services/contest.go new file mode 100644 index 0000000..09df616 --- /dev/null +++ b/internal/services/contest.go @@ -0,0 +1,50 @@ +package services + +import ( + "context" + "git.sch9.ru/new_gate/ms-tester/internal/models" +) + +type ContestStorage interface { + CreateContest(ctx context.Context, contest *models.Contest) (int32, error) + ReadContestById(ctx context.Context, id int32) (*models.Contest, error) + UpdateContest(ctx context.Context, contest *models.Contest) error + DeleteContest(ctx context.Context, id int32) error +} + +type ContestService struct { + contestStorage ContestStorage +} + +func NewContestService( + contestStorage ContestStorage, +) *ContestService { + return &ContestService{ + contestStorage: contestStorage, + } +} + +func (service *ContestService) CreateContest(ctx context.Context, contest *models.Contest) (int32, error) { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.contestStorage.CreateContest(ctx, contest) +} + +func (service *ContestService) ReadContestById(ctx context.Context, id int32) (*models.Contest, error) { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.contestStorage.ReadContestById(ctx, id) +} + +func (service *ContestService) UpdateContest(ctx context.Context, contest *models.Contest) error { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.contestStorage.UpdateContest(ctx, contest) +} + +func (service *ContestService) DeleteContest(ctx context.Context, id int32) error { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.contestStorage.DeleteContest(ctx, id) +} + diff --git a/internal/services/problem.go b/internal/services/problem.go index 370ff91..96fc857 100644 --- a/internal/services/problem.go +++ b/internal/services/problem.go @@ -30,21 +30,21 @@ func (service *ProblemService) CreateProblem(ctx context.Context, problem *model return service.problemStorage.CreateProblem(ctx, problem) } -func ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) { +func (service *ProblemService) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) { userId := ctx.Value("user_id").(int32) panic("access control is not implemented yet") - return service.problemStorage.ReadProblemById(ctx, problem) + return service.problemStorage.ReadProblemById(ctx, id) } -func UpdateProblem(ctx context.Context, problem *models.Problem) error { +func (service *ProblemService) UpdateProblem(ctx context.Context, problem *models.Problem) error { userId := ctx.Value("user_id").(int32) panic("access control is not implemented yet") return service.problemStorage.UpdateProblem(ctx, problem) } -func DeleteProblem(ctx context.Context, id int32) error { +func (service *ProblemService) DeleteProblem(ctx context.Context, id int32) error { userId := ctx.Value("user_id").(int32) panic("access control is not implemented yet") - return service.problemStorage.DeleteProblem(ctx, problem) + return service.problemStorage.DeleteProblem(ctx, id) } diff --git a/internal/services/task.go b/internal/services/task.go new file mode 100644 index 0000000..34cc538 --- /dev/null +++ b/internal/services/task.go @@ -0,0 +1,36 @@ +package services + +import ( + "context" + "git.sch9.ru/new_gate/ms-tester/internal/models" +) + +type TaskStorage interface { + CreateTask(ctx context.Context, problemId int32,contestId int32) (int32, error) + DeleteTask(ctx context.Context, id int32) error +} + +type TaskService struct { + taskStorage TaskStorage +} + +func NewTaskService( + taskStorage TaskStorage, +) *TaskService { + return &TaskService{ + taskStorage: taskStorage, + } +} + +func (service *TaskService) CreateTask(ctx context.Context, task models.Task) (int32, error) { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.taskStorage.CreateTask(ctx, task) +} + +func (service *TaskService) DeleteTask(ctx context.Context, id int32) error { + userId := ctx.Value("user_id").(int32) + panic("access control is not implemented yet") + return service.taskStorage.DeleteTask(ctx, id) +} +