main
|
Last change
on this file since b373fea was b373fea, checked in by kikisrbinoska <srbinoskakristina07@…>, 12 days ago |
|
Fixes for authentication and auhtorization\
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [877c13c] | 1 | using ChapterX.Domain.Repositories;
|
|---|
| 2 | using MediatR;
|
|---|
| 3 | using Microsoft.Extensions.Logging;
|
|---|
| 4 |
|
|---|
| 5 | namespace ChapterX.Application.Chapter.Commands
|
|---|
| 6 | {
|
|---|
| 7 | public class DeleteHandler : IRequestHandler<DeleteRequest, DeleteResponse>
|
|---|
| 8 | {
|
|---|
| 9 | private readonly IChapterRepository _chapterRepository;
|
|---|
| 10 | private readonly ILogger<DeleteHandler> _logger;
|
|---|
| 11 |
|
|---|
| 12 | public DeleteHandler(IChapterRepository chapterRepository, ILogger<DeleteHandler> logger)
|
|---|
| 13 | {
|
|---|
| 14 | _chapterRepository = chapterRepository;
|
|---|
| 15 | _logger = logger;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | public async Task<DeleteResponse> Handle(DeleteRequest request, CancellationToken cancellationToken)
|
|---|
| 19 | {
|
|---|
| [b373fea] | 20 | var chapter = await _chapterRepository.GetByIdWithStoryAsync(request.Id, cancellationToken);
|
|---|
| [877c13c] | 21 | if (chapter is null)
|
|---|
| 22 | return new DeleteResponse(false);
|
|---|
| 23 |
|
|---|
| [b373fea] | 24 | if (chapter.Story.UserId != request.CallerId)
|
|---|
| 25 | throw new UnauthorizedAccessException("You do not own this chapter.");
|
|---|
| 26 |
|
|---|
| [877c13c] | 27 | await _chapterRepository.DeleteAsync(chapter, cancellationToken);
|
|---|
| 28 |
|
|---|
| 29 | return new DeleteResponse(true);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.