Skip to content

Commit

Permalink
Merge branch 'ZelKami-reorder-lists'
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jan 25, 2024
2 parents af934ce + 2780fbf commit 93ef1f0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

## In development

* Add method to reorder lists. Thanks @ZelKami! #131

## 6.11.2
_2022-09-01_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class ListItemRank {

public List<Long> rank;

/**
* Can also be used to reorder lists by passing list IDs.
*/
@Nonnull
public static ListItemRank from(List<Long> rank) {
ListItemRank listItemRank = new ListItemRank();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/uwetrottmann/trakt5/services/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ Call<Void> deleteList(
@Path("id") String id
);

/**
* <b>OAuth Required</b>
*
* <p> Reorder all custom lists by sending the updated rank of list ids.
*/
@POST("users/{username}/lists/reorder")
Call<ListReorderResponse> reorderLists(
@Path("username") UserSlug userSlug,
@Body ListItemRank rank
);

/**
* <b>OAuth Optional</b>
*
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/uwetrottmann/trakt5/services/UsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ public void test_reorderListItems() throws IOException {
assertThat(response.updated).isEqualTo(entries.size());
}

@Test
public void test_reorderLists() throws IOException {
List<TraktList> lists = executeCall(getTrakt().users().lists(UserSlug.ME));

// reverse order
List<Long> newRank = new ArrayList<>();
for (int i = lists.size() - 1; i >= 0; i--) {
newRank.add(lists.get(i).ids.trakt.longValue());
}

ListReorderResponse response = executeCall(getTrakt().users().reorderLists(
UserSlug.ME,
ListItemRank.from(newRank)
));
assertThat(response.updated).isEqualTo(lists.size());
}

@Ignore("Following is now a VIP feature")
@Test
public void test_unfollowAndFollow() throws InterruptedException, IOException {
Expand Down

0 comments on commit 93ef1f0

Please sign in to comment.