I have this model :
public class Post {
private Long expiryDate; // A timestamp
}
And repository as :
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
Page<Post> findAllByOrderByExpiryDateDesc(Pageable pageable);
}
What I want to do:
When the expiry date has passed (post expired, current date greater than expiry date) => orderBy desc
Else, When the expiry date not yet passed (post not expired) => orderBy asc
Example: if I have the expiry date list: Monday, Tuesday, Wednesday, Thursday and Friday
and that today is Wednesday (Wednesday not yet expired).
Wanted result:
- Wednesday
- Thursday
- Friday
- Tuesday
- Monday
Someone got any solution please?