From aa9e0d8804486cb9b357951e2915ec17b9cf89c8 Mon Sep 17 00:00:00 2001 From: heshunme Date: Mon, 1 Jul 2024 18:33:46 +0800 Subject: [PATCH] =?UTF-8?q?/userProfile=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthenticationController.java | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java index b4f68cc..73d0590 100644 --- a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java +++ b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java @@ -12,6 +12,8 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; + @RestController class AuthenticationController { @@ -51,15 +53,25 @@ class AuthenticationController { } @GetMapping("/userProfile") - public ResponseEntity getUserProfile(@RequestParam String jwt) { - UserHS user = userService.getUserByUsername(JwtUtil.); - if (user != null) { - return new ResponseEntity<>(user, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } + public ResponseEntity getUserProfile(@RequestParam String token) { + if (JwtUtil.isTokenValid(token)) { + UserHS user = userService.getUserByUsername(JwtUtil.extractUsername(token)); + if (user != null) { + return new ResponseEntity<>(new UserProfileResponse( + user.getUsername(), + user.getNickname(), + user.getGender(), + user.getPhoneNumber(), + user.getEmail(), + user.getDepartment(), + user.getRole(), + user.getCreatedAt() + ), HttpStatus.OK); + } + } + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } } @@ -95,3 +107,17 @@ class LoginResponse { private String message; private String jwt; } + +@Getter +@Setter +@AllArgsConstructor +class UserProfileResponse { + private String username; + private String nickname; + private String gender; + private String phoneNumber; + private String email; + private String department; + private String role; + private LocalDateTime createdAt; +} \ No newline at end of file