Skip to content

Commit

Permalink
Merge pull request #1 from VulderApp/feature/get-branches-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
MRmlik12 authored Nov 28, 2021
2 parents 157a6a6 + d1cfc7f commit d5d1368
Show file tree
Hide file tree
Showing 32 changed files with 543 additions and 115 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the docker-compose stack
run: docker-compose -f docker-compose.test.yml up -d
- name: Check running containers
run: docker ps -a
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Install dependencies
run: dotnet restore
- name: Test project
run: dotnet test --verbosity normal
21 changes: 21 additions & 0 deletions Vulder.Timetable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulder.Timetable.Integratio
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulder.Timetable.UnitTests", "test\Vulder.Timetable.UnitTests\Vulder.Timetable.UnitTests.csproj", "{AB1C6DF9-3154-448E-8CCD-E35E020B30CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulder.Timetable.Core", "src\Vulder.Timetable.Core\Vulder.Timetable.Core.csproj", "{2D4CCB16-8203-499B-8145-8783B3C585BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulder.Timetable.Application", "src\Vulder.Timetable.Application\Vulder.Timetable.Application.csproj", "{935E6C57-E770-45D9-AE97-1A4ECE888A16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vulder.Timetable.Infrastructure", "src\Vulder.Timetable.Infrastructure\Vulder.Timetable.Infrastructure.csproj", "{993B38C8-83A5-4064-A62B-34ACEEFB141D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,10 +40,25 @@ Global
{AB1C6DF9-3154-448E-8CCD-E35E020B30CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB1C6DF9-3154-448E-8CCD-E35E020B30CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB1C6DF9-3154-448E-8CCD-E35E020B30CA}.Release|Any CPU.Build.0 = Release|Any CPU
{2D4CCB16-8203-499B-8145-8783B3C585BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D4CCB16-8203-499B-8145-8783B3C585BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D4CCB16-8203-499B-8145-8783B3C585BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D4CCB16-8203-499B-8145-8783B3C585BA}.Release|Any CPU.Build.0 = Release|Any CPU
{935E6C57-E770-45D9-AE97-1A4ECE888A16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{935E6C57-E770-45D9-AE97-1A4ECE888A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{935E6C57-E770-45D9-AE97-1A4ECE888A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{935E6C57-E770-45D9-AE97-1A4ECE888A16}.Release|Any CPU.Build.0 = Release|Any CPU
{993B38C8-83A5-4064-A62B-34ACEEFB141D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{993B38C8-83A5-4064-A62B-34ACEEFB141D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{993B38C8-83A5-4064-A62B-34ACEEFB141D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{993B38C8-83A5-4064-A62B-34ACEEFB141D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{95EDD9AD-F0A3-46A7-A3D9-B80D74096C9A} = {DEF9E0BB-3ABD-4956-82F4-D7BCB69EEC08}
{3ED84A63-FF78-4D52-8E18-CC67AFB7D1C6} = {CDBDB6C3-3849-44C7-ACB8-AFF9F7ADB69E}
{AB1C6DF9-3154-448E-8CCD-E35E020B30CA} = {CDBDB6C3-3849-44C7-ACB8-AFF9F7ADB69E}
{2D4CCB16-8203-499B-8145-8783B3C585BA} = {DEF9E0BB-3ABD-4956-82F4-D7BCB69EEC08}
{935E6C57-E770-45D9-AE97-1A4ECE888A16} = {DEF9E0BB-3ABD-4956-82F4-D7BCB69EEC08}
{993B38C8-83A5-4064-A62B-34ACEEFB141D} = {DEF9E0BB-3ABD-4956-82F4-D7BCB69EEC08}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.9'
services:
redis:
image: redis:6.2.6-alpine
restart: always
ports:
- 6379:6379
redis-web:
image: rediscommander/redis-commander:latest
restart: always
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- 9080:8081
7 changes: 7 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.9'
services:
redis:
image: redis:6.2.6-alpine
restart: always
ports:
- 6379:6379
3 changes: 3 additions & 0 deletions src/Vulder.Timetable.Api/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Vulder.Timetable.IntegrationTests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Vulder.Timetable.Core.Models;

namespace Vulder.Timetable.Api.Controllers.Branch;

[ApiController]
[Route("branch/[controller]")]
public class GetBranchesController : ControllerBase
{
private readonly IMediator _mediator;

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

[HttpGet]
public async Task<IActionResult> GetBranches([FromQuery] Guid schoolId)
{
var schoolBranch = await _mediator.Send(new GetBranchesRequestModel
{
SchoolId = schoolId
});

return Ok(schoolBranch);
}
}
32 changes: 0 additions & 32 deletions src/Vulder.Timetable.Api/Controllers/WeatherForecastController.cs

This file was deleted.

19 changes: 15 additions & 4 deletions src/Vulder.Timetable.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
var builder = WebApplication.CreateBuilder(args);
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Vulder.Timetable.Application;
using Vulder.Timetable.Infrastructure;

// Add services to the container.
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory(containerBuild =>
{
containerBuild.RegisterModule(new InfrastructureModule());
containerBuild.RegisterModule(new ApplicationModule());
}));

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand All @@ -23,3 +30,7 @@
app.MapControllers();

app.Run();

public partial class Program
{
}
2 changes: 2 additions & 0 deletions src/Vulder.Timetable.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7163;http://localhost:5284",
"environmentVariables": {
"REDIS_CONNECTION_STRING": "localhost",
"BASE_API_URL": "http://localhost:5211",
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
Expand Down
26 changes: 17 additions & 9 deletions src/Vulder.Timetable.Api/Vulder.Timetable.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0"/>
<PackageReference Include="MediatR" Version="9.0.0"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vulder.Timetable.Application\Vulder.Timetable.Application.csproj"/>
<ProjectReference Include="..\Vulder.Timetable.Core\Vulder.Timetable.Core.csproj"/>
<ProjectReference Include="..\Vulder.Timetable.Infrastructure\Vulder.Timetable.Infrastructure.csproj"/>
</ItemGroup>

</Project>
12 changes: 0 additions & 12 deletions src/Vulder.Timetable.Api/WeatherForecast.cs

This file was deleted.

44 changes: 44 additions & 0 deletions src/Vulder.Timetable.Application/ApplicationModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Reflection;
using Autofac;
using MediatR;
using MediatR.Pipeline;
using Vulder.Timetable.Application.Branch.GetBranches;
using Module = Autofac.Module;

namespace Vulder.Timetable.Application;

public class ApplicationModule : Module
{
private readonly List<Assembly?> _assemblies = new();

public ApplicationModule()
{
_assemblies.Add(Assembly.GetAssembly(typeof(GetBranchesRequestHandler)));
}

protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<Mediator>()
.As<IMediator>()
.InstancePerLifetimeScope();

builder.Register<ServiceFactory>(context =>
{
var c = context.Resolve<IComponentContext>();
return t => c.Resolve(t);
});

var mediatorOpenTypes = new[]
{
typeof(IRequestHandler<,>),
typeof(IRequestExceptionHandler<,,>),
typeof(IRequestExceptionHandler<,>),
typeof(INotificationHandler<>)
};

foreach (var mediatorOpenType in mediatorOpenTypes)
builder.RegisterAssemblyTypes(_assemblies.ToArray()!)
.AsClosedTypesOf(mediatorOpenType)
.AsImplementedInterfaces();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MediatR;
using Optivulcan;
using Vulder.Timetable.Core.Models;
using Vulder.Timetable.Infrastructure.Api;
using Vulder.Timetable.Infrastructure.Redis.Interfaces;

namespace Vulder.Timetable.Application.Branch.GetBranches;

public class GetBranchesRequestHandler : IRequestHandler<GetBranchesRequestModel, List<Optivulcan.Pocos.Branch>?>
{
private readonly IBranchRepository _branchRepository;

public GetBranchesRequestHandler(IBranchRepository branchRepository)
{
_branchRepository = branchRepository;
}

public async Task<List<Optivulcan.Pocos.Branch>?> Handle(GetBranchesRequestModel request,
CancellationToken cancellationToken)
{
var branchesFromCache = await _branchRepository.GetBranchById(request.SchoolId);
if (branchesFromCache != null) return branchesFromCache;

var schoolModel = await SchoolApi.GetSchoolModel(request.SchoolId);
var newSchoolBranches = await Api.GetBranchListAsync(schoolModel.TimetableUrl);
await _branchRepository.Create(request.SchoolId, newSchoolBranches);

return newSchoolBranches;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0"/>
<PackageReference Include="MediatR" Version="9.0.0"/>
<PackageReference Include="Optivulcan" Version="0.1.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vulder.Timetable.Core\Vulder.Timetable.Core.csproj"/>
<ProjectReference Include="..\Vulder.Timetable.Infrastructure\Vulder.Timetable.Infrastructure.csproj"/>
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Vulder.Timetable.Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Vulder.Timetable.Core;

public static class Constants
{
public static readonly string BaseApiUrl = Environment.GetEnvironmentVariable("BASE_API_URL") ?? string.Empty;

public static readonly string RedisConnectionString =
Environment.GetEnvironmentVariable("REDIS_CONNECTION_STRING") ?? string.Empty;
}
9 changes: 9 additions & 0 deletions src/Vulder.Timetable.Core/Models/GetBranchesRequestModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;
using Optivulcan.Pocos;

namespace Vulder.Timetable.Core.Models;

public class GetBranchesRequestModel : IRequest<List<Branch>?>
{
public Guid SchoolId { get; set; }
}
14 changes: 14 additions & 0 deletions src/Vulder.Timetable.Core/Vulder.Timetable.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Optivulcan" Version="0.1.1"/>
<PackageReference Include="Vulder.SharedKernel" Version="0.1.6"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Vulder.Timetable.Infrastructure.Api.Models;

public class GetSchoolResponse
{
public Guid? Id { get; set; }
public string? Name { get; set; }
public string? TimetableUrl { get; set; }
public string? SchoolUrl { get; set; }
}
Loading

0 comments on commit d5d1368

Please sign in to comment.