Skip to content

Commit

Permalink
[FEAT] 숙소 상세 페이지 API 구현 (#58)
Browse files Browse the repository at this point in the history
- 숙소의 id를 받아서 숙소의 상세 페이지 정보를 보내주는 detail API 구현
  • Loading branch information
eunsol-an committed Dec 28, 2022
1 parent 9fdbd41 commit 8483a20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ public ResponseEntity<List<UnClientResponseDto>> search(@PageableDefault(sort =
return ResponseEntity.ok(roomService.search(keyword, pageable));
}

//숙소 상세 조회
@GetMapping("/rooms/{roomId}")
public ResponseEntity<UnClientResponseDto> getRoom(@PathVariable Long roomId) {
return ResponseEntity.ok(roomService.getRoom(roomId));
}

//숙소 정보 수정
@CrossOrigin
@CrossOrigin // CORS 해결책 중 하나
@PatchMapping("/rooms/{roomId}")
public ResponseEntity<ResponseMsgDto> updateRoom(@PathVariable Long roomId,
@RequestPart(value = "data") RoomRequestDto requestDto,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/cloneweek/hanghaebnb/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public List<UnClientResponseDto> search(String keyword, Pageable pageable) {
return roomResponseDtos;
}

//숙소 상세 조회
public UnClientResponseDto getRoom(Long roomId) {
Room room = roomRepository.findById(roomId).orElseThrow(
() -> new CustomException(StatusMsgCode.ROOM_NOT_FOUND)
);
List<String> imageFileList = new ArrayList<>();
for (ImageFile imageFile : room.getImageFileList()) {
imageFileList.add(imageFile.getPath());
}
return new UnClientResponseDto(room, imageFileList);
}

//숙소 정보 수정
@Transactional
public ResponseMsgDto update(Long roomId, RoomRequestDto requestDto, User user, List<MultipartFile> multipartFilelist) {
Expand Down Expand Up @@ -216,4 +228,5 @@ public ResponseMsgDto cancelLike(Long roomId, User user) {
roomLikeRepository.deleteByRoomIdAndUserId(roomId, user.getId());
return new ResponseLikeDto(StatusMsgCode.CANCEL_LIKE, roomId, checkLike(roomId, user));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public Docket swagger() {
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
.apiInfo(apiInfo())
.useDefaultResponseMessages(false);
}

private ApiInfo apiInfo() {
Expand Down

0 comments on commit 8483a20

Please sign in to comment.