Fixed user/del endpoint
This commit is contained in:
parent
f22bdf3040
commit
710b661b0d
@ -144,6 +144,9 @@ public class UserController {
|
||||
if (user == null) {
|
||||
return new ResponseEntity<>("User nicht in der Datenbank vorhanden", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if(userDAO.deleteAllUserEvents(user.getId())){
|
||||
return new ResponseEntity<>("User konnte nicht gelöscht werden", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
userRepository.delete(user);
|
||||
return new ResponseEntity<>("", HttpStatus.OK);
|
||||
}
|
||||
|
@ -21,4 +21,17 @@ public class UserDAOImplementation implements UserDAO {
|
||||
public List<User> getAllUser() {
|
||||
return manager.createNamedQuery("getAllUser", User.class).getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllUserEvents(long userId) {
|
||||
try {
|
||||
manager.createNamedQuery("deleteAllUserEvents", User.class)
|
||||
.setParameter("userId", userId)
|
||||
.executeUpdate();
|
||||
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,6 @@ import java.util.List;
|
||||
|
||||
public interface UserDAO {
|
||||
List<User> getAllUser();
|
||||
|
||||
boolean deleteAllUserEvents(long userId);
|
||||
}
|
||||
|
@ -6,12 +6,22 @@ import java.util.List;
|
||||
// @Entity creates a table out of this class with Hibernate
|
||||
@Entity(name = "User")
|
||||
@Table(name = "user")
|
||||
|
||||
@SqlResultSetMapping(name="deleteResult", columns = {
|
||||
@ColumnResult(name = "count")
|
||||
})
|
||||
|
||||
@NamedNativeQueries({
|
||||
@NamedNativeQuery(
|
||||
name = "getAllUser",
|
||||
query = "SELECT * FROM user",
|
||||
resultClass = User.class
|
||||
)
|
||||
@NamedNativeQuery(
|
||||
name = "getAllUser",
|
||||
query = "SELECT * FROM user",
|
||||
resultClass = User.class
|
||||
),
|
||||
@NamedNativeQuery(
|
||||
name = "deleteAllUserEvents",
|
||||
query = "DELETE FROM user_event WHERE user_id = :userId",
|
||||
resultSetMapping = "deleteResult"
|
||||
)
|
||||
})
|
||||
public class User {
|
||||
// Generate the primary key
|
||||
|
Loading…
Reference in New Issue
Block a user