Add Exception middleware

This commit is contained in:
2022-09-01 23:02:49 +01:00
parent 2ac5937096
commit dcf3b1020a
14 changed files with 241 additions and 90 deletions

View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diary.Component.Entries.Repository
{
@@ -15,15 +10,14 @@ namespace Diary.Component.Entries.Repository
public int EnrtyID { get; set; }
[Required]
[Column(TypeName="date")]
[Column(TypeName = "date")]
public DateTime Date { get; set; }
[Required]
public DateTime ValidFrom { get; set; }
public DateTime ValidFrom { get; set; } = DateTime.Now;
public DateTime? ValidTo { get; set; }
public string Note { get; set; }
public string Note { get; set; }
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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; }

View File

@@ -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);
}