mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-20 09:35:47 +01:00
Simplified endpoint parameters
This commit is contained in:
parent
da04c431b6
commit
93600b74ed
@ -21,10 +21,10 @@ import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.webserver.RequestTarget;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -43,27 +43,16 @@ public class Identifiers {
|
||||
}
|
||||
|
||||
public UUID getServerUUID(RequestTarget target) throws BadRequestException {
|
||||
Optional<String> serverUUID = target.getParameter("serverUUID");
|
||||
if (serverUUID.isPresent()) {
|
||||
return getServerUUIDDirectly(serverUUID.get());
|
||||
} else {
|
||||
return getServerUUIDFromName(target); // Preferred
|
||||
}
|
||||
String serverIndentifier = target.getParameter("server")
|
||||
.orElseThrow(() -> new BadRequestException("'server' parameter was not defined."));
|
||||
|
||||
return UUIDUtility.parseFromString(serverIndentifier)
|
||||
.orElse(getServerUUIDFromName(serverIndentifier));
|
||||
}
|
||||
|
||||
private UUID getServerUUIDFromName(RequestTarget target) throws BadRequestException {
|
||||
String serverName = target.getParameter("serverName")
|
||||
.orElseThrow(() -> new BadRequestException("'serverName' parameter was not defined."));
|
||||
private UUID getServerUUIDFromName(String serverName) throws BadRequestException {
|
||||
return dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverName))
|
||||
.map(Server::getUuid)
|
||||
.orElseThrow(() -> new BadRequestException("'serverName' was not found in the database.: '" + serverName + "'"));
|
||||
}
|
||||
|
||||
private UUID getServerUUIDDirectly(String serverUUIDString) throws BadRequestException {
|
||||
try {
|
||||
return UUID.fromString(serverUUIDString);
|
||||
} catch (IllegalArgumentException malformedUUIDException) {
|
||||
throw new BadRequestException("'serverName' was not a valid UUID: " + malformedUUIDException.getMessage());
|
||||
}
|
||||
.orElseThrow(() -> new BadRequestException("Given 'server' was not found in the database: '" + serverName + "'"));
|
||||
}
|
||||
}
|
@ -50,6 +50,14 @@ public class UUIDUtility {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public static Optional<UUID> parseFromString(String uuidString) {
|
||||
try {
|
||||
return Optional.of(UUID.fromString(uuidString));
|
||||
} catch (IllegalArgumentException malformedUUIDException) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UUID of a player.
|
||||
*
|
||||
|
@ -1416,12 +1416,12 @@
|
||||
|
||||
<script>
|
||||
setLoadingText('Calculating values..');
|
||||
jsonRequest("../v1/serverOverview?serverName=${serverName}", loadServerOverviewValues);
|
||||
jsonRequest("../v1/onlineOverview?serverName=${serverName}", loadOnlineActivityOverviewValues);
|
||||
jsonRequest("../v1/sessionsOverview?serverName=${serverName}", loadSessionValues);
|
||||
jsonRequest("../v1/playerVersus?serverName=${serverName}", loadPvPPvEValues);
|
||||
jsonRequest("../v1/playerbaseOverview?serverName=${serverName}", loadPlayerbaseOverviewValues);
|
||||
jsonRequest("../v1/performanceOverview?serverName=${serverName}", loadPerformanceValues);
|
||||
jsonRequest("../v1/serverOverview?server=${serverName}", loadServerOverviewValues);
|
||||
jsonRequest("../v1/onlineOverview?server=${serverName}", loadOnlineActivityOverviewValues);
|
||||
jsonRequest("../v1/sessionsOverview?server=${serverName}", loadSessionValues);
|
||||
jsonRequest("../v1/playerVersus?server=${serverName}", loadPvPPvEValues);
|
||||
jsonRequest("../v1/playerbaseOverview?server=${serverName}", loadPlayerbaseOverviewValues);
|
||||
jsonRequest("../v1/performanceOverview?server=${serverName}", loadPerformanceValues);
|
||||
setLoadingText('Rendering graphs..');
|
||||
|
||||
// TODO remove
|
||||
@ -1518,7 +1518,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
jsonRequest("../v1/graph?type=performance&serverName=${serverName}", function (data, error) {
|
||||
jsonRequest("../v1/graph?type=performance&server=${serverName}", function (data, error) {
|
||||
if (data) {
|
||||
var series = {
|
||||
playersOnline: {
|
||||
@ -1582,7 +1582,7 @@
|
||||
$('#diskGraph').text("Failed to load graph data: " + error);
|
||||
}
|
||||
});
|
||||
jsonRequest("../v1/graph?type=ping&serverName=${serverName}", function (json, error) {
|
||||
jsonRequest("../v1/graph?type=ping&server=${serverName}", function (json, error) {
|
||||
if (json) {
|
||||
var series = {
|
||||
avgPing: {
|
||||
@ -1613,7 +1613,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
jsonRequest("../v1/graph?type=worldPie&serverName=${serverName}", function (json, error) {
|
||||
jsonRequest("../v1/graph?type=worldPie&server=${serverName}", function (json, error) {
|
||||
if (data) {
|
||||
var worldSeries = {name: 'World Playtime', colorByPoint: true, data: json.world_series};
|
||||
var gmSeries = json.gm_series;
|
||||
@ -1623,7 +1623,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
jsonRequest("../v1/graph?type=activity&serverName=${serverName}", function (json, error) {
|
||||
jsonRequest("../v1/graph?type=activity&server=${serverName}", function (json, error) {
|
||||
if (json) {
|
||||
activityPie('activityPie', {
|
||||
name: 'Players', colorByPoint: true, data: json.activity_pie_series
|
||||
@ -1635,7 +1635,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
jsonRequest("../v1/graph?type=geolocation&serverName=${serverName}", function (json, error) {
|
||||
jsonRequest("../v1/graph?type=geolocation&server=${serverName}", function (json, error) {
|
||||
if (json) {
|
||||
var geolocationSeries = {
|
||||
name: 'Players',
|
||||
@ -1662,7 +1662,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
jsonRequest("../v1/graph?type=uniqueAndNew&serverName=${serverName}", function (data, error) {
|
||||
jsonRequest("../v1/graph?type=uniqueAndNew&server=${serverName}", function (data, error) {
|
||||
if (data) {
|
||||
var uniquePlayers = {
|
||||
name: s.name.uniquePlayers, type: s.type.spline, tooltip: s.tooltip.zeroDecimals,
|
||||
@ -1678,7 +1678,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
jsonRequest("../v1/graph?type=serverCalendar&serverName=${serverName}", function (json, error) {
|
||||
jsonRequest("../v1/graph?type=serverCalendar&server=${serverName}", function (json, error) {
|
||||
if (json) {
|
||||
$('#calendar').text('');
|
||||
onlineActivityCalendar('#calendar', json.data, json.firstDay);
|
||||
@ -1689,7 +1689,7 @@
|
||||
|
||||
setLoadingText('Sorting players table..');
|
||||
|
||||
jsonRequest("../v1/players?serverName=${serverName}", function (playersTableJson, error) {
|
||||
jsonRequest("../v1/players?server=${serverName}", function (playersTableJson, error) {
|
||||
if (playersTableJson) {
|
||||
$('.player-table').DataTable({
|
||||
responsive: true,
|
||||
@ -1704,7 +1704,7 @@
|
||||
})
|
||||
}
|
||||
});
|
||||
jsonRequest("../v1/kills?serverName=${serverName}", loadPlayerKills);
|
||||
jsonRequest("../v1/kills?server=${serverName}", loadPlayerKills);
|
||||
|
||||
setLoadingText('Almost done..');
|
||||
var navButtons = document.getElementsByClassName("nav-button");
|
||||
@ -1723,7 +1723,7 @@
|
||||
x.style.opacity = "1";
|
||||
openFunc(slideIndex)();
|
||||
|
||||
jsonRequest("../v1/sessions?serverName=${serverName}", loadSessionAccordion);
|
||||
jsonRequest("../v1/sessions?server=${serverName}", loadSessionAccordion);
|
||||
|
||||
setLoadingText('Done.');
|
||||
setTimeout(function () {
|
||||
|
@ -19,12 +19,11 @@ Obtain all data in the database for a player.
|
||||
|
||||
Endpoints for tab specific number data, processed for display.
|
||||
|
||||
Required parameters: `serverName` or `serverUUID`
|
||||
Required parameters: `server`
|
||||
|
||||
Parameter|Expected value|Description
|
||||
--|--|--
|
||||
`serverName` | Name of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`serverUUID` | UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
|
||||
#### `GET /v1/serverOverview` - Server Overview tab
|
||||
|
||||
@ -36,51 +35,47 @@ Parameter|Expected value|Description
|
||||
|
||||
#### `GET /v1/playerbaseOverview` - Playerbase Overview tab.
|
||||
|
||||
### `GET /v1/players`
|
||||
#### `GET /v1/performanceOverview`
|
||||
|
||||
### `GET /v1/performanceOverview`
|
||||
### `GET /v1/players`
|
||||
|
||||
Obtain data for `/server` player list.
|
||||
|
||||
Required parameters: `serverName` or `serverUUID`
|
||||
Required parameters: `server`
|
||||
|
||||
Parameter|Expected value|Description
|
||||
--|--|--
|
||||
`serverName` | Name of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`serverUUID` | UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
|
||||
### `GET /v1/sessions`
|
||||
|
||||
Obtain data for `/server` session accordion. Returns configurable amount of sessions.
|
||||
|
||||
Required parameters: `serverName` or `serverUUID`
|
||||
Required parameters: `server`
|
||||
|
||||
Parameter|Expected value|Description
|
||||
--|--|--
|
||||
`serverName` | Name of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`serverUUID` | UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
|
||||
### `GET /v1/kills`
|
||||
|
||||
Obtain data for `/server` kills table. Returns 100 most recent kills.
|
||||
|
||||
Required parameters: `serverName` or `serverUUID`
|
||||
Required parameters: `server`
|
||||
|
||||
Parameter|Expected value|Description
|
||||
--|--|--
|
||||
`serverName` | Name of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`serverUUID` | UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
|
||||
### `GET /v1/graph`
|
||||
|
||||
Obtain data for graphs.
|
||||
|
||||
Required parameters: `serverName` or `serverUUID` and `type`
|
||||
Required parameters: `server` and `type`
|
||||
|
||||
Parameter|Expected value|Description
|
||||
--|--|--
|
||||
`serverName` | Name of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`serverUUID` | UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
|
||||
`type` | `performance`, `uniqueAndNew` | What kind of graph data should be given
|
||||
|
||||
Type | Description
|
||||
|
Loading…
Reference in New Issue
Block a user