diff --git a/build.gradle b/build.gradle index 7dc9866..2daa6a4 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,12 @@ version = '0.1-SNAPSHOT' java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(11) } + + sourceCompatibility = '1.8' + targetCompatibility = '1.8' + withJavadocJar() withSourcesJar() } diff --git a/src/main/java/net/luckperms/rest/model/ActionPage.java b/src/main/java/net/luckperms/rest/model/ActionPage.java new file mode 100644 index 0000000..ea3adb8 --- /dev/null +++ b/src/main/java/net/luckperms/rest/model/ActionPage.java @@ -0,0 +1,46 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.luckperms.rest.model; + +import java.util.Collection; + +public class ActionPage extends AbstractModel { + private final Collection entries; + private final int overallSize; + + public ActionPage(Collection entries, int overallSize) { + this.entries = entries; + this.overallSize = overallSize; + } + + public Collection entries() { + return this.entries; + } + + public int overallSize() { + return this.overallSize; + } +} diff --git a/src/main/java/net/luckperms/rest/service/ActionService.java b/src/main/java/net/luckperms/rest/service/ActionService.java index 7f8843b..dd3456a 100644 --- a/src/main/java/net/luckperms/rest/service/ActionService.java +++ b/src/main/java/net/luckperms/rest/service/ActionService.java @@ -26,12 +26,53 @@ package net.luckperms.rest.service; import net.luckperms.rest.model.Action; +import net.luckperms.rest.model.ActionPage; import retrofit2.Call; import retrofit2.http.Body; +import retrofit2.http.GET; import retrofit2.http.POST; +import retrofit2.http.Query; + +import java.util.UUID; public interface ActionService { + @GET("/action") + Call query(); + + @GET("/action") + Call query(@Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + + @GET("/action") + Call querySource(@Query("source") UUID source); + + @GET("/action") + Call querySource(@Query("source") UUID source, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + + @GET("/action") + Call queryTargetUser(@Query("user") UUID user); + + @GET("/action") + Call queryTargetUser(@Query("user") UUID user, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + + @GET("/action") + Call queryTargetGroup(@Query("group") String group); + + @GET("/action") + Call queryTargetGroup(@Query("group") String group, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + + @GET("/action") + Call queryTargetTrack(@Query("track") String track); + + @GET("/action") + Call queryTargetTrack(@Query("track") String track, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + + @GET("/action") + Call querySearch(@Query("search") String search); + + @GET("/action") + Call querySearch(@Query("search") String search, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber); + @POST("/action") Call submit(@Body Action action); diff --git a/src/main/java/net/luckperms/rest/service/UserService.java b/src/main/java/net/luckperms/rest/service/UserService.java index e6a6153..03b80c0 100644 --- a/src/main/java/net/luckperms/rest/service/UserService.java +++ b/src/main/java/net/luckperms/rest/service/UserService.java @@ -90,6 +90,9 @@ public interface UserService { @DELETE("/user/{uniqueId}") Call delete(@Path("uniqueId") UUID uniqueId); + @DELETE("/user/{uniqueId}") + Call delete(@Path("uniqueId") UUID uniqueId, @Query("playerDataOnly") boolean playerDataOnly); + @GET("/user/{uniqueId}/nodes") Call> nodes(@Path("uniqueId") UUID uniqueId); diff --git a/src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java b/src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java index 2002655..63b22e7 100644 --- a/src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java +++ b/src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java @@ -27,12 +27,19 @@ import net.luckperms.rest.LuckPermsRestClient; import net.luckperms.rest.model.Action; +import net.luckperms.rest.model.ActionPage; import org.junit.jupiter.api.Test; +import org.testcontainers.shaded.com.google.common.collect.ImmutableList; import retrofit2.Response; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class ActionServiceTest extends AbstractIntegrationTest { @@ -50,4 +57,65 @@ public void testSubmit() throws IOException { assertTrue(resp.isSuccessful()); } + @Test + public void testQuery() throws IOException { + LuckPermsRestClient client = createClient(); + + long time = System.currentTimeMillis() / 1000L; + Action.Source source = new Action.Source(UUID.randomUUID(), randomName()); + + Action testUserAction = new Action(time, source, + new Action.Target(UUID.randomUUID(), randomName(), Action.Target.Type.USER), + "test user action" + ); + Action testGroupAction = new Action(time + 1, source, + new Action.Target(null, randomName(), Action.Target.Type.GROUP), + "test group action" + ); + Action testTrackAction = new Action(time + 2, source, + new Action.Target(null, randomName(), Action.Target.Type.TRACK), + "test track action" + ); + + client.actions().submit(testUserAction).execute(); + client.actions().submit(testGroupAction).execute(); + client.actions().submit(testTrackAction).execute(); + + // test simple query all + Response resp1 = client.actions().query().execute(); + assertTrue(resp1.isSuccessful()); + ActionPage body1 = resp1.body(); + assertNotNull(body1); + assertEquals(3, body1.overallSize()); + assertEquals(ImmutableList.of(testTrackAction, testGroupAction, testUserAction), body1.entries()); + + for (int i = 0; i < 20; i++) { + Action testAction = new Action( + time + 100 - i, + new Action.Source(UUID.randomUUID(), randomName()), + new Action.Target(null, randomName(), Action.Target.Type.GROUP), + "test " + i + ); + client.actions().submit(testAction).execute(); + } + + // test pagination + Response resp2 = client.actions().query(5, 2).execute(); + assertTrue(resp2.isSuccessful()); + ActionPage body2 = resp2.body(); + assertNotNull(body2); + assertEquals(23, body2.overallSize()); + assertEquals( + ImmutableList.of("test 5", "test 6", "test 7", "test 8", "test 9"), + body2.entries().stream().map(Action::description).collect(Collectors.toList()) + ); + + // test query by source + Response resp3 = client.actions().querySource(source.uniqueId(), 5, 1).execute(); + assertTrue(resp3.isSuccessful()); + ActionPage body3 = resp3.body(); + assertNotNull(body3); + assertEquals(3, body3.overallSize()); + } + }