-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Transaction): implement sensorChaincodeTransaction API with opti…
…onal filters
- Loading branch information
1 parent
1d35915
commit 4d377b6
Showing
8 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...oc/blocc/dashboard/transaction/specification/SensorChaincodeTransactionSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package uk.ac.ic.doc.blocc.dashboard.transaction.specification; | ||
|
||
import jakarta.persistence.criteria.Predicate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import uk.ac.ic.doc.blocc.dashboard.transaction.model.SensorChaincodeTransaction; | ||
|
||
public class SensorChaincodeTransactionSpecification { | ||
|
||
public static Specification<SensorChaincodeTransaction> filterByParameters(Integer containerNum, | ||
Long sinceTimestamp, Long untilTimestamp) { | ||
return (root, query, criteriaBuilder) -> { | ||
List<Predicate> predicates = new ArrayList<>(); | ||
|
||
if (containerNum != null) { | ||
predicates.add(criteriaBuilder.equal(root.get("key").get("containerNum"), containerNum)); | ||
} | ||
if (sinceTimestamp != null) { | ||
predicates.add( | ||
criteriaBuilder.greaterThanOrEqualTo(root.get("createdTimestamp"), sinceTimestamp)); | ||
} | ||
if (untilTimestamp != null) { | ||
predicates.add( | ||
criteriaBuilder.lessThanOrEqualTo(root.get("createdTimestamp"), untilTimestamp)); | ||
} | ||
|
||
query.orderBy(criteriaBuilder.asc(root.get("createdTimestamp"))); | ||
|
||
return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters