feat: add solutions service

This commit is contained in:
dragonmuffin 2024-08-17 15:43:15 +05:00
parent 0fda91d8d5
commit d9e2f46de8
6 changed files with 80 additions and 5 deletions

View file

@ -13,3 +13,7 @@ var (
var (
ErrBadRole = errors.New("bad role")
)
var (
ErrBadTestingStrategy = errors.New("bad testing strategy")
)

View file

@ -7,7 +7,6 @@ type Solution struct {
ParticipantId *int32 `db:"participant_id"`
ProblemId *int32 `db:"problem_id"`
LanguageId *int32 `db:"language_id"`
ContestId *int32 `db:"contest_id"`
SolutionHash *string `db:"solution_hash"`
Result *int32 `db:"result"`
CreatedAt *time.Time `db:"created_at"`

View file

@ -0,0 +1,24 @@
package models
import "time"
type TestingStrategy int32
const (
EachTestTS TestingStrategy = 1;
CompleteGroupTS TestingStrategy = 2;
)
type Testgroup struct {
Id *int32 `db:"id"`
ProblemId *int32 `db:"problem_id"`
TestingStrategy *int32 `db:"testing_strategy"`
}
func (TestingStrategy ts) Valid() error {
switch ts {
case EachTestTS, CompleteGroupTS:
return nil
}
return lib.ErrBadTestingStrategy
}

View 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)
}