-
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.
- Loading branch information
DustSwiffer
committed
Jul 22, 2024
0 parents
commit 9f8efe2
Showing
70 changed files
with
3,711 additions
and
0 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 @@ | ||
[*.cs] | ||
|
||
|
||
# SA1404: Code analysis suppression should have justification | ||
dotnet_diagnostic.SA1404.severity = none | ||
|
||
# SA1633: File header | ||
dotnet_diagnostic.SA1633.severity = none | ||
|
||
# SA1101: Prefix local calls with this | ||
dotnet_diagnostic.SA1101.severity = none | ||
|
||
# SA1611: Element parameters should be documented | ||
dotnet_diagnostic.SA1611.severity = none | ||
|
||
# SA1309: starting underscore | ||
dotnet_diagnostic.SA1309.severity = none | ||
|
||
dotnet_diagnostic.SA1615.severity = none | ||
|
||
dotnet_diagnostic.SA1642.severity = none | ||
|
||
dotnet_diagnostic.SA1623.severity = none |
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,86 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
# This workflow will build, test, sign and package a WPF or Windows Forms desktop application | ||
# built on .NET Core. | ||
# To learn how to migrate your existing application to .NET Core, | ||
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework | ||
# | ||
# To configure this workflow: | ||
# | ||
# 1. Configure environment variables | ||
# GitHub sets default environment variables for every workflow run. | ||
# Replace the variables relative to your project in the "env" section below. | ||
# | ||
# 2. Signing | ||
# Generate a signing certificate in the Windows Application | ||
# Packaging Project or add an existing signing certificate to the project. | ||
# Next, use PowerShell to encode the .pfx file using Base64 encoding | ||
# by running the following Powershell script to generate the output string: | ||
# | ||
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte | ||
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt' | ||
# | ||
# Open the output file, SigningCertificate_Encoded.txt, and copy the | ||
# string inside. Then, add the string to the repo as a GitHub secret | ||
# and name it "Base64_Encoded_Pfx." | ||
# For more information on how to configure your signing certificate for | ||
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing | ||
# | ||
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key". | ||
# See "Build the Windows Application Packaging project" below to see how the secret is used. | ||
# | ||
# For more information on GitHub Actions, refer to https://github.com/features/actions | ||
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications, | ||
# refer to https://github.com/microsoft/github-actions-for-desktop-apps | ||
|
||
name: .NET Core Desktop | ||
|
||
on: | ||
push: | ||
branches: [ "master", "develop" ] | ||
pull_request: | ||
branches: [ "master", "develop" ] | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
strategy: | ||
matrix: | ||
configuration: [Debug] | ||
|
||
runs-on: windows-latest # For a list of available runner types, refer to | ||
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on | ||
|
||
env: | ||
Solution_Name: AdvancedAPI.sln | ||
Test_Project_Path: AdvancedAPI.Tests\AdvancedAPI.Tests.csproj | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# Install the .NET Core workload | ||
- name: Install .NET Core | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 6.0.x | ||
|
||
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild | ||
- name: Setup MSBuild.exe | ||
uses: microsoft/setup-msbuild@v2 | ||
|
||
# Execute all unit tests in the solution | ||
- name: Execute unit tests | ||
run: dotnet test | ||
|
||
# Restore the application to populate the obj folder with RuntimeIdentifiers | ||
- name: Restore the application | ||
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration | ||
env: | ||
Configuration: ${{ matrix.configuration }} |
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,135 @@ | ||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
|
||
[Dd]ebug/ | ||
[Rr]elease/ | ||
x64/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
*_i.c | ||
*_p.c | ||
*_i.h | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.log | ||
*.svclog | ||
*.scc | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# Guidance Automation Toolkit | ||
*.gpState | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
*.DotSettings.user | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Publish Web Output | ||
*.Publish.xml | ||
*.pubxml | ||
*.azurePubxml | ||
|
||
# NuGet Packages Directory | ||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line | ||
packages/ | ||
## TODO: If the tool you use requires repositories.config, also uncomment the next line | ||
!packages/repositories.config | ||
|
||
# Windows Azure Build Output | ||
csx/ | ||
*.build.csdef | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
sql/ | ||
*.Cache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
![Ss]tyle[Cc]op.targets | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.[Pp]ublish.xml | ||
|
||
*.publishsettings | ||
|
||
# RIA/Silverlight projects | ||
Generated_Code/ | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
UpgradeLog*.htm | ||
|
||
# SQL Server files | ||
App_Data/*.mdf | ||
App_Data/*.ldf | ||
|
||
# ========================= | ||
# Windows detritus | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Mac desktop service store files | ||
.DS_Store | ||
|
||
_NCrunch* | ||
*.idea* | ||
.vs |
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>dotnet-Business-63FD5173-E1FF-446F-A3C3-0D5E7DA4C0FF</UserSecretsId> | ||
<RootNamespace>Business</RootNamespace> | ||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoMapper" Version="13.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AdvancedAPI.Data\AdvancedAPI.Data.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="stylecop.json" /> | ||
</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,19 @@ | ||
using AdvancedAPI.Data.Models; | ||
using AdvancedAPI.Data.ViewModels.NewsArticle; | ||
using AutoMapper; | ||
|
||
namespace Business; | ||
|
||
/// <summary> | ||
/// Auto mapper profiles. | ||
/// </summary> | ||
public class MappingProfile : Profile | ||
{ | ||
/// <summary> | ||
/// Mapping Models against entities and opposite. | ||
/// </summary> | ||
public MappingProfile() | ||
{ | ||
CreateMap<NewsArticleRequestModel, NewsArticle>(); | ||
} | ||
} |
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 @@ | ||
using Business; | ||
|
||
IHost host = Host.CreateDefaultBuilder(args) | ||
.ConfigureServices(services => { services.AddHostedService<Worker>(); }) | ||
.Build(); | ||
|
||
await host.RunAsync(); |
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,11 @@ | ||
{ | ||
"profiles": { | ||
"Business": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
using Business.Services; | ||
using Business.Services.Interfaces; | ||
|
||
namespace Business; | ||
|
||
/// <summary> | ||
/// Service extension used to prepare the business layer for usage. | ||
/// </summary> | ||
public static class ServiceExtension | ||
{ | ||
/// <summary> | ||
/// Registers everything business layer related. | ||
/// </summary> | ||
public static IServiceCollection AddBusinessServices(this IServiceCollection services) | ||
{ | ||
services.AddAutoMapper(typeof(MappingProfile).Assembly); | ||
|
||
services.AddScoped<IAuthenticationService, AuthenticationService>(); | ||
services.AddScoped<INewsArticleService, NewsArticleService>(); | ||
|
||
return services; | ||
} | ||
} |
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,55 @@ | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Security.Claims; | ||
using System.Text; | ||
using AdvancedAPI.Data.Repositories.Interfaces; | ||
using AdvancedAPI.Data.ViewModels.Authentication; | ||
using Business.Services.Interfaces; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace Business.Services; | ||
|
||
/// <inheritdoc /> | ||
public class AuthenticationService : IAuthenticationService | ||
{ | ||
private readonly IIdentityRepository _identityRepository; | ||
private readonly IConfiguration _configuration; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public AuthenticationService(IIdentityRepository identityRepository, IConfiguration configuration) | ||
{ | ||
_identityRepository = identityRepository; | ||
_configuration = configuration; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<JwtSecurityToken?> Login(LoginRequestModel requestModel, CancellationToken ct = default) | ||
{ | ||
IdentityUser? user = await _identityRepository.GetUser(requestModel.Username); | ||
if (user != null && await _identityRepository.CheckPassword(user, requestModel.Password)) | ||
{ | ||
List<Claim> authClaims = new() | ||
{ | ||
new Claim(JwtRegisteredClaimNames.Sub, user.UserName), | ||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), | ||
}; | ||
|
||
IList<string> userRoles = await _identityRepository.GetRoles(user); | ||
authClaims.AddRange(userRoles.Select(role => new Claim(ClaimTypes.Role, role))); | ||
SymmetricSecurityKey authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"])); | ||
|
||
JwtSecurityToken token = new JwtSecurityToken( | ||
issuer: _configuration["Jwt:Issuer"], | ||
audience: _configuration["Jwt:Audience"], | ||
expires: DateTime.Now.AddHours(3), | ||
claims: authClaims, | ||
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)); | ||
|
||
return token; | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.