Základní backend: migrace, autentizace JWT, role, Swagger
- Helpdesk.Migrator (DbUp) aplikuje db/migrations, evidence v schema_version - Domain/Application/Infrastructure/Api podle Clean Architecture - registrace, ověření e-mailu, login, refresh s rotací, logout, reset hesla - JWT podle RFC 7519 evidované jen podle jti v auth_token - správa uživatelů a rolí, číselníky, ProblemDetails, Swagger UI - Docker Compose (db, migrator, api), oddělené DB účty - notifikace mají cizí klíče na issue a proposal - unit testy domény a zabezpečení Closes #1, closes #2, closes #3, closes #4, closes #5, closes #9
This commit is contained in:
1 parent
fc76be7d69
commit
a51d386278
64 files changed
+4394
-1
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using Helpdesk.Api.Infrastructure;
|
||||
using Helpdesk.Application.Catalogs;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Helpdesk.Api.Controllers;
|
||||
|
||||
/// <summary>Číselníky pro formuláře (budovy, kategorie závad a návrhů) a jejich správa.</summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api")]
|
||||
[Produces("application/json")]
|
||||
public sealed class CatalogsController(CatalogService catalogs) : ControllerBase
|
||||
{
|
||||
/// <summary>Budovy. Administrátor může přidat <c>includeInactive=true</c> a vidět i deaktivované.</summary>
|
||||
[HttpGet("buildings")]
|
||||
public Task<IReadOnlyList<BuildingDto>> GetBuildings([FromQuery] bool includeInactive = false, CancellationToken ct = default) =>
|
||||
catalogs.GetBuildingsAsync(includeInactive && User.IsInRole(Roles.Admin), ct);
|
||||
|
||||
[HttpGet("issue-categories")]
|
||||
public Task<IReadOnlyList<CategoryDto>> GetIssueCategories(CancellationToken ct) => catalogs.GetIssueCategoriesAsync(ct);
|
||||
|
||||
[HttpGet("proposal-categories")]
|
||||
public Task<IReadOnlyList<CategoryDto>> GetProposalCategories(CancellationToken ct) => catalogs.GetProposalCategoriesAsync(ct);
|
||||
|
||||
[Authorize(Roles = Roles.Admin)]
|
||||
[HttpPost("buildings")]
|
||||
[ProducesResponseType<BuildingDto>(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
||||
public async Task<ActionResult<BuildingDto>> CreateBuilding(SaveBuildingRequest request, CancellationToken ct)
|
||||
{
|
||||
var building = await catalogs.CreateBuildingAsync(request, ct);
|
||||
return Created($"/api/buildings/{building.Id}", building);
|
||||
}
|
||||
|
||||
[Authorize(Roles = Roles.Admin)]
|
||||
[HttpPut("buildings/{id:int}")]
|
||||
[ProducesResponseType<BuildingDto>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
||||
public Task<BuildingDto> UpdateBuilding(int id, SaveBuildingRequest request, CancellationToken ct) =>
|
||||
catalogs.UpdateBuildingAsync(id, request, ct);
|
||||
|
||||
/// <summary>Deaktivace budovy – záznam se nemaže, jen se přestane nabízet ve formulářích.</summary>
|
||||
[Authorize(Roles = Roles.Admin)]
|
||||
[HttpDelete("buildings/{id:int}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DeactivateBuilding(int id, CancellationToken ct)
|
||||
{
|
||||
await catalogs.DeactivateBuildingAsync(id, ct);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user