From 3750fe2e1e240370a314b708d6a48b46b53c7701 Mon Sep 17 00:00:00 2001 From: Bong-oh Moon Date: Tue, 1 Oct 2024 19:25:20 +0900 Subject: [PATCH] =?UTF-8?q?[#27]=20[feat]=20=EC=97=AC=ED=96=89=EC=83=81?= =?UTF-8?q?=EC=84=B8=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=8F=99=ED=96=89=20=EB=AA=A8=EC=A7=91=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EB=82=98=EC=98=A4=EA=B2=8C=20=ED=95=A8=20(*=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=ED=95=84=EC=9A=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/SpotController.java | 5 ++- .../dto/companion/CompanionRecruitInfo.java | 15 +++++++ .../tripmate/api/dto/companion/HostInfo.java | 18 ++++++++ .../api/entity/CompanionRepository.java | 1 + .../tripmate/api/entity/TripStyleEntity.java | 10 +++++ .../com/tripmate/api/entity/UserEntity.java | 14 +++++- .../api/service/CompanionService.java | 44 ++++++++++++------- 7 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/tripmate/api/controller/SpotController.java b/src/main/java/com/tripmate/api/controller/SpotController.java index 8483a97..55b10c6 100644 --- a/src/main/java/com/tripmate/api/controller/SpotController.java +++ b/src/main/java/com/tripmate/api/controller/SpotController.java @@ -11,6 +11,7 @@ import com.tripmate.api.dto.response.SpotDetailResponse; import com.tripmate.api.dto.response.TripmateApiResponse; import com.tripmate.api.dto.spot.LocationBasedSpotInfo; +import com.tripmate.api.service.CompanionService; import com.tripmate.api.service.LocationBasedSpotSearchService; import com.tripmate.integration.tourapi.dto.response.SpotCommonInfo; import com.tripmate.integration.tourapi.service.TourApiService; @@ -41,6 +42,8 @@ public class SpotController { private final TourApiService tourApiService; + private final CompanionService companionService; + @Operation( summary = "여행지 검색 API", description = "위치(위도, 경도) 및 범위, 여행지 타입(예: EXPERIENCE), 여행지 타입 그룹(예: ACTIVITY)로 여행지 탐색" @@ -72,7 +75,7 @@ public ResponseEntity> getSpotDetail(@Pa SpotCommonInfo spotCommonInfo = tourApiService.getSpotDetailInfo(spotId); SpotType spotType = SpotType.fromTourApiCategory(spotCommonInfo.cat2()); - List companionRecruits = Collections.emptyList(); + List companionRecruits = companionService.getCompanionRecruitsBySpot(spotId); return ResponseEntity.ok( TripmateApiResponse.success( diff --git a/src/main/java/com/tripmate/api/dto/companion/CompanionRecruitInfo.java b/src/main/java/com/tripmate/api/dto/companion/CompanionRecruitInfo.java index 63c9095..a676a87 100644 --- a/src/main/java/com/tripmate/api/dto/companion/CompanionRecruitInfo.java +++ b/src/main/java/com/tripmate/api/dto/companion/CompanionRecruitInfo.java @@ -1,7 +1,12 @@ package com.tripmate.api.dto.companion; +import com.tripmate.api.entity.CompanionEntity; +import com.tripmate.api.entity.TripStyleEntity; +import com.tripmate.api.entity.UserEntity; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +@Builder public record CompanionRecruitInfo( @Schema(description = "동행 ID") @@ -19,4 +24,14 @@ public record CompanionRecruitInfo( @Schema(description = "나이대", example = "20대") String ageRange ) { + + public static CompanionRecruitInfo fromEntity(CompanionEntity companion, UserEntity host, TripStyleEntity tripStyle) { + return CompanionRecruitInfo.builder() + .companionId(companion.getId()) + .hostInfo(HostInfo.fromUser(host, tripStyle)) + .title(companion.getTitle()) + .gender(host.getGender()) + .ageRange(host.getAgeRange()) + .build(); + } } diff --git a/src/main/java/com/tripmate/api/dto/companion/HostInfo.java b/src/main/java/com/tripmate/api/dto/companion/HostInfo.java index 1bb2200..9036eb3 100644 --- a/src/main/java/com/tripmate/api/dto/companion/HostInfo.java +++ b/src/main/java/com/tripmate/api/dto/companion/HostInfo.java @@ -1,8 +1,13 @@ package com.tripmate.api.dto.companion; +import com.tripmate.api.entity.TripStyleEntity; +import com.tripmate.api.entity.UserEntity; import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.Arrays; import java.util.List; import lombok.Builder; +import org.apache.catalina.Host; @Builder public record HostInfo( @@ -24,4 +29,17 @@ public record HostInfo( @Schema(description = "동행 모임장과 매칭 비율") int matchingRatio ) { + + public static HostInfo fromUser(UserEntity user, TripStyleEntity tripStyle) { +// TripStyleEntity tripStyle = user.getTripStyle(); + + return HostInfo.builder() + .profileImage(user.getProfileImage()) + .kakaoNickname(user.getNickname()) + .characterName(tripStyle.getStyleName()) + .characterType(user.getCharacterType()) + .selectedKeyword(tripStyle.getSelectedKeywords()) + .matchingRatio(30) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/com/tripmate/api/entity/CompanionRepository.java b/src/main/java/com/tripmate/api/entity/CompanionRepository.java index 3c43a8b..9e21cb1 100644 --- a/src/main/java/com/tripmate/api/entity/CompanionRepository.java +++ b/src/main/java/com/tripmate/api/entity/CompanionRepository.java @@ -9,4 +9,5 @@ public interface CompanionRepository extends JpaRepository findCompanionEntitiesByHostId(Long hostId); + List findCompanionEntitiesBySpotId(Long spotId); } diff --git a/src/main/java/com/tripmate/api/entity/TripStyleEntity.java b/src/main/java/com/tripmate/api/entity/TripStyleEntity.java index 0eb5936..934bf76 100644 --- a/src/main/java/com/tripmate/api/entity/TripStyleEntity.java +++ b/src/main/java/com/tripmate/api/entity/TripStyleEntity.java @@ -9,6 +9,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Arrays; +import java.util.List; + @Entity @Getter @Builder @@ -21,7 +24,14 @@ public class TripStyleEntity { private Long id; private String styleName; + private String keyword1; + private String keyword2; + private String keyword3; + + public List getSelectedKeywords() { + return Arrays.asList(keyword1, keyword2, keyword3); + } } diff --git a/src/main/java/com/tripmate/api/entity/UserEntity.java b/src/main/java/com/tripmate/api/entity/UserEntity.java index 866f48f..55c490b 100644 --- a/src/main/java/com/tripmate/api/entity/UserEntity.java +++ b/src/main/java/com/tripmate/api/entity/UserEntity.java @@ -1,7 +1,6 @@ package com.tripmate.api.entity; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; @@ -21,14 +20,22 @@ public class UserEntity extends AbstractEntity { @NotNull private String nickname; + @NotNull private String profileImage; + @NotNull private String thumbnailImage; private String gender; + private String birthYear; + private Long tripStyleId; +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "trip_style_id", referencedColumnName = "id") +// private TripStyleEntity tripStyle; + private String characterType; @ColumnDefault("false") @@ -38,4 +45,7 @@ public void deleteAccount() { this.deleted = true; } + public String getAgeRange() { + return "30대"; + } } diff --git a/src/main/java/com/tripmate/api/service/CompanionService.java b/src/main/java/com/tripmate/api/service/CompanionService.java index 6410fc2..892b33a 100644 --- a/src/main/java/com/tripmate/api/service/CompanionService.java +++ b/src/main/java/com/tripmate/api/service/CompanionService.java @@ -2,6 +2,7 @@ import com.tripmate.api.domain.CompanionStatus; import com.tripmate.api.domain.MatchingStatus; +import com.tripmate.api.dto.companion.CompanionRecruitInfo; import com.tripmate.api.dto.companion.HostInfo; import com.tripmate.api.dto.companion.ReviewInfo; import com.tripmate.api.dto.companion.ReviewResult; @@ -9,33 +10,22 @@ import com.tripmate.api.dto.request.CompanionReviewRequest; import com.tripmate.api.dto.response.CollectCompanionResponse; import com.tripmate.api.dto.response.CompanionInfoResponse; -import com.tripmate.api.entity.CompanionEntity; -import com.tripmate.api.entity.CompanionRepository; -import com.tripmate.api.entity.CompanionReviewEntity; -import com.tripmate.api.entity.CompanionReviewRepository; -import com.tripmate.api.entity.CompanionUserEntity; -import com.tripmate.api.entity.CompanionUserRepository; -import com.tripmate.api.entity.TripStyleEntity; -import com.tripmate.api.entity.TripStyleRepository; -import com.tripmate.api.entity.UserEntity; -import com.tripmate.api.entity.UserRepository; -import java.util.Arrays; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; +import com.tripmate.api.entity.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + @Slf4j @RequiredArgsConstructor @Service -@Transactional public class CompanionService { - private final ModelMapper modelMapper; private final CompanionRepository companionRepository; private final CompanionReviewRepository companionReviewRepository; private final CompanionUserRepository companionUserRepository; @@ -43,6 +33,7 @@ public class CompanionService { private final TripStyleRepository tripStyleRepository; private final CompanionReviewService companionReviewService; + @Transactional(readOnly = true) public CompanionInfoResponse getCompanionInfo(Long companionId, Long userId) { CompanionEntity companionEntity = companionRepository.findById(companionId) @@ -89,6 +80,23 @@ public CompanionInfoResponse getCompanionInfo(Long companionId, Long userId) { gender, ageRange); } + @Transactional(readOnly = true) + public List getCompanionRecruitsBySpot(Long spotId) { + return companionRepository.findCompanionEntitiesBySpotId(spotId) + .stream() + .map(companion -> { + UserEntity host = userRepository.findById(companion.getHostId()) + .orElseThrow(() -> new NoSuchElementException("존재하지 않는 회원입니다.", null)); + + TripStyleEntity tripStyle = tripStyleRepository.findById(host.getTripStyleId()) + .orElseThrow(() -> new NoSuchElementException("존재하지 않는 여행스타일ID입니다", null)); + + return CompanionRecruitInfo.fromEntity(companion, host, tripStyle); + }) + .toList(); + } + + @Transactional public CollectCompanionResponse saveCompanionInfo(CollectCompanionRequest collectCompanionRequest) { // 동행 엔티티 생성 @@ -125,6 +133,7 @@ public CollectCompanionResponse saveCompanionInfo(CollectCompanionRequest collec * @param userId * @param companionReviewRequest */ + @Transactional public void saveCompanionReview(Long userId, CompanionReviewRequest companionReviewRequest) { Long companionId = companionReviewRequest.companionId(); @@ -156,6 +165,7 @@ public void saveCompanionReview(Long userId, CompanionReviewRequest companionRev } } + @Transactional public void saveCompanionApply(Long companionId, Long userId) { CompanionUserEntity companionUserEntity = CompanionUserEntity.builder()