Added del-event endpoint

This commit is contained in:
Marc Beyer 2021-11-28 18:20:17 +01:00
parent 540d3a130f
commit bfbcd5c44b
2 changed files with 22 additions and 0 deletions

View File

@ -1,8 +1,10 @@
package com.vpr.server;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import javax.transaction.Transactional;
import java.util.List;
// This will be AUTO IMPLEMENTED by Spring into a Bean called eventRepository
@ -29,4 +31,17 @@ public interface EventRepository extends CrudRepository<Event, Integer> {
"WHERE ue.user_id = ?1",
nativeQuery = true)
Object[] findAllByUserId(long id);
@Modifying
@Transactional
@Query(value = "DELETE ue FROM user_event ue WHERE ue.event_id = ?1",
nativeQuery = true)
void deleteUserEventsById(long id);
@Modifying
@Transactional
@Query(value = "DELETE e FROM event e WHERE e.id = ?1",
nativeQuery = true)
void deleteById(long id);
}

View File

@ -110,6 +110,13 @@ public class MainController {
return "Saved";
}
@PostMapping(path="/del-event")
public @ResponseBody String addEvent ( @RequestParam Integer eventId ) {
eventRepository.deleteUserEventsById(Long.valueOf(eventId));
eventRepository.deleteById(Long.valueOf(eventId));
return "Deleted";
}
// GET-request at /all-users
// returns JSON-data
@GetMapping(path="/all-users")