Skip to content

Commit

Permalink
[#27] [feat] 여행상세페이지에서 동행 모집 목록 나오게 함 (*테스트 필요)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonomoon committed Oct 1, 2024
1 parent cd2452c commit 3750fe2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class SpotController {

private final TourApiService tourApiService;

private final CompanionService companionService;

@Operation(
summary = "여행지 검색 API",
description = "위치(위도, 경도) 및 범위, 여행지 타입(예: EXPERIENCE), 여행지 타입 그룹(예: ACTIVITY)로 여행지 탐색"
Expand Down Expand Up @@ -72,7 +75,7 @@ public ResponseEntity<TripmateApiResponse<SpotDetailResponse>> getSpotDetail(@Pa
SpotCommonInfo spotCommonInfo = tourApiService.getSpotDetailInfo(spotId);
SpotType spotType = SpotType.fromTourApiCategory(spotCommonInfo.cat2());

List<CompanionRecruitInfo> companionRecruits = Collections.emptyList();
List<CompanionRecruitInfo> companionRecruits = companionService.getCompanionRecruitsBySpot(spotId);

return ResponseEntity.ok(
TripmateApiResponse.success(
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/tripmate/api/dto/companion/HostInfo.java
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface CompanionRepository extends JpaRepository<CompanionEntity, Long

List<CompanionEntity> findCompanionEntitiesByHostId(Long hostId);

List<CompanionEntity> findCompanionEntitiesBySpotId(Long spotId);
}
10 changes: 10 additions & 0 deletions src/main/java/com/tripmate/api/entity/TripStyleEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

@Entity
@Getter
@Builder
Expand All @@ -21,7 +24,14 @@ public class TripStyleEntity {
private Long id;

private String styleName;

private String keyword1;

private String keyword2;

private String keyword3;

public List<String> getSelectedKeywords() {
return Arrays.asList(keyword1, keyword2, keyword3);
}
}
14 changes: 12 additions & 2 deletions src/main/java/com/tripmate/api/entity/UserEntity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Expand All @@ -38,4 +45,7 @@ public void deleteAccount() {
this.deleted = true;
}

public String getAgeRange() {
return "30대";
}
}
44 changes: 27 additions & 17 deletions src/main/java/com/tripmate/api/service/CompanionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,38 @@

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;
import com.tripmate.api.dto.request.CollectCompanionRequest;
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;
private final UserRepository userRepository;
private final TripStyleRepository tripStyleRepository;
private final CompanionReviewService companionReviewService;

@Transactional(readOnly = true)
public CompanionInfoResponse getCompanionInfo(Long companionId, Long userId) {

CompanionEntity companionEntity = companionRepository.findById(companionId)
Expand Down Expand Up @@ -89,6 +80,23 @@ public CompanionInfoResponse getCompanionInfo(Long companionId, Long userId) {
gender, ageRange);
}

@Transactional(readOnly = true)
public List<CompanionRecruitInfo> 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) {

// 동행 엔티티 생성
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -156,6 +165,7 @@ public void saveCompanionReview(Long userId, CompanionReviewRequest companionRev
}
}

@Transactional
public void saveCompanionApply(Long companionId, Long userId) {

CompanionUserEntity companionUserEntity = CompanionUserEntity.builder()
Expand Down

0 comments on commit 3750fe2

Please sign in to comment.