update problem service

This commit is contained in:
dragonmuffin 2024-08-16 20:54:23 +05:00
parent c14ed9dc3d
commit 3fed9d7c03
2 changed files with 50 additions and 30 deletions

View file

@ -0,0 +1,50 @@
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
}
type ProblemService struct {
problemStorage ProblemStorage
}
func NewProblemService(
problemStorage ProblemStorage,
) *ProblemService {
return &ProblemService{
problemStorage: problemStorage,
}
}
func (service *ProblemService) CreateProblem(ctx context.Context, problem *models.Problem) (int32, error) {
userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet")
return service.problemStorage.CreateProblem(ctx, problem)
}
func 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)
}
func 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 {
userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet")
return service.problemStorage.DeleteProblem(ctx, problem)
}

View file

@ -1,30 +0,0 @@
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)
ReadProblem(ctx context.Context, id int32) (*models.Problem, error)
UpdateProblem(ctx context.Context, problem *models.Problem) error
DeleteProblem(ctx context.Context, id int32) error
}
type ProblemService struct {
problemStorage ProblemStorage
}
func NewProblemService(
problemStorage ProblemStorage,
) *ProblemService {
return &ProblemService{
problemStorage: problemStorage,
}
}
func (service *ProblemService) CreateProblem(ctx context.Context, problem *models.Problem) (int32, error) {
userId := ctx.Value("user_id").(int32)
return service.problemStorage.CreateProblem(ctx, problem)
}