Skip to content

Commit

Permalink
#26 REST API - BankAccountController
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinajemuovic committed Jun 18, 2022
1 parent c69d193 commit 1212889
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ Run Tests:
```
dotnet test Optivem.Kata.Banking.sln
```

## Migrations

```
dotnet ef migrations add InitialMigration --project .\src\Optivem.Kata.Banking.Web
```
33 changes: 33 additions & 0 deletions src/Optivem.Kata.Banking.Web/Controllers/BankAccountController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Optivem.Kata.Banking.Core.UseCases.OpenAccount;
using Optivem.Kata.Banking.Core.UseCases.ViewAccount;

namespace Optivem.Kata.Banking.Web.Controllers
{
[ApiController]
[Route("bank-accounts")]
public class BankAccountController : ControllerBase
{
private readonly IMediator _mediator;

public BankAccountController(IMediator mediator)
{
_mediator = mediator;
}

[HttpPost]
public async Task<ActionResult<OpenAccountResponse>> OpenAccount(OpenAccountRequest request)
{
// TODO: VC: Helpr base method which is async
var response = await _mediator.Send(request);
return CreatedAtAction(nameof(ViewAccount), new { accountNumber = response.AccountNumber }, response);
}

[HttpGet("{accountNumber}")]
public async Task<ActionResult<ViewAccountResponse>> ViewAccount(string accountNumber)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Register(this IServiceCollection services, ConfigurationManag

services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlServer(configuration.GetConnectionString("BankingDatabase"));
options.UseSqlServer(configuration.GetConnectionString("BankingDatabase"), b => b.MigrationsAssembly("Optivem.Kata.Banking.Infrastructure"));
});

services.AddMediatR(typeof(CoreModule));
Expand Down
4 changes: 4 additions & 0 deletions src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public BankAccountControllerSystemTest()
var application = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
// var configuration = builder.Ser

// builder.ConfigureServices(services => services.Register(builder.Conf))
// TODO: VC: Configure
});

Expand Down

0 comments on commit 1212889

Please sign in to comment.