Added new native queries
This commit is contained in:
parent
2cec62c453
commit
768c57a234
@ -15,6 +15,7 @@ public class Event {
|
|||||||
private String name;
|
private String name;
|
||||||
private Integer priority;
|
private Integer priority;
|
||||||
private boolean isFullDay;
|
private boolean isFullDay;
|
||||||
|
private boolean isPrivate;
|
||||||
private Time start;
|
private Time start;
|
||||||
private Time end;
|
private Time end;
|
||||||
|
|
||||||
@ -57,6 +58,14 @@ public class Event {
|
|||||||
isFullDay = fullDay;
|
isFullDay = fullDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPrivate() {
|
||||||
|
return isPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivate(boolean aPrivate) {
|
||||||
|
isPrivate = aPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
public Time getStart() {
|
public Time getStart() {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,17 @@ public interface EventRepository extends CrudRepository<Event, Integer> {
|
|||||||
"INNER JOIN user_event ue " +
|
"INNER JOIN user_event ue " +
|
||||||
"ON e.id = ue.event_id " +
|
"ON e.id = ue.event_id " +
|
||||||
"INNER JOIN user u " +
|
"INNER JOIN user u " +
|
||||||
"ON ue.user_id = u.id",
|
"ON ue.user_id = u.id " +
|
||||||
|
"WHERE u.id = ?1 " +
|
||||||
|
"OR e.is_private = 0",
|
||||||
nativeQuery = true)
|
nativeQuery = true)
|
||||||
List<Object> test();
|
Object[] findAllVisibleByUserId(long id);
|
||||||
|
|
||||||
|
@Query(value = "SELECT * " +
|
||||||
|
"FROM event e " +
|
||||||
|
"INNER JOIN user_event ue " +
|
||||||
|
"ON e.id = ue.event_id " +
|
||||||
|
"WHERE ue.user_id = ?1",
|
||||||
|
nativeQuery = true)
|
||||||
|
Object[] findAllByUserId(long id);
|
||||||
}
|
}
|
@ -47,26 +47,21 @@ public class MainController {
|
|||||||
// GET-request at /all-users
|
// GET-request at /all-users
|
||||||
// returns JSON-data
|
// returns JSON-data
|
||||||
@GetMapping(path="/all-users")
|
@GetMapping(path="/all-users")
|
||||||
public @ResponseBody Iterable<com.vpr.server.User> getAllUsers() {
|
public @ResponseBody Object[] getAllUsers() {
|
||||||
return userRepository.findAll();
|
return userRepository.findAllUsernames();
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST-request at /users-by-name
|
// POST-request at /all-events
|
||||||
// returns JSON-data
|
// returns JSON-data
|
||||||
@PostMapping(path="/users-by-name")
|
@PostMapping(path="/all-events")
|
||||||
public @ResponseBody Iterable<com.vpr.server.User> getUsersByName(@RequestParam String name) {
|
public @ResponseBody Object[] getAllEvents(@RequestParam long userId) {
|
||||||
return userRepository.findByName(name);
|
return eventRepository.findAllVisibleByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET-request at /all-events
|
// GET-request at /all-events
|
||||||
// returns JSON-data
|
// returns JSON-data
|
||||||
@GetMapping(path="/all-events")
|
@GetMapping(path="/all-events-test")
|
||||||
public @ResponseBody Iterable<com.vpr.server.Event> getAllEvents() {
|
public @ResponseBody Iterable<com.vpr.server.Event> getAllEventsTest() {
|
||||||
return eventRepository.findAll();
|
return eventRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path="/test")
|
|
||||||
public @ResponseBody Iterable<Object> getTest() {
|
|
||||||
return eventRepository.test();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.vpr.server;
|
package com.vpr.server;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -8,5 +9,10 @@ import java.util.List;
|
|||||||
// CRUD refers Create, Read, Update, Delete
|
// CRUD refers Create, Read, Update, Delete
|
||||||
|
|
||||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||||
List<User> findByName(String name);
|
|
||||||
|
@Query(value = "SELECT u.id, u.name, u.forename " +
|
||||||
|
"FROM user u",
|
||||||
|
nativeQuery = true)
|
||||||
|
Object[] findAllUsernames();
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user