Skip to content

Commit

Permalink
v1.1.0: add totalItems and totalPages to the Page object.
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Aug 18, 2019
1 parent a9a9c0a commit 1919f61
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

## v1.1.0 (2019-08-18)
Add `totalItems` and `totalPages` to the `Page` object.

## v1.0.0 (2019-08-04)
Initial release.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
```groovy
dependencies {
/* ... */
implementation 'org.jraf:klibqonto:1.0.0'
implementation 'org.jraf:klibqonto:1.1.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {

allprojects {
group = 'org.jraf'
version = '1.0.0'
version = '1.1.0'

repositories.addRepos()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import org.jraf.klibqonto.model.pagination.Pagination
internal object HasApiMetaConverter {
fun <MODEL> convert(hasApiMeta: HasApiMeta, list: List<MODEL>): Page<MODEL> {
return PageImpl(
list = list,
items = list,
nextPagination = hasApiMeta.meta.next_page?.let { Pagination(it, hasApiMeta.meta.per_page) },
previousPagination = hasApiMeta.meta.prev_page?.let { Pagination(it, hasApiMeta.meta.per_page) }
previousPagination = hasApiMeta.meta.prev_page?.let { Pagination(it, hasApiMeta.meta.per_page) },
totalPages = hasApiMeta.meta.total_pages,
totalItems = hasApiMeta.meta.total_count
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import org.jraf.klibqonto.model.pagination.Page
import org.jraf.klibqonto.model.pagination.Pagination

internal data class PageImpl<out T>(
override val list: List<T>,
override val items: List<T>,
override val nextPagination: Pagination?,
override val previousPagination: Pagination?
override val previousPagination: Pagination?,
override val totalPages: Int,
override val totalItems: Int
) : Page<T>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,32 @@

package org.jraf.klibqonto.model.pagination

/**
* A page of results.
*/
interface Page<out T> {
val list: List<T>
/**
* The actual items of the results.
*/
val items: List<T>

/**
* Next [Pagination] (if any), that can be used to retrieve the next page.
*/
val nextPagination: Pagination?

/**
* Previous [Pagination] (if any), that can be used to retrieve the previous page.
*/
val previousPagination: Pagination?

/**
* Total number of pages (depends on the number of items per page).
*/
val totalPages: Int

/**
* Total number of items.
*/
val totalItems: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ private void main() {
// Get first page of memberships
System.out.println("\n\nMemberships:");
Page<Membership> membershipList = client.getMemberships().getMembershipList(new Pagination());
System.out.println(asLines(membershipList.getList()));
System.out.println(asLines(membershipList.getItems()));

// Get first page of labels
System.out.println("\n\nLabels:");
Page<Label> labels = client.getLabels().getLabelList(new Pagination());
System.out.println(asLines(labels.getList()));
System.out.println(asLines(labels.getItems()));

// Get first 2 pages of transactions
System.out.println("\n\nTransactions:");
Expand Down Expand Up @@ -119,7 +119,7 @@ private List<Transaction> getTransactionList(Organization organization) {
QontoClient.Transactions.SortOrder.DESCENDING,
new Pagination(0, 10)
);
ArrayList<Transaction> list = new ArrayList<>(firstPage.getList());
ArrayList<Transaction> list = new ArrayList<>(firstPage.getItems());

// 2/ Get next page of transactions (if any)
Pagination nextPagination = firstPage.getNextPagination();
Expand All @@ -133,7 +133,7 @@ private List<Transaction> getTransactionList(Organization organization) {
QontoClient.Transactions.SortOrder.DESCENDING,
nextPagination
);
list.addAll(secondPage.getList());
list.addAll(secondPage.getItems());
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ private void main() throws Exception {
// Get first page of memberships
System.out.println("\n\nMemberships:");
Page<Membership> membershipList = client.getMemberships().getMembershipList(new Pagination()).get();
System.out.println(asLines(membershipList.getList()));
System.out.println(asLines(membershipList.getItems()));

// Get first page of labels
System.out.println("\n\nLabels:");
Page<Label> labels = client.getLabels().getLabelList(new Pagination()).get();
System.out.println(asLines(labels.getList()));
System.out.println(asLines(labels.getItems()));

// Get first 2 pages of transactions
System.out.println("\n\nTransactions:");
Expand Down Expand Up @@ -119,7 +119,7 @@ private List<Transaction> getTransactionList(Organization organization) throws E
QontoClient.Transactions.SortOrder.DESCENDING,
new Pagination(0, 10)
).get();
ArrayList<Transaction> list = new ArrayList<>(firstPage.getList());
ArrayList<Transaction> list = new ArrayList<>(firstPage.getItems());

// 2/ Get next page of transactions (if any)
Pagination nextPagination = firstPage.getNextPagination();
Expand All @@ -133,7 +133,7 @@ private List<Transaction> getTransactionList(Organization organization) throws E
QontoClient.Transactions.SortOrder.DESCENDING,
nextPagination
).get();
list.addAll(secondPage.getList());
list.addAll(secondPage.getItems());
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ object FlowSample {
private suspend fun getMembershipList() {
client.memberships.getMembershipList()
.collect {
println(it.list.joinToString("\n"))
println(it.items.joinToString("\n"))
}
}

private suspend fun getLabelList() {
client.labels.getLabelList()
.collect {
println(it.list.joinToString("\n"))
println(it.items.joinToString("\n"))
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ object FlowSample {
)
} ?: emptyFlow())
.map { nextPage ->
firstPage.list + nextPage.list
firstPage.items + nextPage.items
}
}
.onEach { transactionList ->
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/kotlin/org/jraf/klibqonto/sample/Sample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ object Sample {
// Get first page of memberships
println("\n\nMemberships:")
val membershipList = client.memberships.getMembershipList()
println(membershipList.list.joinToString("\n"))
println(membershipList.items.joinToString("\n"))

// Get first page of labels
println("\n\nLabels:")
val labels = client.labels.getLabelList()
println(labels.list.joinToString("\n"))
println(labels.items.joinToString("\n"))

// Get first 2 pages of transactions
println("\n\nTransactions:")
Expand All @@ -115,7 +115,7 @@ object Sample {
sortField = QontoClient.Transactions.SortField.UPDATED_DATE,
pagination = Pagination(itemsPerPage = 10)
)
val list = firstPage.list.toMutableList()
val list = firstPage.items.toMutableList()

// 2/ Get next page of transactions (if any)
firstPage.nextPagination?.let { nextPagination ->
Expand All @@ -126,7 +126,7 @@ object Sample {
sortField = QontoClient.Transactions.SortField.UPDATED_DATE,
pagination = nextPagination
)
list += secondPage.list
list += secondPage.items
}
return list
}
Expand Down

0 comments on commit 1919f61

Please sign in to comment.