Skip to content

Commit

Permalink
New condition added
Browse files Browse the repository at this point in the history
  • Loading branch information
xipi3000 committed Jun 5, 2024
1 parent 9565c5b commit 408d281
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import cat.udl.eps.softarch.demo.domain.Shelter;
import cat.udl.eps.softarch.demo.domain.ShelterVolunteer;
import cat.udl.eps.softarch.demo.domain.User;
import cat.udl.eps.softarch.demo.exceptions.VolunteerCannotKickHimself;
import cat.udl.eps.softarch.demo.exceptions.VolunteerFromDifferentShelter;
import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository;
import cat.udl.eps.softarch.demo.repository.UserRepository;
Expand Down Expand Up @@ -29,12 +30,14 @@ public ShelterVolunteerEventHandler(ShelterVolunteerRepository shelterVolunteerR
}

@HandleBeforeDelete
public void handleShelterVolunteerBeforeDelete(ShelterVolunteer volunteer) {
public void handleShelterVolunteerBeforeDelete(ShelterVolunteer volunteer) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
ShelterVolunteer requestVolunteer = shelterVolunteerRepository.findById(username).orElse(null);
if(requestVolunteer!=null && Objects.equals(requestVolunteer.getUserShelter().getId(), volunteer.getUserShelter().getId())) {
logger.info("Volunteer {} is deleting volunteer {}.", username, volunteer.getUsername());
if(requestVolunteer!=null && Objects.equals(requestVolunteer.getUserShelter().getId(), volunteer.getUserShelter().getId()) ) {
if(!username.equals(volunteer.getUsername()))
logger.info("Volunteer {} is deleting volunteer {}.", username, volunteer.getUsername());
else throw new VolunteerCannotKickHimself();
}
else throw new VolunteerFromDifferentShelter();

Expand Down

0 comments on commit 408d281

Please sign in to comment.