Skip to content

Commit c549525

Browse files
committed
Add actionlog query methods
1 parent c2ed958 commit c549525

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ version = '0.1-SNAPSHOT'
1212

1313
java {
1414
toolchain {
15-
languageVersion = JavaLanguageVersion.of(8)
15+
languageVersion = JavaLanguageVersion.of(11)
1616
}
17+
18+
sourceCompatibility = '1.8'
19+
targetCompatibility = '1.8'
20+
1721
withJavadocJar()
1822
withSourcesJar()
1923
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package net.luckperms.rest.model;
27+
28+
import java.util.Collection;
29+
30+
public class ActionPage extends AbstractModel {
31+
private final Collection<Action> entries;
32+
private final int overallSize;
33+
34+
public ActionPage(Collection<Action> entries, int overallSize) {
35+
this.entries = entries;
36+
this.overallSize = overallSize;
37+
}
38+
39+
public Collection<Action> entries() {
40+
return this.entries;
41+
}
42+
43+
public int overallSize() {
44+
return this.overallSize;
45+
}
46+
}

src/main/java/net/luckperms/rest/service/ActionService.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,53 @@
2626
package net.luckperms.rest.service;
2727

2828
import net.luckperms.rest.model.Action;
29+
import net.luckperms.rest.model.ActionPage;
2930
import retrofit2.Call;
3031
import retrofit2.http.Body;
32+
import retrofit2.http.GET;
3133
import retrofit2.http.POST;
34+
import retrofit2.http.Query;
35+
36+
import java.util.UUID;
3237

3338
public interface ActionService {
3439

40+
@GET("/action")
41+
Call<ActionPage> query();
42+
43+
@GET("/action")
44+
Call<ActionPage> query(@Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
45+
46+
@GET("/action")
47+
Call<ActionPage> querySource(@Query("source") UUID source);
48+
49+
@GET("/action")
50+
Call<ActionPage> querySource(@Query("source") UUID source, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
51+
52+
@GET("/action")
53+
Call<ActionPage> queryTargetUser(@Query("user") UUID user);
54+
55+
@GET("/action")
56+
Call<ActionPage> queryTargetUser(@Query("user") UUID user, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
57+
58+
@GET("/action")
59+
Call<ActionPage> queryTargetGroup(@Query("group") String group);
60+
61+
@GET("/action")
62+
Call<ActionPage> queryTargetGroup(@Query("group") String group, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
63+
64+
@GET("/action")
65+
Call<ActionPage> queryTargetTrack(@Query("track") String track);
66+
67+
@GET("/action")
68+
Call<ActionPage> queryTargetTrack(@Query("track") String track, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
69+
70+
@GET("/action")
71+
Call<ActionPage> querySearch(@Query("search") String search);
72+
73+
@GET("/action")
74+
Call<ActionPage> querySearch(@Query("search") String search, @Query("pageSize") int pageSize, @Query("pageNumber") int pageNumber);
75+
3576
@POST("/action")
3677
Call<Void> submit(@Body Action action);
3778

src/main/java/net/luckperms/rest/service/UserService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public interface UserService {
9090
@DELETE("/user/{uniqueId}")
9191
Call<Void> delete(@Path("uniqueId") UUID uniqueId);
9292

93+
@DELETE("/user/{uniqueId}")
94+
Call<Void> delete(@Path("uniqueId") UUID uniqueId, @Query("playerDataOnly") boolean playerDataOnly);
95+
9396
@GET("/user/{uniqueId}/nodes")
9497
Call<List<Node>> nodes(@Path("uniqueId") UUID uniqueId);
9598

src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@
2727

2828
import net.luckperms.rest.LuckPermsRestClient;
2929
import net.luckperms.rest.model.Action;
30+
import net.luckperms.rest.model.ActionPage;
3031
import org.junit.jupiter.api.Test;
32+
import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
3133
import retrofit2.Response;
3234

3335
import java.io.IOException;
36+
import java.util.ArrayList;
37+
import java.util.List;
3438
import java.util.UUID;
39+
import java.util.stream.Collectors;
3540

41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3643
import static org.junit.jupiter.api.Assertions.assertTrue;
3744

3845
public class ActionServiceTest extends AbstractIntegrationTest {
@@ -50,4 +57,65 @@ public void testSubmit() throws IOException {
5057
assertTrue(resp.isSuccessful());
5158
}
5259

60+
@Test
61+
public void testQuery() throws IOException {
62+
LuckPermsRestClient client = createClient();
63+
64+
long time = System.currentTimeMillis() / 1000L;
65+
Action.Source source = new Action.Source(UUID.randomUUID(), randomName());
66+
67+
Action testUserAction = new Action(time, source,
68+
new Action.Target(UUID.randomUUID(), randomName(), Action.Target.Type.USER),
69+
"test user action"
70+
);
71+
Action testGroupAction = new Action(time + 1, source,
72+
new Action.Target(null, randomName(), Action.Target.Type.GROUP),
73+
"test group action"
74+
);
75+
Action testTrackAction = new Action(time + 2, source,
76+
new Action.Target(null, randomName(), Action.Target.Type.TRACK),
77+
"test track action"
78+
);
79+
80+
client.actions().submit(testUserAction).execute();
81+
client.actions().submit(testGroupAction).execute();
82+
client.actions().submit(testTrackAction).execute();
83+
84+
// test simple query all
85+
Response<ActionPage> resp1 = client.actions().query().execute();
86+
assertTrue(resp1.isSuccessful());
87+
ActionPage body1 = resp1.body();
88+
assertNotNull(body1);
89+
assertEquals(3, body1.overallSize());
90+
assertEquals(ImmutableList.of(testTrackAction, testGroupAction, testUserAction), body1.entries());
91+
92+
for (int i = 0; i < 20; i++) {
93+
Action testAction = new Action(
94+
time + 100 - i,
95+
new Action.Source(UUID.randomUUID(), randomName()),
96+
new Action.Target(null, randomName(), Action.Target.Type.GROUP),
97+
"test " + i
98+
);
99+
client.actions().submit(testAction).execute();
100+
}
101+
102+
// test pagination
103+
Response<ActionPage> resp2 = client.actions().query(5, 2).execute();
104+
assertTrue(resp2.isSuccessful());
105+
ActionPage body2 = resp2.body();
106+
assertNotNull(body2);
107+
assertEquals(23, body2.overallSize());
108+
assertEquals(
109+
ImmutableList.of("test 5", "test 6", "test 7", "test 8", "test 9"),
110+
body2.entries().stream().map(Action::description).collect(Collectors.toList())
111+
);
112+
113+
// test query by source
114+
Response<ActionPage> resp3 = client.actions().querySource(source.uniqueId(), 5, 1).execute();
115+
assertTrue(resp3.isSuccessful());
116+
ActionPage body3 = resp3.body();
117+
assertNotNull(body3);
118+
assertEquals(3, body3.overallSize());
119+
}
120+
53121
}

0 commit comments

Comments
 (0)