Skip to content

Commit

Permalink
return role in personal info
Browse files Browse the repository at this point in the history
  • Loading branch information
DmyMi committed Nov 22, 2024
1 parent a382d75 commit 1b30dd9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace OutOfSchool.BusinessLogic.Models;

public class ShortUserDto : BaseUserDto
{
[DataType(DataType.EmailAddress)]
public string UserName { get; set; }

public string Role { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ public static class CommunicationConstants
public const string BlockRegionAdmin = "regionadmin/block/";

public const string ReinviteRegionAdmin = "regionadmin/reinvite/";

public const int BufferSize = 1024;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OutOfSchool.Common.Communication.ICommunication;
Expand Down Expand Up @@ -94,22 +93,19 @@ public virtual async Task<Either<TError, T>> SendRequest<T, TError>(

requestMessage.Method = HttpMethodService.GetHttpMethodType(request);

logger.LogDebug("Sending request to {RequestMessage}", requestMessage);

var response = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead)
using var response = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead)
.ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
// Error response should be small, but still no need to waste time as default handler is ignoring it
var errorBody = errorHandler == null ? null : await response.Content.ReadAsStringAsync();
var errorBody = errorHandler == null ? null : await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var error = new CommunicationError(response.StatusCode)
{
Body = errorBody,
};
logger.LogDebug("Error body: {Body}", errorBody);
logger.LogError("Remote service error: {StatusCode}", response.StatusCode);
return await HandleErrorAsync(error, "Remote service error", errorHandler);
return await HandleErrorAsync(error, "Remote service error", errorHandler).ConfigureAwait(false);
}

await using var stream = await response.EnsureSuccessStatusCode().Content.ReadAsStreamAsync()
Expand All @@ -120,12 +116,12 @@ public virtual async Task<Either<TError, T>> SendRequest<T, TError>(
catch (HttpRequestException ex)
{
logger.LogError(ex, "Networking error");
return await HandleExceptionAsync(ex, errorHandler);
return await HandleExceptionAsync(ex, errorHandler).ConfigureAwait(false);
}
catch (Exception ex)
{
logger.LogError(ex, "Unknown error");
return await HandleExceptionAsync(ex, errorHandler);
return await HandleExceptionAsync(ex, errorHandler).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ public async Task<IActionResult> GetPersonalInfo()
{
var info = currentUserService.IsInRole(Role.Parent)
? await parentService.GetPersonalInfoByUserId(currentUserService.UserId)
: null;
: await userService.GetById(currentUserService.UserId);

return Ok(info ?? (await userService.GetById(currentUserService.UserId)));
if (string.IsNullOrWhiteSpace(info.Role))
{
info.Role = currentUserService.UserRole;
}
return Ok(info);
}


Expand Down

0 comments on commit 1b30dd9

Please sign in to comment.