Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Fin.Api/People/PersonController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Fin.Application.People;
using Fin.Application.People.Dtos;
using Fin.Application.People.Enums;
using Fin.Domain.Global.Classes;
using Fin.Domain.People.Dtos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Fin.Api.People;

[Route("people")]
[Authorize]
public class PersonController(IPersonService service) : ControllerBase
{
[HttpGet]
public async Task<PagedOutput<PersonOutput>> GetList([FromQuery] PersonGetListInput input)
{
return await service.GetList(input);
}

[HttpGet("{id:guid}")]
public async Task<ActionResult<PersonOutput>> Get([FromRoute] Guid id)
{
var category = await service.Get(id);
return category != null ? Ok(category) : NotFound();
}

[HttpPost]
public async Task<ActionResult<PersonOutput>> Create([FromBody] PersonInput input)
{
var validationResult = await service.Create(input, autoSave: true);
return validationResult.Success
? Created($"categories/{validationResult.Data?.Id}", validationResult.Data)
: UnprocessableEntity(validationResult);
}

[HttpPut("{id:guid}")]
public async Task<ActionResult> Update([FromRoute] Guid id, [FromBody] PersonInput input)
{
var validationResult = await service.Update(id, input, autoSave: true);
return validationResult.Success
? Ok()
: validationResult.ErrorCode == PersonCreateOrUpdateErrorCode.PersonNotFound
? NotFound(validationResult)
: UnprocessableEntity(validationResult);
}

[HttpPut("toggle-inactivated/{id:guid}")]
public async Task<ActionResult> ToggleInactivated([FromRoute] Guid id)
{
var updated = await service.ToggleInactive(id, autoSave: true);
return updated ? Ok() : NotFound();
}

[HttpDelete("{id:guid}")]
public async Task<ActionResult> Delete([FromRoute] Guid id)
{
var validation = await service.Delete(id, autoSave: true);
return validation.Success ? NoContent() : validation.ErrorCode == PersonDeleteErrorCode.PersonNotFound ? NotFound(validation): UnprocessableEntity(validation);
}
}
16 changes: 14 additions & 2 deletions Fin.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
var builder = WebApplication.CreateBuilder(args);

var frontEndUrl = builder.Configuration.GetSection(AppConstants.FrontUrlConfigKey).Get<string>();
var version = builder.Configuration.GetSection(AppConstants.VersionConfigKey).Get<string>();

builder.Services
.AddInfrastructure(builder.Configuration)
Expand Down Expand Up @@ -41,6 +42,14 @@

var app = builder.Build();

if (!string.IsNullOrWhiteSpace(version))
{
var versionPathBase = version;
if (!versionPathBase.StartsWith("/")) versionPathBase = $"/{versionPathBase}";
app.UsePathBase(versionPathBase);
}


if (app.Environment.IsDevelopment())
{
app.UseOpenApi();
Expand All @@ -55,11 +64,14 @@
await app.UseDbMigrations();
await app.UseSeeders();

app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();

app.UseHsts();
app.UseHttpsRedirection();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.Run();
4 changes: 2 additions & 2 deletions Fin.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": true,
"applicationUrl": "http://localhost:5045",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -13,7 +13,7 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": true,
"applicationUrl": "https://localhost:7122",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
Loading
Loading