I have a db with various events, and a corresponding entity:
@NoArgsConstructor
@Data
@Table(name="Event")
public class Event {
@Id
private String id;
private String source;
private String action;
private Date timestamp;
private String data;
}
And a controller that takes a QueryDSLPredicate and parameters:
@GetMapping("/events")
public List<Event> getEvents(@QuerydslPredicate(root = Event.class) Predicate predicate,
@RequestParam(name = "id", required = false) String id,
@RequestParam(name = "source", required = false) String source,
@RequestParam(name = "action", required = false) String action,
@RequestParam(name = "startTimestamp", required = false) String startTimestamp,
@RequestParam(name = "endTimestamp", required = false) String endTimestamp,
@RequestHeader(required = false) String requestId) {
return StreamSupport.stream(eventRepository.findAll(predicate).spliterator(), false).collect(Collectors.toList());
This works great for sending specified parameters like this
http://localhost:8080/events?source=testSource&action=testAction
But how can I handle the date ranges by sending in a starttime and endtime, and pulling all events between those times? I'm new to querydsl/spring (in fact I haven't written java since college) and can't seem to find a great example on how to do this.