I have a List of Travels in my db. I just want to show the travels with not expired date in frontend. I have tried findByTravelDateAfter, but it show me only the date after the date, that I gave as Input. How can I do if we are for example 2021-10-12 and I give as Input 2021-10-22 and I want to display all the travels befor and after 2021-10-22 but only after 2021-10-12.
Can someone give me Idea how to do this ?
Here is my entity:
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.Date;
@Getter
@Setter
@Entity
public class ProposeTravel {
@Id
@GeneratedValue
public Long travelId;
public String startCity;
public String endCity;
public Date travelDate;
public String travelTime;
public Long numberOfPlace;
public double travelPrice;
public String startPoint;
public String carDetails;
public String baggageDetails;
@Column(nullable = false)
public String emailDriver;
@NotBlank
@NotNull
public String drivingLicenceNr;
public Long userId;
public ProposeTravel() {
super();
// TODO Auto-generated constructor stub
}
public ProposeTravel(Long travelId, String startCity, String endCity, Date travelDate, String travelTime,
Long numberOfPlace, double travelPrice, String startPoint, String carDetails, String baggageDetails,
String emailDriver, Long userId) {
super();
this.travelId = travelId;
this.startCity = startCity;
this.endCity = endCity;
this.travelDate = travelDate;
this.travelTime = travelTime;
this.numberOfPlace = numberOfPlace;
this.travelPrice = travelPrice;
this.startPoint = startPoint;
this.carDetails = carDetails;
this.baggageDetails = baggageDetails;
this.emailDriver = emailDriver;
this.userId = userId;
}
}
My repository:
import cm.camtougo.apicamtougo.TravelModule.entities.ProposeTravel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.sql.Date;
import java.util.List;
@Repository
public interface ProposeTravelRepository extends JpaRepository<ProposeTravel, Long> {
ProposeTravel findByTravelId(Long travelId);
public List<ProposeTravel> findByUserId(Long userId);
List<ProposeTravel> findByStartCityAndTravelDateAfterAndEndCity(String startCity, Date travelDate, String endCity);
List<ProposeTravel> findByStartCityAndTravelDateAndEndCity(String startCity, Date travelDate, String endCity);
List<ProposeTravel> findByStartCityAndTravelDateAfter(String startCity, Date travelDate);
List<ProposeTravel> findByEndCityAndTravelDateAfter(String endCity, Date travelDate);
List<ProposeTravel> findByStartCityAndEndCityAndTravelDateAfter(String startCity, String endCity, Date travelDate);
}