2026-10-28 21:43:17 +01:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
[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();
|
|
|
|
|
|
}
|
2026-11-19 13:07:48 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>Kategorie závad. Administrátor může zobrazit i deaktivované pomocí <c>includeInactive=true</c>.</summary>
|
|
|
|
|
|
[HttpGet("issue-categories")]
|
|
|
|
|
|
public Task<IReadOnlyList<CategoryDto>> GetIssueCategories([FromQuery] bool includeInactive = false, CancellationToken ct = default) =>
|
|
|
|
|
|
catalogs.GetIssueCategoriesAsync(includeInactive && User.IsInRole(Roles.Admin), ct);
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpPost("issue-categories")]
|
|
|
|
|
|
[ProducesResponseType<CategoryDto>(StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType<ValidationProblemDetails>(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
|
|
|
|
|
public async Task<ActionResult<CategoryDto>> CreateIssueCategory(SaveCategoryRequest request, CancellationToken ct)
|
|
|
|
|
|
{
|
|
|
|
|
|
var category = await catalogs.CreateIssueCategoryAsync(request, ct);
|
|
|
|
|
|
return Created($"/api/issue-categories/{category.Id}", category);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpPut("issue-categories/{id:int}")]
|
|
|
|
|
|
[ProducesResponseType<CategoryDto>(StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType<ValidationProblemDetails>(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
|
|
|
|
|
public Task<CategoryDto> UpdateIssueCategory(int id, SaveCategoryRequest request, CancellationToken ct) =>
|
|
|
|
|
|
catalogs.UpdateIssueCategoryAsync(id, request, ct);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Deaktivuje kategorii závad.</summary>
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpDelete("issue-categories/{id:int}")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<IActionResult> DeactivateIssueCategory(int id, CancellationToken ct)
|
|
|
|
|
|
{
|
|
|
|
|
|
await catalogs.DeactivateIssueCategoryAsync(id, ct);
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Kategorie návrhů. Administrátor může zobrazit i deaktivované pomocí <c>includeInactive=true</c>.</summary>
|
|
|
|
|
|
[HttpGet("proposal-categories")]
|
|
|
|
|
|
public Task<IReadOnlyList<CategoryDto>> GetProposalCategories([FromQuery] bool includeInactive = false, CancellationToken ct = default) =>
|
|
|
|
|
|
catalogs.GetProposalCategoriesAsync(includeInactive && User.IsInRole(Roles.Admin), ct);
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpPost("proposal-categories")]
|
|
|
|
|
|
[ProducesResponseType<CategoryDto>(StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType<ValidationProblemDetails>(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
|
|
|
|
|
public async Task<ActionResult<CategoryDto>> CreateProposalCategory(SaveCategoryRequest request, CancellationToken ct)
|
|
|
|
|
|
{
|
|
|
|
|
|
var category = await catalogs.CreateProposalCategoryAsync(request, ct);
|
|
|
|
|
|
return Created($"/api/proposal-categories/{category.Id}", category);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpPut("proposal-categories/{id:int}")]
|
|
|
|
|
|
[ProducesResponseType<CategoryDto>(StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType<ValidationProblemDetails>(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
|
|
|
|
|
public Task<CategoryDto> UpdateProposalCategory(int id, SaveCategoryRequest request, CancellationToken ct) =>
|
|
|
|
|
|
catalogs.UpdateProposalCategoryAsync(id, request, ct);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Deaktivuje kategorii návrhů.</summary>
|
|
|
|
|
|
[Authorize(Roles = Roles.Admin)]
|
|
|
|
|
|
[HttpDelete("proposal-categories/{id:int}")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<IActionResult> DeactivateProposalCategory(int id, CancellationToken ct)
|
|
|
|
|
|
{
|
|
|
|
|
|
await catalogs.DeactivateProposalCategoryAsync(id, ct);
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
}
|
2026-10-28 21:43:17 +01:00
|
|
|
|
}
|