Skip to content

Commit

Permalink
still not deleting the user
Browse files Browse the repository at this point in the history
  • Loading branch information
xipi3000 committed Apr 2, 2024
1 parent 1c85fe4 commit f7c23f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import cat.udl.eps.softarch.demo.domain.User;
import cat.udl.eps.softarch.demo.exceptions.VolunteerFromDifferentShelter;
import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository;
import cat.udl.eps.softarch.demo.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeDelete;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.data.rest.core.annotation.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand All @@ -22,9 +21,11 @@ public class ShelterVolunteerEventHandler {
final Logger logger = LoggerFactory.getLogger(ShelterVolunteerEventHandler.class);

final ShelterVolunteerRepository shelterVolunteerRepository;
final UserRepository userRepository;

public ShelterVolunteerEventHandler(ShelterVolunteerRepository shelterVolunteerRepository) {
public ShelterVolunteerEventHandler(ShelterVolunteerRepository shelterVolunteerRepository,UserRepository userRepository) {
this.shelterVolunteerRepository = shelterVolunteerRepository;
this.userRepository = userRepository;
}

@HandleBeforeDelete
Expand All @@ -39,4 +40,11 @@ public void handleShelterVolunteerBeforeCreate(ShelterVolunteer volunteer) {

// Do something with the username, like associating it with the created user
}
@HandleAfterDelete
public void handleShelterVolunteerPostCreate(ShelterVolunteer volunteer) {
logger.info("After deleting: {}", volunteer.toString());

shelterVolunteerRepository.delete(volunteer);
userRepository.delete(volunteer);
}
}
11 changes: 8 additions & 3 deletions src/test/resources/features/KickUserFromShelter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ Feature: Kick ShelterVolunteer from Shelter
And There is a shelter volunteer with username "volunteer2" and password "pass" in the shelter "shelter2"

Scenario: Kick volunteer from shelter
And I can login with username "volunteer" and password "pass"
Then The response code is 200
Given I can login with username "volunteer" and password "pass"
And The response code is 200
And There is a shelter volunteer with username "volunteer1" and password "pass" in the shelter "shelter"
When I kick user "volunteer1" from shelter "shelter"
Then The response code is 200
And I cannot login with username "volunteer1" and password "pass"
And The response code is 200


Scenario: Kick volunteer from shelter as user

Expand All @@ -33,4 +36,6 @@ Feature: Kick ShelterVolunteer from Shelter
Then The response code is 200
And There is a shelter volunteer with username "volunteer" and password "pass" in the shelter "shelter"
When I kick user "volunteer2" from shelter "shelter"
Then The response code is 412
Then The response code is 412
And I can login with username "volunteer2" and password "pass"
And The response code is 401

0 comments on commit f7c23f0

Please sign in to comment.