41 lines
987 B
C#
41 lines
987 B
C#
using AutoMapper;
|
|
using Diary.Component.Entries.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Diary.Component.Entries.Service
|
|
{
|
|
|
|
|
|
public interface IEntryService
|
|
{
|
|
Task<EntryResource> CreateAsync(CreateEntryResource createEntryResource);
|
|
}
|
|
public class EntryService : IEntryService
|
|
{
|
|
private readonly IEntryRepository _entryRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public EntryService(IEntryRepository entryRepository, IMapper mapper)
|
|
{
|
|
_entryRepository = entryRepository ?? throw new ArgumentNullException(nameof(entryRepository));
|
|
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
|
}
|
|
|
|
|
|
public async Task<EntryResource> CreateAsync(CreateEntryResource createEntryResource)
|
|
{
|
|
Entry entry = _mapper.Map<Entry>(createEntryResource);
|
|
|
|
await _entryRepository.CreateAsync(entry);
|
|
|
|
return _mapper.Map<EntryResource>(entry);
|
|
|
|
}
|
|
|
|
}
|
|
}
|