main
|
Last change
on this file since acf690c was acf690c, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago |
|
Added fixes for the login,stories management and reading lists
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [877c13c] | 1 | using ChapterX.Domain.Repositories;
|
|---|
| 2 | using MediatR;
|
|---|
| 3 | using Microsoft.Extensions.Logging;
|
|---|
| 4 |
|
|---|
| 5 | namespace ChapterX.Application.ReadingListItems.Commands
|
|---|
| 6 | {
|
|---|
| 7 | public class AddHandler : IRequestHandler<AddRequest, AddResponse>
|
|---|
| 8 | {
|
|---|
| 9 | private readonly IReadingListItemsRepository _readingListItemsRepository;
|
|---|
| 10 | private readonly ILogger<AddHandler> _logger;
|
|---|
| 11 |
|
|---|
| 12 | public AddHandler(IReadingListItemsRepository readingListItemsRepository, ILogger<AddHandler> logger)
|
|---|
| 13 | {
|
|---|
| 14 | _readingListItemsRepository = readingListItemsRepository;
|
|---|
| 15 | _logger = logger;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | public async Task<AddResponse> Handle(AddRequest request, CancellationToken cancellationToken)
|
|---|
| 19 | {
|
|---|
| [acf690c] | 20 | var exists = await _readingListItemsRepository.ExistsAsync(request.ReadingListId, request.StoryId, cancellationToken);
|
|---|
| 21 | if (exists)
|
|---|
| 22 | throw new InvalidOperationException("Story is already in this reading list.");
|
|---|
| 23 |
|
|---|
| [877c13c] | 24 | var readingListItems = new Domain.Entities.ReadingListItems
|
|---|
| 25 | {
|
|---|
| 26 | ListId = request.ReadingListId,
|
|---|
| 27 | StoryId = request.StoryId,
|
|---|
| 28 | AddedAt = DateTime.UtcNow
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | await _readingListItemsRepository.AddAsync(readingListItems, cancellationToken);
|
|---|
| 32 |
|
|---|
| 33 | return new AddResponse(readingListItems.Id);
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.