source: ChapterX.Application/Collaboration/Commands/AddHandler.cs

main
Last change on this file was 877c13c, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago

Added files

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[877c13c]1using ChapterX.Domain.Repositories;
2using MediatR;
3using Microsoft.Extensions.Logging;
4
5namespace ChapterX.Application.Collaboration.Commands
6{
7 public class AddHandler : IRequestHandler<AddRequest, AddResponse>
8 {
9 private readonly ICollaborationRepository _collaborationRepository;
10 private readonly ILogger<AddHandler> _logger;
11
12 public AddHandler(ICollaborationRepository collaborationRepository, ILogger<AddHandler> logger)
13 {
14 _collaborationRepository = collaborationRepository;
15 _logger = logger;
16 }
17
18 public async Task<AddResponse> Handle(AddRequest request, CancellationToken cancellationToken)
19 {
20 var collaboration = new Domain.Entities.Collaboration
21 {
22 UserId = request.UserId,
23 StoryId = request.StoryId,
24 CreatedAt = DateTime.UtcNow
25 };
26
27 await _collaborationRepository.AddAsync(collaboration, cancellationToken);
28
29 return new AddResponse(collaboration.Id);
30 }
31 }
32}
Note: See TracBrowser for help on using the repository browser.