I have created an integer of type String for the query of dates of a demand
List<Demand> findAllDemandsBydates(String starDate, String endDate) throws ParseException;
here is where I implement my code and say it is a string and I give it a date format to cast and this is my way of doing this query
@SuppressWarnings({ "unchecked", "unused" })
@Override
public List<Demand> findAllDemandsBydates(String starDate, String endDate) throws ParseException {
// TODO Auto-generated method stub
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sDate = format.parse(starDate);
Date enDate = format.parse(endDate);
return entityManager
.createQuery("FROM Demand AS c WHERE c.id BETWEEN :requesteddate AND :agreeddate ")
.setParameter("requesteddate", starDate).setParameter("agreeddate", endDate).getResultList();
}
* in the code of my controller I check if the list is empty oh no for me to return does not contain or if it contains a list within those dates *
@CrossOrigin("http://localhost:8080")
@ApiOperation("obtencion de demandas por fechas ")
@GetMapping("demandsbydates/{starDate}/{endDate}")
public ResponseEntity<List<Demand>>
demandsbydates
(
@PathVariable("starDate")String starDate ,
@PathVariable("endDate") String endDate
) throws ParseException {
List<Demand> list = userService.findAllDemandsBydates(starDate, endDate);
if (list.isEmpty()) {
return new ResponseEntity<List<Demand>>(HttpStatus.NO_CONTENT);
// You many decide to return HttpStatus.NOT_FOUND
}
return new ResponseEntity<List<Demand>>(list, HttpStatus.OK);
}
* the dates that go from beginning to end are to consult them and give me a guide of where I'm going until where I end *
here I present data from my database that I have for the range of dates that I want to consult
This is how I enter the paramenters in my swagger to consult them
* and finally this is how I have my entity class *
@Entity
@Table(name = "demand")
public class Demand {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name = "comentary", length = 500)
private String comments;
@Column(name = "description", length = 300)
private String descriptions;
@ManyToOne
@JoinColumn(name = "id_responsible", referencedColumnName = "id")
private Person persons;
@ManyToOne
@JoinColumn(name = "id_demand_state", referencedColumnName = "id")
private DemandState demandstate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "register_at")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/mm/yyyy hh:mm:ss")
@CreatedDate
private Date registerat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "requested_date")
private Date requesteddate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "agreed_date")
private Date agreeddate;}
//getters and Setters
in short, I can not get the query because I do not have any content and when I want to see the logs, nothing comes out