-
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
Showing
28 changed files
with
1,395 additions
and
2 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
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,10 @@ | ||
namespace Clients.API | ||
{ | ||
public class Client | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
Check warning on line 6 in samples/Clients.API/Client.cs GitHub Actions / build
|
||
public int Age { get; set; } | ||
public string Email { get; set; } | ||
Check warning on line 8 in samples/Clients.API/Client.cs GitHub Actions / build
|
||
} | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\NetSwissTools.Web\NetSwissTools.Web.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,81 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using NetSwissTools.Web.Mvc; | ||
using NetSwissTools.Web.Mvc.Results; | ||
using System; | ||
using System.Net; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Clients.API.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
[ApiVersion("1")] | ||
public class ClientsController : SwissControllerApi | ||
{ | ||
public ClientsController(ILogger<ClientsController> logger) | ||
{ | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Post(Client client) | ||
{ | ||
lock (MemoryStore.Clients) | ||
{ | ||
client.Id = Guid.NewGuid(); | ||
|
||
MemoryStore.Clients.Add(client); | ||
} | ||
await Task.Delay(1000); | ||
return base.Created(client.Id.ToString(), client); | ||
} | ||
|
||
[HttpPost("Pending")] | ||
public async Task<IActionResult> PostCreate(Client client) | ||
{ | ||
lock (MemoryStore.ClientsPending) | ||
{ | ||
client.Id = Guid.NewGuid(); | ||
|
||
MemoryStore.ClientsPending.Add(client); | ||
} | ||
await Task.Delay(1000); | ||
return Created(client.Id.ToString(), client); | ||
} | ||
|
||
[HttpPost("Simulate/{id}")] | ||
public async Task<IActionResult> PostSimulate(Guid id) | ||
{ | ||
await Task.Delay(1000); | ||
lock (MemoryStore.ClientsPending) | ||
{ | ||
var client = MemoryStore.ClientsPending.FirstOrDefault(x => x.Id == id); | ||
|
||
if (client == null) | ||
return MovedPermanently(id.ToString()); | ||
|
||
MemoryStore.Clients.Add(client); | ||
MemoryStore.ClientsPending.Remove(client); | ||
|
||
return Created(client.Id.ToString(), client); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult<Client> Get() | ||
{ | ||
lock (MemoryStore.Clients) | ||
{ | ||
return RequestOK(MemoryStore.Clients); | ||
} | ||
} | ||
|
||
[HttpGet("{id}")] | ||
public ActionResult<Client> GetById(Guid id) | ||
{ | ||
lock (MemoryStore.Clients) | ||
{ | ||
return RequestOK(MemoryStore.Clients.Find(x => x.Id == id)); | ||
} | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace Clients.API | ||
{ | ||
public static class MemoryStore | ||
{ | ||
public static List<Client> Clients = new(); | ||
public static List<Client> ClientsPending = new(); | ||
} | ||
} |
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,25 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
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,31 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:38011", | ||
"sslPort": 44392 | ||
} | ||
}, | ||
"profiles": { | ||
"Clients.API": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7038;http://localhost:5031", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_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,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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,18 @@ | ||
namespace NetSwissTools.Web.Enums | ||
{ | ||
public enum EExceptionErrorCodes | ||
{ | ||
UnhandledException = 900, | ||
InvalidRequest = 997, | ||
UnauthorizedRequest = 998, | ||
InvalidEstablishmentKey = 999, | ||
ValidationError = -10000, | ||
RegisterNotFound = -15000, | ||
RegisterChild = -16000, | ||
InsertSQLError = -20001, | ||
UpdateSQLError = -20002, | ||
DeleteSQLError = -20003, | ||
SaveSQLError = -20004, | ||
SQLCommandError = -20005 | ||
} | ||
} |
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,32 @@ | ||
using System.Net; | ||
|
||
namespace NetSwissTools.Web.Mvc.Helpers | ||
{ | ||
public static class ResultStatusHelper | ||
{ | ||
public static bool IsClientError(HttpStatusCode code) => | ||
(int)code >= 400 && (int)code <= 499; | ||
|
||
public static bool IsInformational(HttpStatusCode code) => | ||
(int)code >= 100 && (int)code <= 199; | ||
|
||
public static bool IsRedirect(HttpStatusCode code) => | ||
(int)code >= 300 && (int)code <= 399; | ||
|
||
public static bool IsServerError(HttpStatusCode code) => | ||
(int)code >= 500 && (int)code <= 599; | ||
|
||
public static bool IsSuccess(HttpStatusCode code) => | ||
(int)code >= 200 && (int)code <= 299; | ||
|
||
public static bool IsSuccessReponse(HttpStatusCode code) | ||
{ | ||
if (IsInformational(code) || IsSuccess(code) || IsRedirect(code)) | ||
return true; | ||
else if (IsClientError(code) || IsServerError(code)) | ||
return false; | ||
|
||
return false; | ||
} | ||
} | ||
} |
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 NetSwissTools.Exceptions; | ||
|
||
namespace NetSwissTools.Web.Mvc.Interfaces | ||
{ | ||
public interface IErrorService | ||
{ | ||
List<ModelException> Errors { 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,20 @@ | ||
using NetSwissTools.Exceptions; | ||
|
||
namespace NetSwissTools.Web.Mvc.Interfaces | ||
{ | ||
public interface IErrorsController | ||
{ | ||
void AddError(string message); | ||
void AddError(string field, string exception); | ||
void AddError(string field, string exception, string value); | ||
void AddError(int code, string field, string exception, string value); | ||
void AddError(ModelException exception); | ||
void AddError(ModelException[] exceptions); | ||
void AddError(Exception exception); | ||
void ClearErrors(); | ||
ModelException[] GetErrors(); | ||
bool HasAnyErrors(); | ||
bool IsOperationValid(); | ||
bool ValidateModelState<TEntity>(TEntity pModel) where TEntity : class; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/NetSwissTools.Web/Mvc/Interfaces/IResultStatusController.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,15 @@ | ||
using System.Net; | ||
|
||
namespace NetSwissTools.Web.Mvc.Interfaces | ||
{ | ||
public interface IResultStatusController | ||
{ | ||
bool IsInformational(HttpStatusCode code); | ||
bool IsSuccess(HttpStatusCode code); | ||
bool IsRedirect(HttpStatusCode code); | ||
bool IsClientError(HttpStatusCode code); | ||
bool IsServerError(HttpStatusCode code); | ||
bool IsSuccessReponse(HttpStatusCode code); | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/NetSwissTools.Web/Mvc/Interfaces/IUrlInfoController.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,13 @@ | ||
namespace NetSwissTools.Web.Mvc.Interfaces | ||
{ | ||
public interface IUrlInfoController | ||
{ | ||
IQueryCollection QueryString { get; } | ||
int GetPageNumber(); | ||
int GetPageSize(); | ||
string GetSort(); | ||
string GetFilter(); | ||
string GetQueryColumn(); | ||
DateTime? GetDateTime(string pDate); | ||
} | ||
} |
Oops, something went wrong.