-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c98b2c7
commit 6f0f6cc
Showing
12 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
GrpcTodo.Server/Domain/UseCases/Tasks/DeleteTaskUseCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using GrpcTodo.Server.Domain.Repositories; | ||
|
||
namespace GrpcTodo.Server.Domain.UseCases.Tasks; | ||
|
||
public sealed class DeleteTaskUseCase | ||
{ | ||
private readonly ITaskRepository _taskRepository; | ||
|
||
public DeleteTaskUseCase(ITaskRepository taskRepository) | ||
{ | ||
_taskRepository = taskRepository; | ||
} | ||
|
||
public async Task ExecuteAsync(Guid userId, DeleteTaskUseCaseInput request) | ||
{ | ||
var task = await _taskRepository.FindByShortIdAsync(request.Id); | ||
|
||
if (task is null) | ||
throw new NotFoundException("this task does not exists"); | ||
|
||
if (task.UserId != userId) | ||
throw new DeniedException("this task does not belongs to you"); | ||
|
||
await _taskRepository.DeleteAsync(task.Id); | ||
} | ||
} | ||
|
||
public sealed record DeleteTaskUseCaseInput(string Id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Grpc.Core; | ||
|
||
namespace GrpcTodo.SharedKernel.Exceptions; | ||
|
||
public sealed class DeniedException : RpcException | ||
{ | ||
public DeniedException(string message) : base(new Status( | ||
StatusCode.PermissionDenied, | ||
message | ||
), message) | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters