Skip to content

Commit

Permalink
Merge pull request #31 from theImmortalCoders/issue-30
Browse files Browse the repository at this point in the history
feat: #30 all users endpoint
  • Loading branch information
marcinbator authored Oct 22, 2024
2 parents 7a3f710 + 83b504c commit d779a6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
7 changes: 3 additions & 4 deletions rag-2-backend/Controllers/AdministrationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ public UserResponse GetUserDetails([Required] int userId)
return administrationService.GetUserDetails(UserUtil.GetPrincipalEmail(User), userId);
}

/// <summary>Get students list by study year cycle (Admin, Teacher)</summary>
/// <summary>Get all users list (Admin, Teacher)</summary>
[HttpGet("students")]
[Authorize(Roles = "Admin, Teacher")]
public List<UserResponse> GetStudents([FromQuery] [Required] int studyCycleYearA,
[FromQuery] [Required] int studyCycleYearB)
public List<UserResponse> GetStudents()
{
return administrationService.GetStudents(studyCycleYearA, studyCycleYearB);
return administrationService.GetStudents();
}
}
6 changes: 1 addition & 5 deletions rag-2-backend/Services/AdministrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ public UserResponse GetUserDetails(string principalEmail, int userId)
return UserMapper.MapDetails(userUtil.GetUserByIdOrThrow(userId));
}

public List<UserResponse> GetStudents(int studyCycleYearA, int studyCycleYearB)
public List<UserResponse> GetStudents()
{
return context.Users
.Where(u => u.Role == Role.Student &&
u.StudyCycleYearA == studyCycleYearA &&
u.StudyCycleYearB == studyCycleYearB)
.OrderBy(u => u.Email)
.Select(u => UserMapper.Map(u))
.ToList();
}
Expand Down
10 changes: 5 additions & 5 deletions rag-2-backend/Test/AdministrationServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ public void ShouldGetStudents()
{
var response = new UserResponse
{
Id = 2,
Email = "email2@stud.prz.edu.pl",
Id = 1,
Email = "email@prz.edu.pl",
Name = "John",
Role = Role.Student,
Role = Role.Admin,
StudyCycleYearA = 2022,
StudyCycleYearB = 2023
};

Assert.Equal(
JsonConvert.SerializeObject(new List<UserResponse> { response }),
JsonConvert.SerializeObject(_administrationService.GetStudents(2022, 2023))
JsonConvert.SerializeObject(response),
JsonConvert.SerializeObject(_administrationService.GetStudents()[0])
);
}
}

0 comments on commit d779a6d

Please sign in to comment.