-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] 북마크 컨트롤러 구현 및 TransportType Enum 리팩토링 (#86)
- 북마크 컨트롤러 구현 - `GET` `/bookmark` : 본인이 작성한 북마크 리스트 반환 - `GET` `/bookmark/{bookmarkId}` : bookmarkId로 북마크 조회 - `POST` `/bookmark` : 북마크 생성 - `DELETE` `/bookmark/{bookmarkId}` : bookmarkId로 북마크 삭제 - `PUT` `/bookmark/{bookmarkId}` : bookmarkId로 북마크 수정 - 북마크 서비스 수정 - `getBookmarkById` 메소드에서 본인이 작성한 북마크만 조회하도록 수정 - 북마크 서비스 메소드 순서 변경 : get, create, update, delete 순서 - 메소드 파라미터 순서 수정 : dto, userId, bookmarkId 순서 - 받아야하는 파라미터가 늘어날수록 코드 가독성이 나빠질 수 있음 -> 추후 service단에서 사용할 dto를 분리하도록 리팩토링 고려 - TransportType Enum 리팩토링 - `BookmarkRespDto` 에서 `TransportType`를 `String`이 아닌 `enum`으로 반환하도록 리팩토링 - `TransportType`에서 `name` 필드가 불필요하다고 생각되어 삭제 close #84
- Loading branch information
Showing
4 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
server/src/main/java/com/talkka/server/bookmark/controller/BookmarkController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.talkka.server.bookmark.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.talkka.server.bookmark.dto.BookmarkReqDto; | ||
import com.talkka.server.bookmark.dto.BookmarkRespDto; | ||
import com.talkka.server.bookmark.exception.BookmarkNotFoundException; | ||
import com.talkka.server.bookmark.exception.BookmarkUserNotFoundException; | ||
import com.talkka.server.bookmark.exception.enums.InvalidTransportTypeEnumException; | ||
import com.talkka.server.bookmark.service.BookmarkService; | ||
import com.talkka.server.oauth.domain.OAuth2UserInfo; | ||
import com.talkka.server.review.exception.ContentAccessException; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/bookmark") | ||
public class BookmarkController { | ||
private final BookmarkService bookmarkService; | ||
|
||
// 본인이 작성한 북마크 리스트만 조회 | ||
@GetMapping("") | ||
public ResponseEntity<?> getBookmarkList(@AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo) { | ||
List<BookmarkRespDto> bookmarks = bookmarkService.getBookmarkByUserId(oAuth2UserInfo.getUserId()); | ||
return ResponseEntity.ok(bookmarks); | ||
} | ||
|
||
@GetMapping("/{bookmarkId}") | ||
public ResponseEntity<?> getBookmark(@AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo, | ||
@PathVariable Long bookmarkId) { | ||
ResponseEntity<?> response; | ||
try { | ||
BookmarkRespDto bookmark = bookmarkService.getBookmarkById(oAuth2UserInfo.getUserId(), bookmarkId); | ||
response = ResponseEntity.ok(bookmark); | ||
} catch (BookmarkNotFoundException | BookmarkUserNotFoundException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} catch (ContentAccessException exception) { | ||
response = ResponseEntity.status(HttpStatus.FORBIDDEN).body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<?> createBookmark(@AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo, | ||
BookmarkReqDto bookmarkReqDto) { | ||
ResponseEntity<?> response; | ||
try { | ||
BookmarkRespDto bookmark = bookmarkService.createBookmark(bookmarkReqDto, oAuth2UserInfo.getUserId()); | ||
return ResponseEntity.ok(bookmark); | ||
} catch (BookmarkUserNotFoundException | InvalidTransportTypeEnumException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@PutMapping("{bookmarkId}") | ||
public ResponseEntity<?> updateBookmark(@AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo, | ||
BookmarkReqDto bookmarkReqDto, @PathVariable Long bookmarkId) { | ||
ResponseEntity<?> response; | ||
try { | ||
BookmarkRespDto bookmark = bookmarkService.updateBookmark(bookmarkReqDto, oAuth2UserInfo.getUserId(), | ||
bookmarkId); | ||
response = ResponseEntity.ok(bookmark); | ||
} catch (BookmarkNotFoundException | BookmarkUserNotFoundException | ||
| InvalidTransportTypeEnumException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} catch (ContentAccessException exception) { | ||
response = ResponseEntity.status(HttpStatus.FORBIDDEN).body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@DeleteMapping("/{bookmarkId}") | ||
public ResponseEntity<?> deleteBookmark(@AuthenticationPrincipal OAuth2UserInfo oAuth2UserInfo, | ||
@PathVariable Long bookmarkId) { | ||
ResponseEntity<?> response; | ||
try { | ||
bookmarkService.deleteBookmark(oAuth2UserInfo.getUserId(), bookmarkId); | ||
response = ResponseEntity.ok().build(); | ||
} catch (BookmarkNotFoundException | BookmarkUserNotFoundException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} catch (ContentAccessException exception) { | ||
response = ResponseEntity.status(HttpStatus.FORBIDDEN).body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
server/src/main/java/com/talkka/server/bookmark/dto/BookmarkDetailRespDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters