package usecase import ( "context" "git.sch9.ru/new_gate/models" "git.sch9.ru/new_gate/ms-tester/pkg/utils" ) type TaskStorage interface { CreateTask(ctx context.Context, task models.Task) (int32, error) DeleteTask(ctx context.Context, id int32) error } type TaskService struct { taskStorage TaskStorage permissionService IPermissionService } func NewTaskService( taskStorage TaskStorage, permissionService IPermissionService, ) *TaskService { return &TaskService{ taskStorage: taskStorage, permissionService: permissionService, } } func (service *TaskService) CreateTask(ctx context.Context, task models.Task) (int32, error) { if !service.permissionService.Allowed(ctx, extractUser(ctx), "create") { return 0, utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.taskStorage.CreateTask(ctx, task) } func (service *TaskService) DeleteTask(ctx context.Context, id int32) error { if !service.permissionService.Allowed(ctx, extractUser(ctx), "delete") { return utils.ServiceError(nil, utils.ErrNoPermission, "permission denied") } return service.taskStorage.DeleteTask(ctx, id) }