Restructure project

This commit is contained in:
Aaron Po
2026-01-15 21:48:20 -05:00
parent c5aaf8cd05
commit 89da531c48
47 changed files with 57 additions and 157 deletions

View 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>

View 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." });
}
}
}

View 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
View 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();

View 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
View 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}}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}