Skip to content
Merged
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
17 changes: 7 additions & 10 deletions exercise.wwwapi/Endpoints/UserEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static async Task<IResult> GetUsers(IRepository<User> userRepository, st

results = results.Where(u =>
{
var first = u.FirstName?.ToLowerInvariant() ?? "";
var first = u.FirstName?.ToLowerInvariant() ?? "";
var last = u.LastName?.ToLowerInvariant() ?? "";
var full = (first + " " + last).Trim();

Expand All @@ -73,9 +73,8 @@ private static async Task<IResult> GetUsers(IRepository<User> userRepository, st




var userData = new UsersSuccessDTO
{
{
Users = results.Select(user => authorizedAsTeacher
? new UserDTO(user, PrivilegeLevel.Teacher) //if teacher loads students, also load notes for students.
: new UserDTO(user, PrivilegeLevel.Student)).ToList() //if teacher loads students, also load notes for students.
Expand Down Expand Up @@ -140,7 +139,7 @@ private static async Task<IResult> Register(PostUserDTO request, IRepository<Use
return Results.Conflict(new Payload<object>
{
Status = "fail",
Data = "User already exists"
Data = "User already exists"
});
}

Expand Down Expand Up @@ -186,7 +185,7 @@ private static async Task<IResult> Register(PostUserDTO request, IRepository<Use
}
}
};


return Results.Ok(responseObject);
}
Expand All @@ -197,7 +196,7 @@ private static async Task<IResult> Login(LoginRequestDTO request, IRepository<Us
IConfigurationSettings configurationSettings)
{
var response = await userRepository.GetWithIncludes(x => x.Where(u => u.Email == request.Email)); // uses where-statement to filter data before fetching
if (response.Count == 0)
if (response.Count == 0)
{
return Results.BadRequest(new Payload<object>
{
Expand Down Expand Up @@ -379,12 +378,10 @@ private static string CreateToken(User user, IConfigurationSettings configuratio
new(ClaimTypes.Sid, user.Id.ToString()),
new(ClaimTypes.Name, user.Username),
new(ClaimTypes.Email, user.Email),
new(ClaimTypes.Role, user.Role.ToString()),
new("FirstName", user.FirstName),
new("LastName", user.LastName)
new(ClaimTypes.Role, user.Role.ToString())
};

var tokenKey = Environment.GetEnvironmentVariable(Globals.EnvironmentEnvVariable) == "Staging"
var tokenKey = Environment.GetEnvironmentVariable(Globals.EnvironmentEnvVariable) == "Staging"
? Globals.TestTokenKey
: Globals.TokenKey;
var rawToken = configurationSettings.GetValue(tokenKey);
Expand Down