-
Notifications
You must be signed in to change notification settings - Fork 9
Develop #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Develop #11
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| using Resgrid.Providers.ApiClient.V4.Models; | ||
| using System; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Resgrid.Providers.ApiClient.V4 | ||
| { | ||
| /// <summary> | ||
| /// Provides v4 API methods to resolve dispatch codes (names like "STATION5") | ||
| /// into numeric IDs required by the DispatchList parameter in SaveCall. | ||
| /// | ||
| /// These endpoints correspond to the new lookup APIs that need to be built | ||
| /// in the Resgrid API project. Until they exist, callers should handle the | ||
| /// expected 404 gracefully and fall back to code-based DispatchList values. | ||
| /// </summary> | ||
| public static class LookupsApi | ||
| { | ||
| /// <summary> | ||
| /// Resolves a group dispatch email code to its numeric group ID. | ||
| /// Maps to: GET /api/v4/Groups/GetGroupByDispatchCode?code={code}&departmentId={departmentId} | ||
| /// | ||
| /// Behind the scenes this queries DepartmentGroups.DispatchEmail. | ||
| /// Returns null when the endpoint returns 404 (group not found or API | ||
| /// endpoint not yet deployed). | ||
| /// </summary> | ||
| public static async Task<GroupLookupResult> LookupGroupByDispatchCodeAsync( | ||
| string code, | ||
| string departmentId, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| if (String.IsNullOrWhiteSpace(code)) | ||
| return null; | ||
|
|
||
| var url = $"Groups/GetGroupByDispatchCode?code={Uri.EscapeDataString(code)}"; | ||
|
|
||
| if (!String.IsNullOrWhiteSpace(departmentId)) | ||
| url += $"&departmentId={Uri.EscapeDataString(departmentId)}"; | ||
|
|
||
| return await TryGetAsync<GroupLookupResult>(url, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resolves a group message email code to its numeric group ID. | ||
| /// Maps to: GET /api/v4/Groups/GetGroupByMessageCode?code={code}&departmentId={departmentId} | ||
| /// | ||
| /// Behind the scenes this queries DepartmentGroups.MessageEmail. | ||
| /// Returns null when the endpoint returns 404. | ||
| /// </summary> | ||
| public static async Task<GroupLookupResult> LookupGroupByMessageCodeAsync( | ||
| string code, | ||
| string departmentId, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| if (String.IsNullOrWhiteSpace(code)) | ||
| return null; | ||
|
|
||
| var url = $"Groups/GetGroupByMessageCode?code={Uri.EscapeDataString(code)}"; | ||
|
|
||
| if (!String.IsNullOrWhiteSpace(departmentId)) | ||
| url += $"&departmentId={Uri.EscapeDataString(departmentId)}"; | ||
|
|
||
| return await TryGetAsync<GroupLookupResult>(url, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resolves a unit name to its numeric unit ID. | ||
| /// Maps to: GET /api/v4/Units/GetUnitByName?name={name}&departmentId={departmentId} | ||
| /// | ||
| /// Behind the scenes this queries Units.UnitName. | ||
| /// Returns null when the endpoint returns 404. | ||
| /// </summary> | ||
| public static async Task<UnitLookupResult> LookupUnitByNameAsync( | ||
| string name, | ||
| string departmentId, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| if (String.IsNullOrWhiteSpace(name)) | ||
| return null; | ||
|
|
||
| var url = $"Units/GetUnitByName?name={Uri.EscapeDataString(name)}"; | ||
|
|
||
| if (!String.IsNullOrWhiteSpace(departmentId)) | ||
| url += $"&departmentId={Uri.EscapeDataString(departmentId)}"; | ||
|
|
||
| return await TryGetAsync<UnitLookupResult>(url, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resolves a role name to its numeric role ID. | ||
| /// Maps to: GET /api/v4/Roles/GetRoleByName?name={name}&departmentId={departmentId} | ||
| /// | ||
| /// Behind the scenes this queries PersonnelRoles.Name. | ||
| /// Returns null when the endpoint returns 404. | ||
| /// </summary> | ||
| public static async Task<RoleLookupResult> LookupRoleByNameAsync( | ||
| string name, | ||
| string departmentId, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| if (String.IsNullOrWhiteSpace(name)) | ||
| return null; | ||
|
|
||
| var url = $"Roles/GetRoleByName?name={Uri.EscapeDataString(name)}"; | ||
|
|
||
| if (!String.IsNullOrWhiteSpace(departmentId)) | ||
| url += $"&departmentId={Uri.EscapeDataString(departmentId)}"; | ||
|
|
||
| return await TryGetAsync<RoleLookupResult>(url, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| private static async Task<T> TryGetAsync<T>(string url, CancellationToken cancellationToken) where T : class | ||
| { | ||
| try | ||
| { | ||
| var response = await ResgridV4ApiClient.GetAsync<LookupResponse<T>>(url, cancellationToken).ConfigureAwait(false); | ||
| return response?.Data; | ||
| } | ||
| catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound) | ||
| { | ||
| // Entity not found, or the API endpoint doesn't exist yet. | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.