/userProfile完成

This commit is contained in:
高子兴 2024-07-01 18:33:46 +08:00
parent 0f13440ab0
commit aa9e0d8804

View File

@ -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<UserHS> getUserProfile(@RequestParam String jwt) {
UserHS user = userService.getUserByUsername(JwtUtil.);
public ResponseEntity<UserProfileResponse> getUserProfile(@RequestParam String token) {
if (JwtUtil.isTokenValid(token)) {
UserHS user = userService.getUserByUsername(JwtUtil.extractUsername(token));
if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK);
} else {
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;
}