Skip to content

Commit

Permalink
Find tenants without apartments
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceZ916 committed May 19, 2023
1 parent 1761743 commit 48df74d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/moveOutAndAssignNewOwner").hasAuthority("ROLE_MANAGER")
.antMatchers("/getFlatmates").hasAuthority("ROLE_MANAGER")
.antMatchers("/findApartmentsWithVacancy").hasAuthority("ROLE_MANAGER")
.antMatchers("/getTenantsWithoutApartments").hasAuthority("ROLE_MANAGER")
.antMatchers("/reservation").hasAnyAuthority("ROLE_TENANT","ROLE_MANAGER")
.antMatchers("/reservation/*").hasAnyAuthority("ROLE_TENANT", "ROLE_MANAGER")
.antMatchers("/reservations").hasAnyAuthority("ROLE_TENANT", "ROLE_MANAGER")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ public Set<String> getFlatmates(String username) {

@GetMapping("findApartmentsWithVacancy")
public List<String> findApartmentsWithVacancy() {return moveService.findApartmentsWithVacancy(); }

@GetMapping("getTenantsWithoutApartments")
public List<String> getTenantsWithoutApartments() {return moveService.getTenantsWithoutApartments();}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public interface UserRepository extends JpaRepository<User, String> {
List<User> getOccupants(
@Param("apartment_number") String apartmentNumber);

@Query ("SELECT u FROM User u where u.apartmentNumber=NULL")
List<User> getTenantsWithoutApartments();

}

5 changes: 5 additions & 0 deletions src/main/java/com/backend/management/service/MoveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public List<String> findApartmentsWithVacancy(){
return apartments.stream().map(Apartment::getApartmentId).collect(Collectors.toSet()).stream().sorted().collect(Collectors.toList());
}

public List<String> getTenantsWithoutApartments() {
List<User> tenant = userRepository.getTenantsWithoutApartments();
return tenant.stream().map(User::getUsername).collect(Collectors.toSet()).stream().sorted().collect(Collectors.toList());
}

private void move(String username, String newApartmentNumber, String newOwnerUsername) {
Optional<User> userOptional = userRepository.findById(username);
if (userOptional.isEmpty()) {
Expand Down

0 comments on commit 48df74d

Please sign in to comment.