source: ChapterX.Application/Story/Commands/UpdateHandler.cs@ e882b92

main
Last change on this file since e882b92 was e882b92, checked in by kikisrbinoska <srbinoskakristina07@…>, 13 days ago

Added corrected entitef from the ER diagram and changes for the logic to be coresponding to the ddl

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[877c13c]1using ChapterX.Domain.Repositories;
2using MediatR;
3using Microsoft.Extensions.Logging;
4
5namespace ChapterX.Application.Story.Commands
6{
7 public class UpdateHandler : IRequestHandler<UpdateRequest, UpdateResponse>
8 {
9 private readonly IStoryRepository _storyRepository;
10 private readonly ILogger<UpdateHandler> _logger;
11
12 public UpdateHandler(IStoryRepository storyRepository, ILogger<UpdateHandler> logger)
13 {
14 _storyRepository = storyRepository;
15 _logger = logger;
16 }
17
18 public async Task<UpdateResponse> Handle(UpdateRequest request, CancellationToken cancellationToken)
19 {
20 var story = await _storyRepository.GetByIdAsync(request.Id, cancellationToken);
21 if (story is null)
22 return new UpdateResponse(false);
23
[b373fea]24 if (story.UserId != request.CallerId)
25 throw new UnauthorizedAccessException("You do not own this story.");
26
[877c13c]27 story.MatureContent = request.MatureContent;
[99c1e45]28 story.Title = request.Title;
[877c13c]29 story.ShortDescription = request.ShortDescription;
30 story.Image = request.Image;
31 story.Content = request.Content;
[e882b92]32 if (request.Status is not null)
33 story.Status = request.Status;
[877c13c]34 story.UpdatedAt = DateTime.UtcNow;
35
36 await _storyRepository.UpdateAsync(story, cancellationToken);
37
38 return new UpdateResponse(true);
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.