Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

refactor: extract controllers #447

Merged
merged 3 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Domain\Kysect.Shreks.Common\Kysect.Shreks.Common.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.Abstractions\Kysect.Shreks.Application.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Domain\Kysect.Shreks.Common\Kysect.Shreks.Common.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.Abstractions\Kysect.Shreks.Application.Abstractions.csproj" />
</ItemGroup>

</Project>
</Project>
1 change: 1 addition & 0 deletions Source/Kysect.Shreks.WebApi/Kysect.Shreks.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ProjectReference Include="..\Infrastructure\Kysect.Shreks.DataAccess\Kysect.Shreks.DataAccess.csproj" />
<ProjectReference Include="..\Infrastructure\Kysect.Shreks.Mapping\Kysect.Shreks.Mapping.csproj" />
<ProjectReference Include="..\Infrastructure\Kysect.Shreks.Seeding\Kysect.Shreks.Seeding.csproj" />
<ProjectReference Include="..\Presentation\Kysect.Shreks.Controllers\Kysect.Shreks.Controllers.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions Source/Kysect.Shreks.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Kysect.Shreks.Application.GithubWorkflow.Extensions;
using Kysect.Shreks.Application.Handlers.Extensions;
using Kysect.Shreks.Common.Exceptions;
using Kysect.Shreks.Controllers;
using Kysect.Shreks.Controllers.Models;
using Kysect.Shreks.Core.Study;
using Kysect.Shreks.Core.SubjectCourseAssociations;
using Kysect.Shreks.Core.Submissions;
Expand All @@ -21,7 +23,6 @@
using Kysect.Shreks.Seeding.Extensions;
using Kysect.Shreks.WebApi.Extensions;
using Kysect.Shreks.WebApi.Filters;
using Kysect.Shreks.WebApi.Models;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -46,7 +47,13 @@ void InitServiceCollection(WebApplicationBuilder webApplicationBuilder)
{
webApplicationBuilder.Services.TryAddSingleton(testEnvironmentConfiguration);
}
webApplicationBuilder.Services.AddControllers(x => x.Filters.Add<AuthenticationFilter>()).AddNewtonsoftJson();

webApplicationBuilder.Services
.AddControllers(x => x.Filters.Add<AuthenticationFilter>())
.AddNewtonsoftJson()
.AddApplicationPart(typeof(IControllersProjectMarker).Assembly)
.AddControllersAsServices();

webApplicationBuilder.Services.AddEndpointsApiExplorer();
webApplicationBuilder.Services.AddSwaggerGen(c =>
{
Expand Down
9 changes: 8 additions & 1 deletion Source/Kysect.Shreks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kysect.Shreks.Application.TableManagement", "Application\Kysect.Shreks.Application.TableManagement\Kysect.Shreks.Application.TableManagement.csproj", "{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kysect.Shreks.Application.TableManagement", "Application\Kysect.Shreks.Application.TableManagement\Kysect.Shreks.Application.TableManagement.csproj", "{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kysect.Shreks.Controllers", "Presentation\Kysect.Shreks.Controllers\Kysect.Shreks.Controllers.csproj", "{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -172,6 +174,10 @@ Global
{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Release|Any CPU.Build.0 = Release|Any CPU
{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -202,6 +208,7 @@ Global
{DF0C2310-8F92-404C-885E-D495B3F334EB} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5}
{3B0EB40E-6E3C-4F8D-BBD7-9B7FC5FB7D68} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5}
{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5}
{561BAC9C-4E54-414A-BFDA-AFF90B6F5ADF} = {7A93BF5E-D7A6-4D8A-AC22-9D5AF09C4880}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD5C67DB-70F8-4C47-A3F4-7C94BECE1657}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Kysect.Shreks.Application.Abstractions.Study.Commands;
using Kysect.Shreks.Application.Abstractions.Study.Queries;
using Kysect.Shreks.Application.Dto.Study;
using Kysect.Shreks.Controllers.Models;
using Kysect.Shreks.Identity.Entities;
using Kysect.Shreks.WebApi.Models;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("/api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Kysect.Shreks.Application.Dto.Identity;
using Kysect.Shreks.Common.Exceptions;
using Microsoft.AspNetCore.Http;

namespace Kysect.Shreks.WebApi.Extensions;
namespace Kysect.Shreks.Controllers.Extensions;

public static class HttpContextExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Security.Claims;
using Kysect.Shreks.Application.Abstractions.Users.Commands;
using Kysect.Shreks.Application.Abstractions.Users.Commands;
using Kysect.Shreks.Identity.Entities;
using MediatR;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[ApiController]
[Route("api/auth/github")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers
namespace Kysect.Shreks.Controllers
{
[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Kysect.Shreks.Application.TableManagement;
using Kysect.Shreks.Integration.Google;
using Kysect.Shreks.Application.Abstractions.Google;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers
namespace Kysect.Shreks.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GoogleController : ControllerBase
{
private readonly TableUpdateQueue _tableUpdate;
private readonly ITableUpdateQueue _tableUpdate;

public GoogleController(TableUpdateQueue tableUpdate)
public GoogleController(ITableUpdateQueue tableUpdate)
{
_tableUpdate = tableUpdate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers
namespace Kysect.Shreks.Controllers
{
[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Kysect.Shreks.Controllers;

public interface IControllersProjectMarker
{
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Kysect.Shreks.Application.Abstractions.Identity.Commands;
using Kysect.Shreks.Application.Abstractions.Identity.Queries;
using Kysect.Shreks.Controllers.Models;
using Kysect.Shreks.Identity.Entities;
using Kysect.Shreks.WebApi.Models;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[ApiController]
[Route("api/identity")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Net;
using Kysect.Shreks.Identity.Entities;
using Kysect.Shreks.Identity.Entities;
using Kysect.Shreks.Integration.Github.Helpers;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using static Kysect.Shreks.Application.Abstractions.Internal.SeedTestData;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[ApiController]
[Route("api/internal/")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Application\Kysect.Shreks.Application.Abstractions\Kysect.Shreks.Application.Abstractions.csproj" />
<ProjectReference Include="..\..\Application\Kysect.Shreks.Application.GithubWorkflow.Abstractions\Kysect.Shreks.Application.GithubWorkflow.Abstractions.csproj" />
<ProjectReference Include="..\..\Infrastructure\Kysect.Shreks.Identity\Kysect.Shreks.Identity.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Kysect.Shreks.WebApi.Models;
namespace Kysect.Shreks.Controllers.Models;

public class AdminModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Kysect.Shreks.WebApi.Models;
namespace Kysect.Shreks.Controllers.Models;

public record CreateAssignmentRequest(Guid SubjectCourseId, string Title, string ShortName, int Order, double MinPoints, double MaxPoints);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Kysect.Shreks.WebApi.Models;
namespace Kysect.Shreks.Controllers.Models;

public record LoginRequest(string Username, string Password);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Kysect.Shreks.WebApi.Models;
namespace Kysect.Shreks.Controllers.Models;

public record LoginResponse(string Token, DateTime Expires, IReadOnlyCollection<string> Roles);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Kysect.Shreks.WebApi.Models;
namespace Kysect.Shreks.Controllers.Models;

public record RegisterUserRequest(string Username, string Password);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[Route("api/[controller]")]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using Kysect.Shreks.Application.Abstractions.Users.Commands;
using Kysect.Shreks.Application.Abstractions.Users.Queries;
using Kysect.Shreks.Application.Dto.Users;
using Kysect.Shreks.Controllers.Extensions;
using Kysect.Shreks.Identity.Entities;
using Kysect.Shreks.WebApi.Extensions;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Kysect.Shreks.WebApi.Controllers;
namespace Kysect.Shreks.Controllers;

[ApiController]
[Route("api/[controller]")]
Expand Down