Add entries controller

This commit is contained in:
2022-08-10 21:14:27 +01:00
parent 8978af10bc
commit 2ac5937096
4 changed files with 45 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Diary.Component.Entries.Service;
using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -11,9 +12,20 @@ namespace Diary.Component.Entries
[Route("[controller]")] [Route("[controller]")]
public class EntriesController:ControllerBase public class EntriesController:ControllerBase
{ {
public EntriesController() private readonly IEntryService _entryService;
{
public EntriesController(IEntryService entryService)
{
_entryService = entryService ?? throw new ArgumentNullException(nameof(entryService));
} }
[HttpPost]
public async Task<EntryResource> CreateEntryAsync(CreateEntryResource create)
{
return await _entryService.CreateAsync(create);
}
} }
} }

17
Data/UnitOfWork.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diary.Data
{
public class UnitOfWork
{
public UnitOfWork()
{
}
}
}

View File

@@ -1,4 +1,6 @@
using System; using Diary.Component.Entries.Repository;
using Diary.Component.Entries.Service;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -10,6 +12,11 @@ namespace Diary.Installers
{ {
public static IServiceCollection AddDependencies(this IServiceCollection services) public static IServiceCollection AddDependencies(this IServiceCollection services)
{ {
services.AddScoped<IEntryService, EntryService>();
services.AddScoped<IEntryRepository, EntryRepository>();
return services; return services;
} }

View File

@@ -44,6 +44,11 @@ try
builder.Services.AddDatabase(builder.Configuration); builder.Services.AddDatabase(builder.Configuration);
builder.Services.AddScoped<IDiaryDBContext, DiaryDBContext>(); builder.Services.AddScoped<IDiaryDBContext, DiaryDBContext>();
//---y
//Dependancies
builder.Services.AddDependencies();
//---Y //---Y
//Automapper //Automapper
builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly()); builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());