| | | 1 | | using ArturRios.Util.Http; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Heimdall.Shared.Messages; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Maps each <see cref="ApplicationMessages" /> value to its HTTP status code, following the |
| | | 7 | | /// UC-16 – UC-20 flows. Passed to the response resolver. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class ApplicationMessageMap |
| | | 10 | | { |
| | 4 | 11 | | public static readonly IReadOnlyDictionary<string, int> StatusCodes = |
| | 4 | 12 | | DataAccessMessageMap.CombinedWith(new Dictionary<string, int> |
| | 4 | 13 | | { |
| | 4 | 14 | | // UC-16 main flow — application created. |
| | 4 | 15 | | [ApplicationMessages.ApplicationCreatedSuccessfully] = HttpStatusCodes.Created, |
| | 4 | 16 | | // AF-16a — scope not found. |
| | 4 | 17 | | [ApplicationMessages.ScopeNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 18 | | // AF-16e — the acting Scope Admin does not own the target scope; AF-16c — a Scope Admin |
| | 4 | 19 | | // named someone else as owner. |
| | 4 | 20 | | [ApplicationMessages.NotScopeOwner] = HttpStatusCodes.Forbidden, |
| | 4 | 21 | | [ApplicationMessages.CannotSetAnotherOwner] = HttpStatusCodes.Forbidden, |
| | 4 | 22 | | // AF-16b — the owner is not tied to the scope. |
| | 4 | 23 | | [ApplicationMessages.OwnerNotValidForScope] = HttpStatusCodes.BadRequest, |
| | 4 | 24 | | // AF-16d — invalid input. |
| | 4 | 25 | | [ApplicationMessages.NameRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 26 | | [ApplicationMessages.NameTooLong] = HttpStatusCodes.BadRequest, |
| | 4 | 27 | | [ApplicationMessages.OwnerRequired] = HttpStatusCodes.BadRequest, |
| | 4 | 28 | | // UC-17 main flow — application(s) retrieved. |
| | 4 | 29 | | [ApplicationMessages.ApplicationRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 30 | | [ApplicationMessages.ApplicationsRetrievedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 31 | | // AF-17a — application not found. The listing's own 404 reuses ScopeNotFound above. |
| | 4 | 32 | | [ApplicationMessages.ApplicationNotFound] = HttpStatusCodes.NotFound, |
| | 4 | 33 | | // AF-17b — caller may not view the application. The listing's 403 reuses NotScopeOwner. |
| | 4 | 34 | | [ApplicationMessages.NotAuthorizedToViewApplication] = HttpStatusCodes.Forbidden, |
| | 4 | 35 | | // UC-18 main flow — application updated. |
| | 4 | 36 | | [ApplicationMessages.ApplicationUpdatedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 37 | | // AF-18c — caller may not update the application. AF-18a reuses ApplicationNotFound above, |
| | 4 | 38 | | // AF-18b reuses OwnerNotValidForScope, and UC-18's input validation reuses the UC-16 messages. |
| | 4 | 39 | | [ApplicationMessages.NotAuthorizedToUpdateApplication] = HttpStatusCodes.Forbidden, |
| | 4 | 40 | | // UC-19 main flow — application logically deleted. AF-19b answers with the same 200, so the |
| | 4 | 41 | | // response's AlreadyDeleted flag is what tells the two paths apart. |
| | 4 | 42 | | [ApplicationMessages.ApplicationDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 43 | | // AF-19c — caller may not delete the application. AF-19a reuses ApplicationNotFound above. |
| | 4 | 44 | | [ApplicationMessages.NotAuthorizedToDeleteApplication] = HttpStatusCodes.Forbidden, |
| | 4 | 45 | | // UC-20 main flow — application hard deleted. AF-20a reuses ApplicationNotFound above, and |
| | 4 | 46 | | // UC-20's only other refusals are the framework's: 403 from [RoleRequirement], 401 unauthenticated. |
| | 4 | 47 | | [ApplicationMessages.ApplicationHardDeletedSuccessfully] = HttpStatusCodes.Ok, |
| | 4 | 48 | | // UC-17 listing (NFR-10) — invalid pagination or an over-length name filter. |
| | 4 | 49 | | [PaginationMessages.InvalidPageNumber] = HttpStatusCodes.BadRequest, |
| | 4 | 50 | | [PaginationMessages.InvalidPageSize] = HttpStatusCodes.BadRequest, |
| | 4 | 51 | | [PaginationMessages.FilterTooLong] = HttpStatusCodes.BadRequest |
| | 4 | 52 | | }); |
| | | 53 | | } |