web: formulář nového hlášení závady s přílohami
Název, kategorie, budova, upřesnění místa, popis a až 5 příloh po 10 MB (JPG, PNG, HEIC, PDF, DOCX). Přílohy jdou do API v jednom multipart požadavku spolu s hlášením. Typ, velikost a počet souborů kontroluje už web, obsah souboru ověřuje API. Tlačítko Nahlásit závadu v menu a v seznamu, delší časový limit volání API kvůli nahrávání. Unit testy příloh, místa v seznamu a odeslání formuláře. Refs #23
This commit is contained in:
1 parent
2fe939ba5c
commit
946ff5ce12
9 files changed
+348
-12
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
@@ -33,6 +34,36 @@ public sealed class HelpdeskApiClient(HttpClient http)
|
||||
return await ApiResponse.ReadAsync<PagedResult<IssueSummary>>(response, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nahlásí závadu i s přílohami jedním požadavkem (multipart). Soubory se z formuláře
|
||||
/// posílají rovnou dál jako proud, web je celé nenačítá do paměti.
|
||||
/// </summary>
|
||||
public async Task<IssueDetail> CreateIssueAsync(CreateIssueRequest request, IReadOnlyCollection<UploadFile> files, CancellationToken ct)
|
||||
{
|
||||
using var content = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(request.Title), "title" },
|
||||
{ new StringContent(request.Description), "description" },
|
||||
{ new StringContent(request.CategoryId.ToString(CultureInfo.InvariantCulture)), "categoryId" },
|
||||
};
|
||||
if (request.BuildingId is { } buildingId)
|
||||
content.Add(new StringContent(buildingId.ToString(CultureInfo.InvariantCulture)), "buildingId");
|
||||
if (!string.IsNullOrWhiteSpace(request.LocationDetail))
|
||||
content.Add(new StringContent(request.LocationDetail), "locationDetail");
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var part = new StreamContent(file.OpenRead());
|
||||
part.Headers.ContentType = MediaTypeHeaderValue.TryParse(file.ContentType, out var type)
|
||||
? type
|
||||
: new MediaTypeHeaderValue("application/octet-stream");
|
||||
content.Add(part, "files", file.FileName);
|
||||
}
|
||||
|
||||
using var response = await http.PostAsync("api/v1/issues", content, ct);
|
||||
return await ApiResponse.ReadAsync<IssueDetail>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<CategoryDto>> GetIssueCategoriesAsync(CancellationToken ct)
|
||||
{
|
||||
using var response = await http.GetAsync("api/v1/issue-categories", ct);
|
||||
|
||||
Reference in new issue
Block a user