feat: add solutions service
This commit is contained in:
parent
0fda91d8d5
commit
d9e2f46de8
6 changed files with 80 additions and 5 deletions
50
internal/services/solution.go
Normal file
50
internal/services/solution.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/models"
|
||||
)
|
||||
|
||||
type SolutionStorage interface {
|
||||
CreateSolution(ctx context.Context, models.Solution) (int32, error)
|
||||
ReadSolutionById(ctx context.Context, id int32) (models.Solution, error)
|
||||
RejudgeSolution(ctx context.Context, id int32) error
|
||||
DeleteSolution(ctx context.Context, id int32) error
|
||||
}
|
||||
|
||||
type SolutionService struct {
|
||||
solutionStorage SolutionStorage
|
||||
}
|
||||
|
||||
func NewSolutionService(
|
||||
solutionStorage SolutionStorage,
|
||||
) *SolutionService {
|
||||
return &SolutionService{
|
||||
solutionStorage: solutionStorage,
|
||||
}
|
||||
}
|
||||
|
||||
func (service *SolutionService) CreateSolution(ctx context.Context, solution models.Solution) (int32, error) {
|
||||
userId := ctx.Value("user_id").(int32)
|
||||
panic("access control is not implemented yet")
|
||||
return service.solutionStorage.CreateSolution(ctx, solution)
|
||||
}
|
||||
|
||||
func (service *SolutionService) ReadSolutionById(ctx context.Context, id int32) (models.Solution, error) {
|
||||
userId := ctx.Value("user_id").(int32)
|
||||
panic("access control is not implemented yet")
|
||||
return service.solutionStorage.ReadSolutionById(ctx, id)
|
||||
}
|
||||
|
||||
func (service *SolutionService) RejudgeSolution(ctx context.Context, id int32) error {
|
||||
userId := ctx.Value("user_id").(int32)
|
||||
panic("access control is not implemented yet")
|
||||
return service.solutionStorage.RejudgeSolution(ctx, id)
|
||||
}
|
||||
|
||||
func (service *SolutionService) DeleteSolution(ctx context.Context, id int32) error {
|
||||
userId := ctx.Value("user_id").(int32)
|
||||
panic("access control is not implemented yet")
|
||||
return service.solutionStorage.DeleteSolution(ctx, id)
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue