Skip to content

Commit 9895931

Browse files
committed
feat(api): Update player management API and enhance player entity structure
1 parent 951984f commit 9895931

8 files changed

Lines changed: 397 additions & 13 deletions

File tree

backend/src/main/java/net/onelitefeather/otis/OtisApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@OpenAPIDefinition(
1313
info = @Info(
1414
title = "Otis API",
15-
version = "0.0.1",
15+
version = "1.0.1",
1616
description = "Simple user management system",
1717
license = @License(name = "Apache-2.0"),
1818
contact = @Contact(url = "https://onelitefeather.net", name = "Management", email = "admin@onelitefeather.net")

backend/src/main/java/net/onelitefeather/otis/controller/OtisRequestsController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public OtisRequestsController(OtisPlayerRepository repository) {
6060
public HttpResponse<OtisPlayerDTO> add(@Valid OtisPlayerDTO playerDTO) {
6161
LOGGER.info("Adding new player: {}", playerDTO);
6262
OtisPlayer otisPlayer = OtisPlayer.toEntity(playerDTO);
63-
OtisPlayer saved = repository.update(otisPlayer);
63+
OtisPlayer saved = repository.save(otisPlayer);
6464
LOGGER.info("Saved player: {}", saved);
6565
return HttpResponse.ok(saved.toDto());
6666
}
@@ -90,7 +90,7 @@ public HttpResponse<OtisPlayerDTO> add(@Valid OtisPlayerDTO playerDTO) {
9090
@Validated
9191
@Get("/byId/{owner}")
9292
public HttpResponse<OtisPlayerDTO> getById(@Valid UUID owner) {
93-
OtisPlayer entity = this.repository.findById(owner).orElse(null);
93+
OtisPlayer entity = this.repository.findByPlayerUuid(owner).orElse(null);
9494
if (entity == null) {
9595
return HttpResponse.notFound();
9696
}

backend/src/main/java/net/onelitefeather/otis/database/entity/OtisPlayer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222

2323
@Serdeable
2424
@Entity
25-
@Table(name = "otis_player", indexes = @Index(columnList = "uuid"))
25+
@Table(name = "otis_player", indexes = {
26+
@Index(name = "idx_player_uuid", columnList = "playerUuid"),
27+
@Index(name = "idx_player_name", columnList = "playerName")
28+
})
2629
public class OtisPlayer {
2730

2831
@Id
2932
@GeneratedValue(strategy = GenerationType.UUID)
3033
private UUID uuid;
3134

35+
private UUID playerUuid;
36+
3237
private String playerName;
3338

3439
private long firstJoin;
@@ -45,6 +50,7 @@ public class OtisPlayer {
4550
public static OtisPlayer toEntity(OtisPlayerDTO otisPlayerDTO) {
4651
return new OtisPlayer(
4752
otisPlayerDTO.uuid(),
53+
otisPlayerDTO.playerUuid(),
4854
otisPlayerDTO.playerName(),
4955
otisPlayerDTO.firstJoin(),
5056
otisPlayerDTO.lastJoin(),
@@ -64,14 +70,17 @@ public OtisPlayer() {
6470
* Creates a new instance of the {@link OtisPlayer} with all required values.
6571
*
6672
* @param uuid the unique identifier from the player
73+
* @param playerUuid the unique player UUID from mojang
6774
* @param playerName the name from the player
6875
* @param firstJoin the first join from the player
6976
* @param lastJoin the last join from the player
7077
* @param profileTexture the profile texture from the player
7178
* @param locale the locale from the player
7279
*/
73-
public OtisPlayer(UUID uuid, String playerName, long firstJoin, long lastJoin, Map<String, Object> profileTexture, Locale locale) {
80+
public OtisPlayer(UUID uuid, UUID playerUuid, String playerName, long firstJoin, long lastJoin,
81+
Map<String, Object> profileTexture, Locale locale) {
7482
this.uuid = uuid;
83+
this.playerUuid = playerUuid;
7584
this.playerName = playerName;
7685
this.firstJoin = firstJoin;
7786
this.lastJoin = lastJoin;
@@ -118,6 +127,7 @@ public Locale getLocale() {
118127
public OtisPlayerDTO toDto() {
119128
return new OtisPlayerDTO(
120129
this.uuid,
130+
this.playerUuid,
121131
this.playerName,
122132
this.firstJoin,
123133
this.lastJoin,

backend/src/main/java/net/onelitefeather/otis/database/repository/OtisPlayerRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ public interface OtisPlayerRepository extends PageableRepository<OtisPlayer, UUI
1414

1515
@Query("SELECT player FROM OtisPlayer player WHERE player.playerName = :name")
1616
Optional<OtisPlayer> findByName(@Param("name") String name);
17+
18+
@Query("SELECT player FROM OtisPlayer player WHERE player.playerUuid = :uuid")
19+
Optional<OtisPlayer> findByPlayerUuid(@Param("uuid") UUID uuid);
1720
}

backend/src/main/java/net/onelitefeather/otis/dto/OtisPlayerDTO.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.micronaut.core.annotation.Introspected;
44
import io.micronaut.serde.annotation.Serdeable;
5+
import io.swagger.v3.oas.annotations.media.Schema;
56
import jakarta.validation.constraints.Pattern;
67
import jakarta.validation.constraints.Size;
78

@@ -12,13 +13,33 @@
1213
@Serdeable
1314
@Introspected
1415
public record OtisPlayerDTO(
16+
@Schema(description = "Unique identifier for the player in the Otis system.",
17+
example = "123e4567-e89b-12d3-a456-426614174000", type = "string", format = "uuid")
1518
UUID uuid,
19+
@Schema(description = "Unique identifier for the player from mojang.",
20+
example = "123e4567-e89b-12d3-a456-426614174001", type = "string", format = "uuid"
21+
)
22+
UUID playerUuid,
1623
@Size(min = 3, max = 16, message = "Username must be between 3 and 16 characters.")
1724
@Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "Username can only contain alphanumeric characters and underscores.")
25+
@Schema(description = "The player's username.",
26+
example = "Player123", type = "string", format = "username",
27+
minimum = "3", maximum = "16", pattern = "^[a-zA-Z0-9_]+$"
28+
)
1829
String playerName,
30+
@Schema(description = "The timestamp of the player's first join in milliseconds since epoch.",
31+
example = "1633072800000", type = "integer", format = "int64"
32+
)
1933
long firstJoin,
34+
@Schema(description = "The timestamp of the player's last join in milliseconds since epoch.",
35+
example = "1633072800000", type = "integer", format = "int64"
36+
)
2037
long lastJoin,
38+
@Schema(description = "A map containing the player's profile textures, such as skin and cape.")
2139
Map<String, Object> profileTextures,
40+
@Schema(description = "The locale of the player, used for localization purposes.",
41+
example = "en-US", type = "string", format = "locale"
42+
)
2243
Locale locale
2344
) {
2445
}

java-client/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies {
1818
openApiGenerate {
1919
generatorName.set("java")
2020
library.set("native")
21-
inputSpec.set("$projectDir/specs/otis-api-0.0.1.yml")
21+
inputSpec.set("$projectDir/specs/otis-api-1.0.1.yml")
2222
outputDir.set(outDir.get().asFile.absolutePath)
2323
apiPackage.set("net.onelitefeather.otis.client.api")
2424
invokerPackage.set("net.onelitefeather.otis.client.invoker")

0 commit comments

Comments
 (0)