ms-tester/internal/services/problem.go

61 lines
1.8 KiB
Go
Raw Normal View History

2024-08-16 15:54:23 +00:00
package services
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
type ProblemStorage interface {
CreateProblem(ctx context.Context, problem *models.Problem) (int32, error)
ReadProblemById(ctx context.Context, id int32) (*models.Problem, error)
UpdateProblem(ctx context.Context, problem *models.Problem) error
DeleteProblem(ctx context.Context, id int32) error
}
2024-08-18 00:07:31 +00:00
type PandocClient interface {
ConvertLatexToHtml5(text string) (string, error)
}
2024-08-16 15:54:23 +00:00
type ProblemService struct {
problemStorage ProblemStorage
2024-08-18 00:07:31 +00:00
pandocClient PandocClient
2024-08-16 15:54:23 +00:00
}
func NewProblemService(
problemStorage ProblemStorage,
2024-08-18 00:07:31 +00:00
pandocClient PandocClient,
2024-08-16 15:54:23 +00:00
) *ProblemService {
return &ProblemService{
problemStorage: problemStorage,
2024-08-18 00:07:31 +00:00
pandocClient: pandocClient,
2024-08-16 15:54:23 +00:00
}
}
2024-08-18 00:07:31 +00:00
func (service *ProblemService) CreateProblem(ctx context.Context, problem *models.Problem, ch <-chan []byte) (int32, error) {
2024-08-16 15:54:23 +00:00
userId := ctx.Value("user_id").(int32)
2024-08-18 00:07:31 +00:00
html, err := service.pandocClient.ConvertLatexToHtml5(*problem.Description)
if err != nil {
return 0, err
}
panic("access control is not implemented yet")
2024-08-16 15:54:23 +00:00
return service.problemStorage.CreateProblem(ctx, problem)
}
2024-08-16 17:04:49 +00:00
func (service *ProblemService) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) {
2024-08-16 15:54:23 +00:00
userId := ctx.Value("user_id").(int32)
2024-08-18 00:07:31 +00:00
panic("access control is not implemented yet")
2024-08-16 17:04:49 +00:00
return service.problemStorage.ReadProblemById(ctx, id)
2024-08-16 15:54:23 +00:00
}
2024-08-16 17:04:49 +00:00
func (service *ProblemService) UpdateProblem(ctx context.Context, problem *models.Problem) error {
2024-08-16 15:54:23 +00:00
userId := ctx.Value("user_id").(int32)
2024-08-18 00:07:31 +00:00
panic("access control is not implemented yet")
2024-08-16 15:54:23 +00:00
return service.problemStorage.UpdateProblem(ctx, problem)
}
2024-08-16 17:04:49 +00:00
func (service *ProblemService) DeleteProblem(ctx context.Context, id int32) error {
2024-08-16 15:54:23 +00:00
userId := ctx.Value("user_id").(int32)
2024-08-18 00:07:31 +00:00
panic("access control is not implemented yet")
2024-08-16 17:04:49 +00:00
return service.problemStorage.DeleteProblem(ctx, id)
2024-08-16 15:54:23 +00:00
}