Changeset b373fea for ChapterX.Application/Chapter/Commands
- Timestamp:
- 06/23/26 15:20:39 (13 days ago)
- Branches:
- main
- Children:
- 0b502c2
- Parents:
- d300631
- Location:
- ChapterX.Application/Chapter/Commands
- Files:
-
- 5 edited
-
AddRequest.cs (modified) (1 diff)
-
DeleteHandler.cs (modified) (1 diff)
-
DeleteRequest.cs (modified) (1 diff)
-
UpdateHandler.cs (modified) (1 diff)
-
UpdateRequest.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ChapterX.Application/Chapter/Commands/AddRequest.cs
rd300631 rb373fea 1 1 using MediatR; 2 using System.ComponentModel.DataAnnotations; 2 3 3 4 namespace ChapterX.Application.Chapter.Commands 4 5 { 5 6 public record AddRequest( 6 int Number,7 string Name,8 string Title,9 string Content,7 [Range(1, int.MaxValue)] int Number, 8 [Required][MaxLength(200)] string Name, 9 [Required][MaxLength(300)] string Title, 10 [Required] string Content, 10 11 int StoryId 11 12 ) : IRequest<AddResponse>; -
ChapterX.Application/Chapter/Commands/DeleteHandler.cs
rd300631 rb373fea 18 18 public async Task<DeleteResponse> Handle(DeleteRequest request, CancellationToken cancellationToken) 19 19 { 20 var chapter = await _chapterRepository.GetById Async(request.Id, cancellationToken);20 var chapter = await _chapterRepository.GetByIdWithStoryAsync(request.Id, cancellationToken); 21 21 if (chapter is null) 22 22 return new DeleteResponse(false); 23 24 if (chapter.Story.UserId != request.CallerId) 25 throw new UnauthorizedAccessException("You do not own this chapter."); 23 26 24 27 await _chapterRepository.DeleteAsync(chapter, cancellationToken); -
ChapterX.Application/Chapter/Commands/DeleteRequest.cs
rd300631 rb373fea 3 3 namespace ChapterX.Application.Chapter.Commands 4 4 { 5 public record DeleteRequest(int Id ) : IRequest<DeleteResponse>;5 public record DeleteRequest(int Id, int CallerId) : IRequest<DeleteResponse>; 6 6 } -
ChapterX.Application/Chapter/Commands/UpdateHandler.cs
rd300631 rb373fea 18 18 public async Task<UpdateResponse> Handle(UpdateRequest request, CancellationToken cancellationToken) 19 19 { 20 var chapter = await _chapterRepository.GetById Async(request.Id, cancellationToken);20 var chapter = await _chapterRepository.GetByIdWithStoryAsync(request.Id, cancellationToken); 21 21 if (chapter is null) 22 22 return new UpdateResponse(false); 23 24 if (chapter.Story.UserId != request.CallerId) 25 throw new UnauthorizedAccessException("You do not own this chapter."); 23 26 24 27 chapter.Number = request.Number; -
ChapterX.Application/Chapter/Commands/UpdateRequest.cs
rd300631 rb373fea 9 9 string Title, 10 10 string Content, 11 int? WordCount 11 int? WordCount, 12 int CallerId = 0 12 13 ) : IRequest<UpdateResponse>; 13 14 }
Note:
See TracChangeset
for help on using the changeset viewer.
