1414
1515@ Tag (
1616 name = "User" ,
17- description = "회원 정보, 아기 등록 및 선택 등 사용자 관련 API"
17+ description = "회원 정보, 사용자, 아기 관련 API"
1818)
1919@ RestController
2020@ RequiredArgsConstructor
@@ -23,71 +23,27 @@ public class UserController {
2323
2424 private final UserService userService ;
2525
26- /*
27- @GetMapping("/baby")
28- public String babyRegisterPage(@AuthenticationPrincipal UserDetailsImpl userDetails) {
29- if (userDetails == null) {
30- return "<html><body><h2>인증되지 않은 사용자입니다.</h2></body></html>";
31- }
32-
33- User user = userDetails.getUser();
34- String html = """
35- <html>
36- <head><title>아기 정보 입력</title></head>
37- <body>
38- <h2>추가 정보 입력</h2>
39- <form method=\"post\" action=\"/api/user/baby\">
40- <label>이름: <input type=\"text\" name=\"userName\" /></label><br/>
41- <label>아기 태명: <input type=\"text\" name=\"babyName\" /></label><br/>
42- <label>출산 예정일: <input type=\"date\" name=\"dueDate\" /></label><br/>
43- <button type=\"submit\">등록하기</button>
44- </form>
45- </body>
46- </html>
47- """;
48- return html;
49- }
50- */
51-
52- @ Operation (summary = "아기 정보 등록" ,
53- description = "로그인한 사용자의 이름과 아기 정보를 등록하고, 선택된 아기 ID도 자동으로 저장합니다." )
54- @ ApiResponses ({
55- @ ApiResponse (responseCode = "200" , description = "아기 정보 등록 성공" ),
56- @ ApiResponse (responseCode = "401" , description = "인증되지 않은 사용자 (로그인 필요)" )
57- })
58- @ PostMapping ("/baby" )
59- public ResponseEntity <?> registerBaby (
60- @ RequestBody BabyRegisterRequest requestDto ,
61- @ AuthenticationPrincipal UserDetailsImpl userDetails ) {
62-
63- if (userDetails == null ) {
64- return ResponseEntity .status (401 ).body ("인증이 필요합니다." );
65- }
66-
67- userService .registerBaby (requestDto , userDetails .getUser ());
68- return ResponseEntity .ok ("아기 정보 등록 완료" );
69- }
70-
71- @ Operation (summary = "선택된 아기 변경" ,
72- description = "로그인한 사용자가 등록한 아기 중 하나를 선택된 아기로 변경합니다." )
26+ @ GetMapping ("" )
27+ @ Operation (
28+ summary = "현재 로그인된 유저 정보 조회" ,
29+ description = "로그인된 사용자의 이름, 전화번호, 배우자 전화번호, 선택된 아기의 이름을 반환합니다. "
30+ + "Authorization 헤더에 유효한 Access Token이 필요합니다."
31+ )
7332 @ ApiResponses ({
74- @ ApiResponse (responseCode = "200" , description = "선택된 아기 변경 성공" ),
33+ @ ApiResponse (responseCode = "200" , description = "유저 정보 조회 성공" ),
7534 @ ApiResponse (responseCode = "401" , description = "인증되지 않은 사용자 (로그인 필요)" ),
76- @ ApiResponse (responseCode = "404" , description = "해당 아기 정보를 찾을 수 없음" )
35+ @ ApiResponse (responseCode = "404" , description = "해당 유저를 찾을 수 없음" )
7736 })
78- @ PatchMapping ("/select-baby/{babyId}" )
79- public ResponseEntity <?> selectBaby (@ PathVariable Long babyId ,
80- @ AuthenticationPrincipal UserDetailsImpl userDetails ) {
37+ public ResponseEntity <UserResponse > getMyInfo (@ AuthenticationPrincipal UserDetailsImpl userDetails ) {
8138 if (userDetails == null ) {
82- return ResponseEntity .status (401 ).body ( "인증이 필요합니다." );
39+ return ResponseEntity .status (401 ).build ( );
8340 }
8441
85- userService .changeSelectedBaby (userDetails .getUser (), babyId );
86- return ResponseEntity .ok ("선택된 아기 변경 완료" );
42+ UserResponse userInfo = userService .getUserInfo (userDetails .getUser (). getId () );
43+ return ResponseEntity .ok (userInfo );
8744 }
8845
89-
90- @ PatchMapping ("/change-name" )
46+ @ PatchMapping ("/name" )
9147 @ Operation (
9248 summary = "유저 이름 변경" ,
9349 description = "로그인된 사용자의 이름을 새 이름으로 변경합니다. "
@@ -110,24 +66,60 @@ public ResponseEntity<?> changeName(
11066 return ResponseEntity .ok ("유저 이름 변경 완료" );
11167 }
11268
113- @ GetMapping ("/me" )
69+ @ Operation (summary = "아기 정보 등록 (튜토리얼)" ,
70+ description = "로그인한 사용자의 이름과 아기 정보를 등록하고, 선택된 아기 ID도 자동으로 저장합니다." )
71+ @ ApiResponses ({
72+ @ ApiResponse (responseCode = "200" , description = "아기 정보 등록 성공" ),
73+ @ ApiResponse (responseCode = "401" , description = "인증되지 않은 사용자 (로그인 필요)" )
74+ })
75+ @ PostMapping ("/baby" )
76+ public ResponseEntity <?> registerBaby (
77+ @ RequestBody BabyRegisterRequest requestDto ,
78+ @ AuthenticationPrincipal UserDetailsImpl userDetails ) {
79+
80+ if (userDetails == null ) {
81+ return ResponseEntity .status (401 ).body ("인증이 필요합니다." );
82+ }
83+
84+ userService .registerBaby (requestDto , userDetails .getUser ());
85+ return ResponseEntity .ok ("아기 정보 등록 완료" );
86+ }
87+
88+ @ GetMapping ("/baby" )
11489 @ Operation (
115- summary = "현재 로그인된 유저 정보 조회" ,
116- description = "로그인된 사용자의 이름, 전화번호, 배우자 전화번호, 선택된 아기의 이름을 반환합니다. "
90+ summary = "선택된 아기 정보 조회" ,
91+ description = "로그인된 사용자가 선택한 아기의 상세 정보( 이름, D-day, 프로필 이미지, 메시지)를 반환합니다. "
11792 + "Authorization 헤더에 유효한 Access Token이 필요합니다."
11893 )
11994 @ ApiResponses ({
120- @ ApiResponse (responseCode = "200" , description = "유저 정보 조회 성공" ),
95+ @ ApiResponse (responseCode = "200" , description = "선택된 아기 정보 조회 성공" ),
12196 @ ApiResponse (responseCode = "401" , description = "인증되지 않은 사용자 (로그인 필요)" ),
122- @ ApiResponse (responseCode = "404 " , description = "해당 유저를 찾을 수 없음" )
97+ @ ApiResponse (responseCode = "400 " , description = "선택된 아기가 없거나 해당 아기를 찾을 수 없음" )
12398 })
124- public ResponseEntity <UserResponse > getMyInfo (@ AuthenticationPrincipal UserDetailsImpl userDetails ) {
99+ public ResponseEntity <SelectedBabyResponse > getSelectedBabyInfo (@ AuthenticationPrincipal UserDetailsImpl userDetails ) {
125100 if (userDetails == null ) {
126101 return ResponseEntity .status (401 ).build ();
127102 }
128103
129- UserResponse userInfo = userService .getUserInfo (userDetails .getUser (). getId ());
130- return ResponseEntity .ok (userInfo );
104+ SelectedBabyResponse selectedBabyInfo = userService .getSelectedBabyInfo (userDetails .getUser ());
105+ return ResponseEntity .ok (selectedBabyInfo );
131106 }
132107
108+ @ PatchMapping ("/selected-baby/{babyId}" )
109+ @ Operation (summary = "선택된 아기 변경" ,
110+ description = "로그인한 사용자가 등록한 아기 중 하나를 선택된 아기로 변경합니다." )
111+ @ ApiResponses ({
112+ @ ApiResponse (responseCode = "200" , description = "선택된 아기 변경 성공" ),
113+ @ ApiResponse (responseCode = "401" , description = "인증되지 않은 사용자 (로그인 필요)" ),
114+ @ ApiResponse (responseCode = "404" , description = "해당 아기 정보를 찾을 수 없음" )
115+ })
116+ public ResponseEntity <?> selectBaby (@ PathVariable Long babyId ,
117+ @ AuthenticationPrincipal UserDetailsImpl userDetails ) {
118+ if (userDetails == null ) {
119+ return ResponseEntity .status (401 ).body ("인증이 필요합니다." );
120+ }
121+
122+ userService .changeSelectedBaby (userDetails .getUser (), babyId );
123+ return ResponseEntity .ok ("선택된 아기 변경 완료" );
124+ }
133125}
0 commit comments