Skip to content

Commit

Permalink
Merge pull request #120 from IT-Cotato/feature/119-refactor-find-plac…
Browse files Browse the repository at this point in the history
…es-by-self

Refactor: 개인 장소 조회에서 다른 사람들 장소도 리턴하도록 변경(#119)
  • Loading branch information
yooooonshine authored Aug 5, 2024
2 parents aa022d1 + 1c8e8dc commit 1176995
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public ResponseEntity<BaseResponse> placesSaveOrUpdateBySelf(@RequestBody Places
@Operation(
summary = "개개인 장소 조회하기",
description = """
개개인이 저장한 장소 조회하기.
개개인이 저장한 장소 및 다른 사람들이 저장한 장소들 조회하기.
다른 사람들이 저장한 장소(otherPlaces)에는 당사자가 저장한 장소는 포함되지 않는다.
AccessToken 필요.""",
parameters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static class PlacesSaveOrUpdateBySelfRequest {
@AllArgsConstructor
public static class PlaceFindResponse {

private final Boolean existence;
private final PlaceVO place;
private final Boolean myPlaceExistence;
private final PlaceVO myPlace;
private final Boolean otherPlacesExistence;
private final List<PlaceVO> otherPlaces;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import io.lettuce.core.dynamic.annotation.Param;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.place.domain.Place;
import middle_point_search.backend.domains.room.domain.Room;
Expand All @@ -22,4 +24,7 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {
Optional<Place> findByRoom_IdentityNumberAndMember_Name(String roomId, String name);

void deleteAllByRoom_IdentityNumber(String roomId);

@Query("select p from Place p where p.member.name != :memberName and p.room.identityNumber = :roomId")
List<Place> findAllByRoom_IdentityNumberAndMember_Name(@Param(value = "roomId") String roomId ,@Param(value = "memberName") String memberName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import middle_point_search.backend.domains.member.domain.Role;
import middle_point_search.backend.domains.member.service.MemberService;
import middle_point_search.backend.domains.place.domain.Place;
import middle_point_search.backend.domains.place.dto.PlaceDTO;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceFindResponse;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceSaveOrUpdateRequest;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceVO;
Expand Down Expand Up @@ -97,9 +98,23 @@ private void saveOrUpdatePlacesBySelf(Room room, PlacesSaveOrUpdateBySelfRequest
//개개인 장소 조회
public PlaceFindResponse findPlace(String roomId, String memberName) {

return placeRepository.findByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.map(place -> new PlaceFindResponse(true, place.toVO()))
.orElseGet(() -> new PlaceFindResponse(false, null));
//내 장소 조회
PlaceVO myPlace = placeRepository.findByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.map(Place:: toVO)
.orElse(null);

//내 장소 존재 유무
Boolean myPlaceExistence = myPlace != null;

//다른 사람들 장소 조회
List<PlaceVO> otherPlaces = placeRepository.findAllByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.stream().map(Place::toVO)
.toList();

//다른 사람들 장소 유무
boolean otherPlacesExistence = !otherPlaces.isEmpty();

return new PlaceDTO.PlaceFindResponse(myPlaceExistence, myPlace, otherPlacesExistence, otherPlaces);
}

//개인 장소 조회
Expand Down

0 comments on commit 1176995

Please sign in to comment.