Initial commit

This commit is contained in:
2021-06-15 10:59:47 +02:00
commit 8e156ba356
65 changed files with 1786 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
using System.Net;
using GerstITS.Data;
using GerstITS.Web.Api.ExceptionHandling;
namespace GerstITS.Examples.Api.ExceptionHandling
{
public class EntityNotFoundExceptionTransformation : ExceptionTransformationBase<EntityNotFoundException>
{
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(EntityNotFoundException exception, string ticketId)
{
return new ExceptionTransformationInfo
{
StatusCode = HttpStatusCode.NotFound,
ReasonPhrase = "Enitity nicht gefunden",
Details = exception.Message
};
}
}
}

View File

@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
using System.Net;
using GerstITS.Web.Api.ExceptionHandling;
namespace GerstITS.Examples.Api.ExceptionHandling
{
internal sealed class ValidationExceptionTransformation : ExceptionTransformationBase<ValidationException>
{
#region Methods
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(ValidationException exception, string ticketId)
{
return new ExceptionTransformationInfo
{
StatusCode = HttpStatusCode.BadRequest,
ReasonPhrase = "Validierungsfehler",
Details = exception.Message
};
}
#endregion
}
}

View File

@@ -0,0 +1,39 @@
using System.Diagnostics;
using GerstITS.Examples.Logic.Example;
using GerstITS.IoC;
using GerstITS.System.Json;
namespace GerstITS.Examples.Api.StartupTasks
{
internal class ExampleStartupTask : IStartupTask
{
#region Fields#
private readonly IExampleProvider _provider;
private readonly IJsonConvert _jsonConvert;
#endregion
#region Construtcors
public ExampleStartupTask(IExampleProvider provider,
IJsonConvert jsonConvert)
{
_jsonConvert = jsonConvert;
_provider = provider;
}
#endregion
#region IStartupTask
public StartupPriorities Priority => StartupPriorities.Normal;
public void Execute()
{
Debug.WriteLine($"---> {nameof(ExampleStartupTask)}: {_jsonConvert.Serialize(_provider.GetById(123))}");
}
#endregion
}
}

View File

@@ -0,0 +1,15 @@
using System;
using GerstITS.Web.Api.Swagger;
namespace GerstITS.Examples.Api.Swagger
{
internal class LicenseConfiguration : ILicense
{
#region Properties
public string Name { get; set; }
public Uri Url { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,19 @@
using GerstITS.Web.Api.Swagger;
using Microsoft.OpenApi.Models;
namespace GerstITS.Examples.Api.Swagger
{
internal sealed class SwaggerSecurityConfiguration : IOpenApiSecuritySchemeConfiguration
{
#region Properties
public bool AllowAnonymous { get; set; }
public string HttpHeaderKey { get; set; }
public string Scheme { get; set; }
public SecuritySchemeType SchemeType { get; set; }
public ParameterLocation ParameterLocation { get; set; }
public string Description { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Diagnostics;
using GerstITS.System.Configurations;
using GerstITS.Web.Api.Swagger;
namespace GerstITS.Examples.Api.Swagger
{
internal class WebApiConfiguration : ISwaggerConfiguration, IConfiguration
{
#region Constructors
public WebApiConfiguration()
{
var currentAssembly = typeof(WebApiConfiguration).Assembly;
var fileVersionInfo = FileVersionInfo.GetVersionInfo(currentAssembly.Location);
Company = fileVersionInfo.CompanyName;
Name = fileVersionInfo.ProductName;
Release = currentAssembly.GetName().Version;
TermsOfService = new Uri("https://en.wikipedia.org/wiki/Terms_of_service");
License = new LicenseConfiguration
{
Name = "MIT",
Url = new Uri("https://opensource.org/licenses/MIT")
};
SupportEMail = "info@examples.net";
Security = new SwaggerSecurityConfiguration
{
AllowAnonymous = true
};
}
#endregion
#region ISwaggerConfiguration
public string Name { get; }
public string Company { get; }
public string SupportEMail { get; }
public Uri TermsOfService { get; }
public ILicense License { get; }
public Version Release { get; }
public IOpenApiSecuritySchemeConfiguration Security { get; }
#endregion
}
}

View File

@@ -0,0 +1,12 @@
namespace GerstITS.Examples.Api.Versioning
{
public static class Versions
{
#region Versions
public const string _1_0 = "1.0";
public const string _1_1 = "1.1";
#endregion
}
}