-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from VulderApp/feature/get-branches-controller
- Loading branch information
Showing
32 changed files
with
543 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Vulder.Timetable.IntegrationTests")] |
28 changes: 28 additions & 0 deletions
28
src/Vulder.Timetable.Api/Controllers/Branch/GetBranchesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/Vulder.Timetable.Api/Controllers/WeatherForecastController.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Vulder.Timetable.Application/Branch/GetBranches/GetBranchesRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Vulder.Timetable.Application/Vulder.Timetable.Application.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
9 changes: 9 additions & 0 deletions
9
src/Vulder.Timetable.Infrastructure/Api/Models/GetSchoolResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
Oops, something went wrong.