11package com .web .SearchWeb .bookmark .controller ;
22
33
4+ import com .web .SearchWeb .bookmark .controller .dto .BookmarkRequests ;
45import com .web .SearchWeb .bookmark .domain .Bookmark ;
5- import com .web .SearchWeb .bookmark .dto .BookmarkDto ;
66import com .web .SearchWeb .bookmark .service .BookmarkService ;
7+ import com .web .SearchWeb .config .ApiResponse ;
78import com .web .SearchWeb .member .dto .CustomOAuth2User ;
89import com .web .SearchWeb .member .dto .CustomUserDetails ;
910import org .springframework .beans .factory .annotation .Autowired ;
1415import org .springframework .security .oauth2 .core .user .OAuth2User ;
1516import org .springframework .web .bind .annotation .*;
1617
17- import java .util .HashMap ;
1818import java .util .List ;
19- import java .util .Map ;
2019
2120
2221/**
@@ -34,142 +33,161 @@ public BookmarkApiController(BookmarkService bookmarkService) {
3433 this .bookmarkService = bookmarkService ;
3534 }
3635
37- /**
38- * 북마크 확인
39- */
40- @ GetMapping ("/check" )
41- public ResponseEntity <Boolean > checkBookmark (@ AuthenticationPrincipal Object currentUser , @ RequestParam String url ) {
42- // 로그인 되지 않은 경우
43- if (currentUser == null || "anonymousUser" .equals (currentUser )) {
44- return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
45- }
46-
47- Long memberId = getMemberId (currentUser );
48-
49- // 북마크 존재 여부 확인
50- boolean exists = bookmarkService .checkBookmarkExistsByUrl (memberId , url );
51- return ResponseEntity .ok (exists );
52- }
53-
54-
5536 /**
5637 * 북마크 추가
5738 */
5839 @ PostMapping
59- public ResponseEntity <Map < String , Object >> insertBookmark (
40+ public ResponseEntity <ApiResponse < Long >> insertBookmark (
6041 @ AuthenticationPrincipal Object currentUser ,
61- @ RequestBody BookmarkDto bookmarkDto ,
62- @ RequestParam String url ) {
63-
64- Map <String , Object > response = new HashMap <>();
65-
42+ @ RequestBody BookmarkRequests .CreateDto request ) {
43+
44+ // TODO: AOP 처리
6645 // 로그인 되지 않은 경우
6746 if (currentUser == null || "anonymousUser" .equals (currentUser )) {
68- return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).body ( response );
47+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ( );
6948 }
7049
7150 Long memberId = getMemberId (currentUser );
7251 if (memberId == null ) {
73- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body ( response );
52+ return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ( );
7453 }
7554
76- bookmarkDto .setCreatedByMemberId (memberId );
77- int result = bookmarkService .insertBookmark (bookmarkDto , url );
78- response .put ("success" , result > 0 );
79- return ResponseEntity .ok (response );
55+ Long bookmarkId = bookmarkService .insertBookmark (
56+ memberId ,
57+ request .url ,
58+ request .memberFolderId ,
59+ request .displayTitle ,
60+ request .note ,
61+ request .primaryCategoryId ,
62+ request .tags
63+ );
64+
65+ return ResponseEntity
66+ .status (HttpStatus .CREATED )
67+ .body (ApiResponse .success (bookmarkId ));
8068 }
8169
8270
8371 /**
84- * 북마크 목록 조회
72+ * 북마크 단일 조회
8573 */
86- @ GetMapping
87- public ResponseEntity <List <Bookmark >> selectBookmarkList (
74+ @ GetMapping ( "/{bookmarkId}" )
75+ public ResponseEntity <ApiResponse <Bookmark >> selectBookmark (
8876 @ AuthenticationPrincipal Object currentUser ,
89- @ RequestParam (required = false ) Long folderId ,
90- @ RequestParam (defaultValue = "Newest" ) String sort ,
91- @ RequestParam (required = false ) String query ,
92- @ RequestParam (required = false ) Long categoryId ) {
93-
77+ @ PathVariable Long bookmarkId ) {
78+
79+ // TODO: AOP 처리
9480 // 로그인 되지 않은 경우
9581 if (currentUser == null || "anonymousUser" .equals (currentUser )) {
9682 return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
9783 }
98-
84+
9985 Long memberId = getMemberId (currentUser );
10086 if (memberId == null ) {
10187 return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ();
10288 }
103-
104- List < Bookmark > bookmarks = bookmarkService .selectBookmarkList (memberId , folderId , sort , query , categoryId );
105- return ResponseEntity .ok (bookmarks );
89+
90+ Bookmark bookmark = bookmarkService .selectBookmark (memberId , bookmarkId );
91+ return ResponseEntity .ok (ApiResponse . success ( bookmark ) );
10692 }
10793
10894
10995 /**
110- * 북마크 단일 조회
96+ * 북마크 목록 조회
11197 */
112- @ GetMapping ( "/{bookmarkId}" )
113- public ResponseEntity <Bookmark > selectBookmark (
98+ @ GetMapping
99+ public ResponseEntity <ApiResponse < List < Bookmark >>> selectBookmarkList (
114100 @ AuthenticationPrincipal Object currentUser ,
115- @ PathVariable Long bookmarkId ) {
116-
101+ @ ModelAttribute BookmarkRequests .SearchDto searchDto ) {
102+
103+ // TODO: AOP 처리
117104 // 로그인 되지 않은 경우
118105 if (currentUser == null || "anonymousUser" .equals (currentUser )) {
119106 return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
120107 }
121-
108+
122109 Long memberId = getMemberId (currentUser );
123110 if (memberId == null ) {
124111 return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ();
125112 }
126-
127- Bookmark bookmark = bookmarkService .selectBookmark ( memberId , bookmarkId );
128- return ResponseEntity .ok (bookmark );
113+
114+ List < Bookmark > bookmarks = bookmarkService .selectBookmarkList ( searchDto . toCommand ( memberId ) );
115+ return ResponseEntity .ok (ApiResponse . success ( bookmarks ) );
129116 }
130117
131118
132119 /**
133120 * 북마크 수정
134121 */
135122 @ PutMapping ("/{bookmarkId}" )
136- public ResponseEntity <Map < String , Object >> updateBookmark (
123+ public ResponseEntity <ApiResponse < Long >> updateBookmark (
137124 @ AuthenticationPrincipal Object currentUser ,
138125 @ PathVariable Long bookmarkId ,
139- @ RequestBody BookmarkDto bookmarkDto ) {
126+ @ RequestBody BookmarkRequests . UpdateDto request ) {
140127
141- Map <String , Object > response = new HashMap <>();
128+ // TODO: AOP 처리
129+ // 로그인 되지 않은 경우
130+ if (currentUser == null || "anonymousUser" .equals (currentUser )) {
131+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
132+ }
142133
143134 Long memberId = getMemberId (currentUser );
144135 if (memberId == null ) {
145- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body ( response );
136+ return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ( );
146137 }
147138
148- bookmarkDto .setCreatedByMemberId (memberId );
149- int result = bookmarkService .updateBookmark (bookmarkDto , bookmarkId );
150- response .put ("success" , result > 0 );
151- return ResponseEntity .ok (response );
139+ Long updatedBookmarkId = bookmarkService .updateBookmark (
140+ memberId ,
141+ bookmarkId ,
142+ request .memberFolderId ,
143+ request .displayTitle ,
144+ request .note ,
145+ request .primaryCategoryId ,
146+ request .tags
147+ );
148+ return ResponseEntity .ok (ApiResponse .success (updatedBookmarkId ));
152149 }
153150
154151
155152 /**
156153 * 북마크 삭제
157154 */
158155 @ DeleteMapping ("/{bookmarkId}" )
159- public ResponseEntity <Map < String , Object >> deleteBookmark (
156+ public ResponseEntity <ApiResponse < Long >> deleteBookmark (
160157 @ AuthenticationPrincipal Object currentUser ,
161158 @ PathVariable Long bookmarkId ) {
162159
163- Map <String , Object > response = new HashMap <>();
164-
160+ // TODO: AOP 처리
161+ // 로그인 되지 않은 경우
162+ if (currentUser == null || "anonymousUser" .equals (currentUser )) {
163+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
164+ }
165+
165166 Long memberId = getMemberId (currentUser );
166167 if (memberId == null ) {
167- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body ( response );
168+ return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ( );
168169 }
169170
170- int result = bookmarkService .deleteBookmark (memberId , bookmarkId );
171- response .put ("success" , result > 0 );
172- return ResponseEntity .ok (response );
171+ Long deletedId = bookmarkService .deleteBookmark (memberId , bookmarkId );
172+ return ResponseEntity .ok (ApiResponse .success (deletedId ));
173+ }
174+
175+
176+ /**
177+ * 북마크 확인
178+ */
179+ @ GetMapping ("/check" )
180+ public ResponseEntity <Boolean > checkBookmark (@ AuthenticationPrincipal Object currentUser , @ RequestParam String url ) {
181+ // 로그인 되지 않은 경우
182+ if (currentUser == null || "anonymousUser" .equals (currentUser )) {
183+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
184+ }
185+
186+ Long memberId = getMemberId (currentUser );
187+
188+ // 북마크 존재 여부 확인
189+ boolean exists = bookmarkService .checkBookmarkExistsByUrl (memberId , url );
190+ return ResponseEntity .ok (exists );
173191 }
174192
175193
0 commit comments