Skip to content

Commit

Permalink
[FIX] 사라진 검색 기능 추가
Browse files Browse the repository at this point in the history
- RoomService에 사라졌던 search 메소드 추가
- RoomController에 사용하지 않는 import 삭제
  • Loading branch information
eunsol-an committed Dec 26, 2022
1 parent b76653f commit accbec0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import com.cloneweek.hanghaebnb.dto.ResponseMsgDto;
import com.cloneweek.hanghaebnb.dto.RoomRequestDto;
import com.cloneweek.hanghaebnb.dto.RoomResponseDto;
import com.cloneweek.hanghaebnb.entity.Room;
import com.cloneweek.hanghaebnb.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/cloneweek/hanghaebnb/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public List<RoomResponseDto> getRooms(Pageable pageable, User user) {
return roomResponseDto;
}

//숙소 키워드 검색
@Transactional(readOnly = true)
public List<RoomResponseDto> search(String keyword, Pageable pageable, User user) {
// 페이징 처리
// 작성날짜 순으로 정렬
Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");

pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);

Page<Room> roomList = roomRepository.findByTitleContaining(keyword, pageable);
List<RoomResponseDto> roomResponseDtos = new ArrayList<>();
for(Room room : roomList){
roomResponseDtos.add(new RoomResponseDto(room, (checkLike(room.getId(), user))));
}

return roomResponseDtos;
}

//숙소 정보 수정
// @Transactional
// public RoomResponseDto update(Long roomId, RoomRequestDto requestDto, User user, List<MultipartFile> multipartFilelist) throws IOException {
Expand Down Expand Up @@ -127,7 +145,6 @@ public RoomResponseDto update(Long roomId, RoomRequestDto requestDto, User user,
return new RoomResponseDto(room, user.getNickname());
}


//숙소 정보 삭제
// @Transactional
// public ResponseMsgDto delete(Long roomId, User user) {
Expand Down

0 comments on commit accbec0

Please sign in to comment.