adding pagination for transaction controller

This commit is contained in:
2025-07-24 23:51:31 +02:00
parent 75b1564faa
commit 5bbff964e2
5 changed files with 13547 additions and 4978 deletions

View File

@@ -7,6 +7,8 @@ import net.kaczmarzyk.spring.data.jpa.web.annotation.Or;
import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec;
import net.kaczmarzyk.spring.data.jpa.web.annotation.Conjunction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import zw.qantra.tm.domain.services.TransactionService;
import zw.qantra.tm.domain.models.Transaction;
@@ -16,7 +18,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import zw.qantra.tm.utils.LogUtils;
import java.util.List;
import java.util.UUID;
@RestController
@@ -28,7 +29,7 @@ public class TransactonController {
private final TransactionService transactionService;
@GetMapping
public ResponseEntity<List<Transaction>> getAll(
public ResponseEntity<Page<Transaction>> getAll(
@Conjunction(value = {
@Or({
@Spec(path = "status", spec = Equal.class),
@@ -54,9 +55,9 @@ public class TransactonController {
})
}, and = {
@Spec(path = "type", spec = Equal.class),
@Spec(path = "userId", spec = Equal.class),
}) Specification<Transaction> specification) {
return ResponseEntity.ok(transactionService.findAll(specification));
@Spec(path = "userId", defaultVal = "null", spec = Equal.class),
}) Specification<Transaction> specification, Pageable pageable) {
return ResponseEntity.ok(transactionService.findAll(specification, pageable));
}
@GetMapping("/{id}")

View File

@@ -10,6 +10,8 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
@@ -182,8 +184,8 @@ public class TransactionService {
return transaction;
}
public List<Transaction> findAll(Specification<Transaction> spec) {
return transactionRepository.findAll(spec, Sort.by(Sort.Direction.ASC, "createdAt"));
public Page<Transaction> findAll(Specification<Transaction> spec, Pageable pageable) {
return transactionRepository.findAll(spec, pageable);
}
public Transaction save(Transaction transaction){

View File

@@ -63,7 +63,7 @@ public class EcocashRemotePaymentProcessor implements TransactionProcessorInterf
.action("PAYMENT")
.sandbox(true)
.paymentProcessorLabel("ECOCASH")
.responseUrl("https://peakapi.stewardpay.co.zw")
.responseUrl("https://peakapi.qantra.co.zw")
.build();
HttpHeaders headers = new HttpHeaders();