Add Exception middleware
This commit is contained in:
@@ -8,7 +8,8 @@ namespace Diary.Component.Entries.Service
|
||||
public EntryMappings()
|
||||
{
|
||||
CreateMap<CreateEntryResource, Entry>();
|
||||
CreateMap<Entry, EntryResource>();
|
||||
CreateMap<Entry, EntryResource>()
|
||||
.ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.Date.Date));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
public class EntryResource
|
||||
{
|
||||
public int EnrtyID { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public DateTime ValidFrom { get; set; }
|
||||
public DateTime? ValidTo { get; set; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using Diary.Component.Entries.Repository;
|
||||
using Diary.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -18,11 +19,13 @@ namespace Diary.Component.Entries.Service
|
||||
{
|
||||
private readonly IEntryRepository _entryRepository;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public EntryService(IEntryRepository entryRepository, IMapper mapper)
|
||||
public EntryService(IEntryRepository entryRepository, IMapper mapper, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_entryRepository = entryRepository ?? throw new ArgumentNullException(nameof(entryRepository));
|
||||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +35,8 @@ namespace Diary.Component.Entries.Service
|
||||
|
||||
await _entryRepository.CreateAsync(entry);
|
||||
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
return _mapper.Map<EntryResource>(entry);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user