mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Restructure project
This commit is contained in:
22
API/API.Core/API.Core.csproj
Normal file
22
API/API.Core/API.Core.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>WebAPI</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Infrastructure\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Repository\Repository.Core\Repository.Core.csproj" />
|
||||
<ProjectReference Include="..\..\Service\Service.Core\Service.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
16
API/API.Core/Controllers/NotFoundController.cs
Normal file
16
API/API.Core/Controllers/NotFoundController.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Route("error")] // ← required
|
||||
public class NotFoundController : ControllerBase
|
||||
{
|
||||
[HttpGet("404")] // ← required
|
||||
public IActionResult Handle404()
|
||||
{
|
||||
return NotFound(new { message = "Route not found." });
|
||||
}
|
||||
}
|
||||
}
|
||||
26
API/API.Core/Controllers/UserController.cs
Normal file
26
API/API.Core/Controllers/UserController.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using BusinessLayer.Services;
|
||||
using DataAccessLayer.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UserController(IUserService userService) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<UserAccount>>> GetAll([FromQuery] int? limit, [FromQuery] int? offset)
|
||||
{
|
||||
var users = await userService.GetAllAsync(limit, offset);
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<ActionResult<UserAccount>> GetById(Guid id)
|
||||
{
|
||||
var user = await userService.GetByIdAsync(id);
|
||||
if (user is null) return NotFound();
|
||||
return Ok(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
API/API.Core/Program.cs
Normal file
25
API/API.Core/Program.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using BusinessLayer.Services;
|
||||
using DataAccessLayer.Repositories;
|
||||
using DataAccessLayer.Sql;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
// Dependency Injection
|
||||
builder.Services.AddSingleton<ISqlConnectionFactory, DefaultSqlConnectionFactory>();
|
||||
builder.Services.AddScoped<IUserAccountRepository, UserAccountRepository>();
|
||||
builder.Services.AddScoped<IUserService, UserService>();
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.MapOpenApi();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
app.MapFallbackToController("Handle404", "NotFound");
|
||||
app.Run();
|
||||
23
API/API.Core/Properties/launchSettings.json
Normal file
23
API/API.Core/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5069",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7002;http://localhost:5069",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
API/API.Core/WebAPI.http
Normal file
64
API/API.Core/WebAPI.http
Normal file
@@ -0,0 +1,64 @@
|
||||
@WebAPI_HostAddress = http://localhost:5069
|
||||
|
||||
GET {{WebAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/by-username/{{username}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/by-email/{{email}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
POST {{WebAPI_HostAddress}}/api/users
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"userAccountID": "00000000-0000-0000-0000-000000000000",
|
||||
"username": "testuser",
|
||||
"firstName": "Test",
|
||||
"lastName": "User",
|
||||
"email": "testuser@example.com",
|
||||
"createdAt": "2025-01-01T00:00:00Z",
|
||||
"updatedAt": null,
|
||||
"dateOfBirth": "1990-01-01T00:00:00Z",
|
||||
"timer": null
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
PUT {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"userAccountID": "{{userId}}",
|
||||
"username": "testuser",
|
||||
"firstName": "Updated",
|
||||
"lastName": "User",
|
||||
"email": "testuser@example.com",
|
||||
"createdAt": "2025-01-01T00:00:00Z",
|
||||
"updatedAt": "2025-02-01T00:00:00Z",
|
||||
"dateOfBirth": "1990-01-01T00:00:00Z",
|
||||
"timer": null
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
8
API/API.Core/appsettings.Development.json
Normal file
8
API/API.Core/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
API/API.Core/appsettings.json
Normal file
9
API/API.Core/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user