Skip to content

Commit

Permalink
feat: paginação
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdev01 committed Nov 21, 2024
1 parent 7aef279 commit e9c3fa8
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 15 deletions.
20 changes: 19 additions & 1 deletion src/main/java/io/github/jpdev/asaassdk/doc/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.github.jpdev.asaassdk.rest.pix.qrcode.PixQrCode;
import io.github.jpdev.asaassdk.rest.pix.qrcode.decode.PixDecodedQrCode;
import io.github.jpdev.asaassdk.rest.pix.transaction.PixTransaction;
import io.github.jpdev.asaassdk.rest.pix.transaction.PixTransactionReader;
import io.github.jpdev.asaassdk.rest.subscription.Subscription;
import io.github.jpdev.asaassdk.rest.subscription.SubscriptionCycle;
import io.github.jpdev.asaassdk.rest.transfer.Transfer;
Expand All @@ -42,13 +43,30 @@
import io.github.jpdev.asaassdk.utils.Money;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class Examples {

public static void main(String[] args) {
Asaas.initSandbox(Secret.getAccessToken()); // Initialize the SDK with your access token
transfer();
paging();
}

private static void paging() {
PixTransactionReader reader = PixTransaction.reader();
ResourceSet<PixTransaction> page0 = reader.read();
ResourceSet<PixTransaction> page1 = reader.nextPage().read();

ArrayList<PixTransaction> pixTransactions = new ArrayList<>();
pixTransactions.addAll(page0.getData());
pixTransactions.addAll(page1.getData());

for (PixTransaction pixTransaction : pixTransactions) {
System.out.println(pixTransaction.getId().equals("6b212665-4963-460d-9005-3805281790a4"));
}
}

private static void pixTransaction() {
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/io/github/jpdev/asaassdk/rest/action/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

public abstract class Reader<T> {

public Integer limit;
public Long offset;
public int limit = 10;
public long offset = 0;

public List<FilterVO> activeFilters;

Expand Down Expand Up @@ -70,9 +70,16 @@ public void addFilter(String propertyName, String filterName) {
));
}

public Reader<T> nextPage() {
offset += limit;
return this;
}

private String buildFullPath() {
try {
String path = getResourceUrl();
path = path.concat(fillPagination());

if (activeFilters == null || activeFilters.isEmpty()) return path;

String pathParams = "";
Expand All @@ -98,18 +105,6 @@ private String buildFullPath() {
}
}

if (limit != null) {
pathParams = concatDelimiterFilter(pathParams)
.concat("limit=")
.concat(limit.toString());
}

if (offset != null) {
pathParams = concatDelimiterFilter(pathParams)
.concat("offset=")
.concat(offset.toString());
}

return path.concat(pathParams);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException |
IllegalAccessException unexpectedException) {
Expand All @@ -121,4 +116,17 @@ private String concatDelimiterFilter(String currentFilter) {
if (currentFilter.isEmpty()) return currentFilter.concat("?");
return currentFilter.concat("&");
}

private String fillPagination() {
String pathParams = "";
pathParams = concatDelimiterFilter(pathParams)
.concat("limit=")
.concat(String.valueOf(limit));

pathParams = concatDelimiterFilter(pathParams)
.concat("offset=")
.concat(String.valueOf(offset));

return pathParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,114 @@ public PixTransaction() {

}

public String getId() {
return id;
}

public Object getTransferId() {
return transferId;
}

public String getEndToEndIdentifier() {
return endToEndIdentifier;
}

public Object getFinality() {
return finality;
}

public BigDecimal getValue() {
return value;
}

public BigDecimal getChangeValue() {
return changeValue;
}

public BigDecimal getRefundedValue() {
return refundedValue;
}

public Date getDateCreated() {
return dateCreated;
}

public Date getEffectiveDate() {
return effectiveDate;
}

public Date getScheduledDate() {
return scheduledDate;
}

public PixTransactionStatus getStatus() {
return status;
}

public PixTransactionType getType() {
return type;
}

public PixTransactionOriginType getOriginType() {
return originType;
}

public String getConciliationIdentifier() {
return conciliationIdentifier;
}

public String getDescription() {
return description;
}

public String getTransactionReceiptUrl() {
return transactionReceiptUrl;
}

public int getChargedFeeValue() {
return chargedFeeValue;
}

public boolean isCanBeRefunded() {
return canBeRefunded;
}

public String getRefundDisabledReason() {
return refundDisabledReason;
}

public String getRefusalReason() {
return refusalReason;
}

public boolean isCanBeCanceled() {
return canBeCanceled;
}

public Object getOriginalTransaction() {
return originalTransaction;
}

public PixTransactionExternalAccount getExternalAccount() {
return externalAccount;
}

public Object getQrCode() {
return qrCode;
}

public Object getPayment() {
return payment;
}

public String getAddressKey() {
return addressKey;
}

public PixAddressKeyType getAddressKeyType() {
return addressKeyType;
}

public static PixTransactionReader reader() {
return new PixTransactionReader();
}
Expand Down

0 comments on commit e9c3fa8

Please sign in to comment.