Skip to content
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

Issue-39: Handle multiple groups in profile #156

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Topo/Services/LoginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LoginService(StorageService storageService, ITerrainAPIService terrainAPI
public async Task<AuthenticationResultModel?> LoginAsync(string? branch, string? username, string? password)
{
var authenticationResultModel = await _terrainAPIService.LoginAsync(branch, username, password);

_storageService.IsAuthenticated = false;
if (authenticationResultModel.AuthenticationSuccessResultModel.AuthenticationResult != null)
{
Expand All @@ -37,24 +37,36 @@ public LoginService(StorageService storageService, ITerrainAPIService terrainAPI

public async Task GetUserAsync()
{
var getUserResultModel = await _terrainAPIService.GetUserAsync();
var getUserResultModel = await _terrainAPIService.GetUserAsync();
_storageService.GetUserResult = getUserResultModel;
}

public async Task GetProfilesAsync()
{
var getProfilesResultModel = await _terrainAPIService.GetProfilesAsync();
var profilesWithUnits = getProfilesResultModel.profiles.Where(p => p.unit != null).ToArray();
getProfilesResultModel.profiles = profilesWithUnits;
if (_storageService != null)
_storageService.GetProfilesResult = getProfilesResultModel;
}

public List<SelectListItem>? GetUnits()
{
return _storageService.GetProfilesResult?.profiles?
.Where(p => p.member.name == _storageService.MemberName)
.Select(p => p.unit)
.Select(u => new SelectListItem { Text = u?.name, Value = u?.id })
.ToList();
var groupCount = _storageService.GetProfilesResult?.profiles.Select(p => p.group.name).Distinct().Count();
if (groupCount == 1)
{
return _storageService.GetProfilesResult?.profiles?
.Where(p => p.member.name == _storageService.MemberName)
.Select(p => new SelectListItem { Text = $"{p.unit?.name}", Value = p.unit?.id })
.ToList();
}
else
{
return _storageService.GetProfilesResult?.profiles?
.Where(p => p.member.name == _storageService.MemberName)
.Select(p => new SelectListItem { Text = $"{p.unit?.name} ({p.group?.name})", Value = p.unit?.id })
.ToList();
}
}


Expand Down
17 changes: 4 additions & 13 deletions Topo/Services/TerrainAPIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,12 @@ public async Task RefreshTokenAsync()
public async Task<GetProfilesResultModel> GetProfilesAsync()
{
await RefreshTokenAsync();
GetProfilesResultModel? getProfilesResultModel = new GetProfilesResultModel();
using (var httpClient = new HttpClient())
{
HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, membersAddress + "profiles");

httpRequest.Content = new StringContent("", Encoding.UTF8, "application/x-amz-json-1.1");
httpRequest.Headers.Add("authorization", _storageService?.AuthenticationResult?.IdToken);
httpRequest.Headers.Add("accept", "application/json, text/plain, */*");
string requestUri = $"{membersAddress}profiles";
var result = await SendRequest(HttpMethod.Get, requestUri);
var getProfilesResultModel = DeserializeObject<GetProfilesResultModel>(result);

var response = await httpClient.SendAsync(httpRequest);
var responseContent = response.Content.ReadAsStringAsync();
var result = responseContent.Result;
getProfilesResultModel = DeserializeObject<GetProfilesResultModel>(result);
return getProfilesResultModel;
}
return getProfilesResultModel;
}

public async Task<GetMembersResultModel?> GetMembersAsync(string selectedUnitId)
Expand Down