From 0f7a890e441924514fafbf7f9c0a1112d809ae79 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 1 Aug 2024 06:55:42 +0100 Subject: [PATCH] return the user DTO instead of the full user --- .../fascinated/controller/RootController.java | 2 +- .../fascinated/controller/UserController.java | 5 +-- .../java/cc/fascinated/model/user/User.java | 9 +++++ .../cc/fascinated/model/user/UserDTO.java | 33 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 API/src/main/java/cc/fascinated/model/user/UserDTO.java diff --git a/API/src/main/java/cc/fascinated/controller/RootController.java b/API/src/main/java/cc/fascinated/controller/RootController.java index 25a1f4b..7fccbda 100644 --- a/API/src/main/java/cc/fascinated/controller/RootController.java +++ b/API/src/main/java/cc/fascinated/controller/RootController.java @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping(value = "/") public class RootController { /** - * A GET mapping to show the + * A GET mapping to show the welcome message. */ @ResponseBody @GetMapping(value = "/") diff --git a/API/src/main/java/cc/fascinated/controller/UserController.java b/API/src/main/java/cc/fascinated/controller/UserController.java index 9fbf861..e2f9f5b 100644 --- a/API/src/main/java/cc/fascinated/controller/UserController.java +++ b/API/src/main/java/cc/fascinated/controller/UserController.java @@ -2,6 +2,7 @@ package cc.fascinated.controller; import cc.fascinated.exception.impl.BadRequestException; import cc.fascinated.model.user.User; +import cc.fascinated.model.user.UserDTO; import cc.fascinated.services.UserService; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +34,7 @@ public class UserController { */ @ResponseBody @GetMapping(value = "/{id}") - public ResponseEntity getUser(@PathVariable String id) { - return ResponseEntity.ok(userService.getUser(id)); + public ResponseEntity getUser(@PathVariable String id) { + return ResponseEntity.ok(userService.getUser(id).getAsDTO()); } } diff --git a/API/src/main/java/cc/fascinated/model/user/User.java b/API/src/main/java/cc/fascinated/model/user/User.java index 776f343..192d062 100644 --- a/API/src/main/java/cc/fascinated/model/user/User.java +++ b/API/src/main/java/cc/fascinated/model/user/User.java @@ -43,4 +43,13 @@ public class User { *

*/ public boolean hasLoggedIn; + + /** + * Converts the User object to a UserDTO object. + * + * @return The UserDTO object. + */ + public UserDTO getAsDTO() { + return new UserDTO(id, username, steamId); + } } diff --git a/API/src/main/java/cc/fascinated/model/user/UserDTO.java b/API/src/main/java/cc/fascinated/model/user/UserDTO.java new file mode 100644 index 0000000..55dc862 --- /dev/null +++ b/API/src/main/java/cc/fascinated/model/user/UserDTO.java @@ -0,0 +1,33 @@ +package cc.fascinated.model.user; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.data.annotation.Id; + +import java.util.UUID; + +/** + * @author Fascinated (fascinated7) + */ +@AllArgsConstructor +@Getter +public class UserDTO { + /** + * The ID of the user. + */ + @Id + private final UUID id; + + /** + * The username of the user. + *

+ * Usually their Steam name. + *

+ */ + private String username; + + /** + * The ID of the users steam profile. + */ + private String steamId; +}