diff --git a/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java b/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java index e0c1c7bfa8b3b801412a5fe6e3a217cf850d330c..a7e65b13ef013bd12eb821ddda841c84d85b69c4 100644 --- a/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java +++ b/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java @@ -41,7 +41,48 @@ public class AccountVerificationRequestRepository implements BaseRepository<Acco int totalPage = 0; while (totalPageRs.next()) { - totalPage = totalPageRs.getInt(1) / pageSize + 1; + totalPage = (int) Math.ceil((double) totalPageRs.getInt(1) / pageSize); + } + + List<AccountVerificationRequest> rows = new ArrayList<>(); + while (rs.next()) { + System.out.println(rs.getString(1)); + AccountVerificationRequest row = new AccountVerificationRequest(); + row.setId(rs.getInt(1)); + row.setUuid(rs.getString(2)); + row.setUserId(rs.getString(3)); + row.setStatus(rs.getString(4)); + row.setCreatedAt(rs.getString(5)); + row.setUpdatedAt(rs.getString(6)); + rows.add(row); + } + + GetAllResponse<AccountVerificationRequest> response = new GetAllResponse<>(); + response.setPage(page); + response.setTotalPage(totalPage); + response.setData(rows); + return response; + } + + public GetAllResponse<AccountVerificationRequest> getAll(int page, int pageSize, String status) + throws SQLException { + page = Math.max(page, 0); + pageSize = Math.max(pageSize, 1); + int offset = pageSize * (page - 1); + String query = "SELECT id, uuid, user_id, status, created_at, updated_at FROM account_verification_requests WHERE status = ? LIMIT ? OFFSET ?"; + String totalPageQuery = "SELECT COUNT(*) AS total_page FROM account_verification_requests"; + PreparedStatement ps = conn.prepareStatement(query); + PreparedStatement totalPagePs = conn.prepareStatement(totalPageQuery); + ps.setString(1, status); + ps.setInt(2, pageSize); + ps.setInt(3, offset); + + ResultSet rs = ps.executeQuery(); + ResultSet totalPageRs = totalPagePs.executeQuery(); + + int totalPage = 0; + while (totalPageRs.next()) { + totalPage = (int) Math.ceil((double) totalPageRs.getInt(1) / pageSize); } List<AccountVerificationRequest> rows = new ArrayList<>(); diff --git a/src/main/java/org/soapService/Services/AccountVerificationRequestService.java b/src/main/java/org/soapService/Services/AccountVerificationRequestService.java index ea3cbfd167a52c648e22a338c7ccd985e282e9d3..2c1605890d1685ccda058a686dd56c20ca640a95 100644 --- a/src/main/java/org/soapService/Services/AccountVerificationRequestService.java +++ b/src/main/java/org/soapService/Services/AccountVerificationRequestService.java @@ -19,7 +19,8 @@ public interface AccountVerificationRequestService { @WebMethod(operationName = "GetRequests") @RequestWrapper(className = "AccountVerificationRequestService.GetRequests") public ServiceResponse<GetAllResponse<AccountVerificationRequest>> getAccountVerificationRequests( - @WebParam(name = "page") Integer page, @WebParam(name = "pageSize") Integer pageSize) + @WebParam(name = "page") Integer page, @WebParam(name = "pageSize") Integer pageSize, + @WebParam(name = "status") String status) throws SOAPFaultException; @WebMethod(operationName = "CreateRequest") diff --git a/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java b/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java index fb0257598a5326a7eb325f4578f5584a7ea8288f..5cf4128c2748067a617ce23e1c4e30e70ff30d0f 100644 --- a/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java +++ b/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java @@ -21,7 +21,8 @@ public class AccountVerificationRequestServiceImpl extends BaseService implement private static AccountVerificationRequestValidation accountVerificationServiceValidation = new AccountVerificationRequestValidation(); public ServiceResponse<GetAllResponse<AccountVerificationRequest>> getAccountVerificationRequests(Integer page, - Integer pageSize) + Integer pageSize, + String status) throws SOAPFaultException { if (page == null) { page = 1; @@ -33,7 +34,11 @@ public class AccountVerificationRequestServiceImpl extends BaseService implement List<GetAllResponse<AccountVerificationRequest>> lru = new ArrayList<>(); try { - lru.add(accountVerificationRepository.getAll(page, pageSize)); + if (status == null) { + lru.add(accountVerificationRepository.getAll(page, pageSize)); + } else { + lru.add(accountVerificationRepository.getAll(page, pageSize, status)); + } } catch (Exception e) { System.out.println(e.getMessage()); new RequestException(HTTPStatusCode.INTERNAL_SERVER_ERROR.getCodeStr(),