0

I have a list "BonusHistory" with many objects, which I find by "bonus id"

List<BonusHistory> bonusHistories = bonusHistoryRepository.findAllByBonusIdAndDeletedAtIsNull(id);

Now I need to get from these list, objects which were created from (yesterday, last week, last month) till now. Maybe i need to change query in repository, idk. I am sorry if I explained incomprehensibly (i'm newbie in programming)

3 Answers3

1

You should have Data field like creationDate in BonusHistory and after it, you will be able to customize your query

Nick
  • 805
  • 5
  • 14
1

For a simple solution, you can just add you created_id clause in the method like:

List<BonusHistory> bonusHistories = bonusHistoryRepository.findAllByBonusIdAndDeletedAtIsNullAndCreatedIdAfter(id,your_date_range);

For a more sophisticated solution, you can write a native query and perform the date operation as mentioned here.

Sandeep Kumar
  • 2,397
  • 5
  • 30
  • 37
0

My objects already contains "created_at" fields