package usecase import ( "context" "git.sch9.ru/new_gate/models" "git.sch9.ru/new_gate/ms-tester/internal/contests" "git.sch9.ru/new_gate/ms-tester/pkg/utils" ) type ContestService struct { contestStorage contests.ContestRepository permissionService IPermissionService } func NewContestService( contestStorage ContestStorage, permissionService IPermissionService, ) *ContestService { return &ContestService{ contestStorage: contestStorage, permissionService: permissionService, } } func (service *ContestService) CreateContest(ctx context.Context, contest *models.Contest) (int32, error) { if !service.permissionService.Allowed(ctx, extractUser(ctx), "create") { return 0, utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.contestStorage.CreateContest(ctx, contest) } func (service *ContestService) ReadContestById(ctx context.Context, id int32) (*models.Contest, error) { if !service.permissionService.Allowed(ctx, extractUser(ctx), "read") { return nil, utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.contestStorage.ReadContestById(ctx, id) } func (service *ContestService) UpdateContest(ctx context.Context, contest *models.Contest) error { if !service.permissionService.Allowed(ctx, extractUser(ctx), "update") { return utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.contestStorage.UpdateContest(ctx, contest) } func (service *ContestService) DeleteContest(ctx context.Context, id int32) error { if !service.permissionService.Allowed(ctx, extractUser(ctx), "delete") { return utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.contestStorage.DeleteContest(ctx, id) }