Fixed user/del endpoint
This commit is contained in:
parent
f22bdf3040
commit
710b661b0d
@ -144,6 +144,9 @@ public class UserController {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
return new ResponseEntity<>("User nicht in der Datenbank vorhanden", HttpStatus.BAD_REQUEST);
|
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);
|
userRepository.delete(user);
|
||||||
return new ResponseEntity<>("", HttpStatus.OK);
|
return new ResponseEntity<>("", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,17 @@ public class UserDAOImplementation implements UserDAO {
|
|||||||
public List<User> getAllUser() {
|
public List<User> getAllUser() {
|
||||||
return manager.createNamedQuery("getAllUser", User.class).getResultList();
|
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 {
|
public interface UserDAO {
|
||||||
List<User> getAllUser();
|
List<User> getAllUser();
|
||||||
|
|
||||||
|
boolean deleteAllUserEvents(long userId);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,21 @@ import java.util.List;
|
|||||||
// @Entity creates a table out of this class with Hibernate
|
// @Entity creates a table out of this class with Hibernate
|
||||||
@Entity(name = "User")
|
@Entity(name = "User")
|
||||||
@Table(name = "user")
|
@Table(name = "user")
|
||||||
|
|
||||||
|
@SqlResultSetMapping(name="deleteResult", columns = {
|
||||||
|
@ColumnResult(name = "count")
|
||||||
|
})
|
||||||
|
|
||||||
@NamedNativeQueries({
|
@NamedNativeQueries({
|
||||||
@NamedNativeQuery(
|
@NamedNativeQuery(
|
||||||
name = "getAllUser",
|
name = "getAllUser",
|
||||||
query = "SELECT * FROM user",
|
query = "SELECT * FROM user",
|
||||||
resultClass = User.class
|
resultClass = User.class
|
||||||
|
),
|
||||||
|
@NamedNativeQuery(
|
||||||
|
name = "deleteAllUserEvents",
|
||||||
|
query = "DELETE FROM user_event WHERE user_id = :userId",
|
||||||
|
resultSetMapping = "deleteResult"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
public class User {
|
public class User {
|
||||||
|
Loading…
Reference in New Issue
Block a user