diff --git a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java index 2785144..0b72216 100644 --- a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java +++ b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java @@ -40,10 +40,11 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ /** - * 8000: membersocialring 관련 + * 8000: member socialring 관련 */ CANNOT_FOUND_MEMBERSOCIALRING(8000, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링을 찾을 수 없습니다."), CANNOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."), + CANNOT_FOUND_MEMBERSOCIALRING_LIST(8002, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링 리스트를 찾을 수 없습니다."), /** * 9000 : crew 관련 diff --git a/src/main/java/com/example/likelion12/controller/SocialringController.java b/src/main/java/com/example/likelion12/controller/SocialringController.java index 7a8ae62..f1ea6af 100644 --- a/src/main/java/com/example/likelion12/controller/SocialringController.java +++ b/src/main/java/com/example/likelion12/controller/SocialringController.java @@ -2,6 +2,7 @@ import com.example.likelion12.common.response.BaseResponse; import com.example.likelion12.common.response.status.BaseExceptionResponseStatus; +import com.example.likelion12.dto.socialring.GetSocialringDetailResponse; import com.example.likelion12.dto.socialring.PatchSocialringModifyRequest; import com.example.likelion12.dto.socialring.PostSocialringRequest; import com.example.likelion12.dto.socialring.PostSocialringResponse; @@ -9,7 +10,6 @@ import com.example.likelion12.util.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @Slf4j @@ -45,4 +45,15 @@ public BaseResponse modifySocialring(@RequestHeader("Authorization") Strin return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); } + /** + * 소셜링 상세 조회 + */ + @GetMapping("") + public BaseResponse getSocialringDetail(@RequestHeader("Authorization") String authorization, + @RequestParam Long socialringId){ + log.info("[SocialringController.getSocialringDetail]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + return new BaseResponse<>(socialringService.getSocialringDetail(memberId, socialringId)); + } + } diff --git a/src/main/java/com/example/likelion12/dto/socialring/GetSocialringDetailResponse.java b/src/main/java/com/example/likelion12/dto/socialring/GetSocialringDetailResponse.java new file mode 100644 index 0000000..34451bd --- /dev/null +++ b/src/main/java/com/example/likelion12/dto/socialring/GetSocialringDetailResponse.java @@ -0,0 +1,54 @@ +package com.example.likelion12.dto.socialring; + +import com.example.likelion12.domain.base.BaseGender; +import com.example.likelion12.domain.base.BaseLevel; +import com.example.likelion12.domain.base.BaseRole; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.List; + +@Getter +@AllArgsConstructor +public class GetSocialringDetailResponse { + + /** + * 소셜링 상세 조회 response dto + */ + private BaseRole memberRole; + private String socialringName; + private String socialringImg; + private String activityRegionName; + private String facilityName; + private String exerciseName; + private int totalRecruits; + private LocalDate socialringDate; + private int socialringCost; + private String comment; + private String commentSimple; + private BaseGender gender; + private BaseLevel level; + private List members; + private List recommands; + + @Getter + @AllArgsConstructor + public static class Socialrings { + private String memberImg; + } + + @Getter + @AllArgsConstructor + public static class Recommands{ + private Long socialringId; + private String socialringName; + private String socialringImg; + private String activityRegionName; + private LocalDate socialringDate; + private int socialringCost; + private String commentSimple; + private int currentRecruits; + private int totalRecruits; + } +} diff --git a/src/main/java/com/example/likelion12/repository/MemberSocialringRepository.java b/src/main/java/com/example/likelion12/repository/MemberSocialringRepository.java index 0e6a495..3eeef28 100644 --- a/src/main/java/com/example/likelion12/repository/MemberSocialringRepository.java +++ b/src/main/java/com/example/likelion12/repository/MemberSocialringRepository.java @@ -4,10 +4,13 @@ import com.example.likelion12.domain.base.BaseStatus; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface MemberSocialringRepository extends JpaRepository { - //Optional findByMemberIdAndSocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status); + Optional findByMember_MemberIdAndSocialring_SocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status); + Optional> findBySocialring_SocialringIdAndStatus(Long socialringId, BaseStatus baseStatus); } + diff --git a/src/main/java/com/example/likelion12/repository/SocialringRepository.java b/src/main/java/com/example/likelion12/repository/SocialringRepository.java index d0c0620..c71a7b2 100644 --- a/src/main/java/com/example/likelion12/repository/SocialringRepository.java +++ b/src/main/java/com/example/likelion12/repository/SocialringRepository.java @@ -2,13 +2,14 @@ import com.example.likelion12.domain.Socialring; import com.example.likelion12.domain.base.BaseStatus; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; import java.util.Optional; -import java.util.Optional; public interface SocialringRepository extends JpaRepository { @@ -17,4 +18,9 @@ public interface SocialringRepository extends JpaRepository { Optional> findTop4ByOrderBySocialringDate(); Optional findBySocialringIdAndStatus(Long socialringId, BaseStatus status); + + // 특정 activity_region_id 값을 가진 상위 3개의 Socialring를 반환하는 쿼리 + @Query("SELECT c FROM Socialring c WHERE c.activityRegion.id = :activityRegionId AND c.status = :status ORDER BY c.socialringId ASC") + List findTop3ByActivityRegionIdAndStatus(@Param("activityRegionId") Long activityRegionId, @Param("status") BaseStatus status, Pageable pageable); + } diff --git a/src/main/java/com/example/likelion12/service/SocialringService.java b/src/main/java/com/example/likelion12/service/SocialringService.java index 05e5506..80f71a7 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -5,16 +5,20 @@ import com.example.likelion12.domain.base.BaseGender; import com.example.likelion12.domain.base.BaseLevel; import com.example.likelion12.domain.base.BaseStatus; +import com.example.likelion12.dto.socialring.GetSocialringDetailResponse; import com.example.likelion12.dto.socialring.PatchSocialringModifyRequest; import com.example.likelion12.dto.socialring.PostSocialringRequest; import com.example.likelion12.dto.socialring.PostSocialringResponse; import com.example.likelion12.repository.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; @@ -30,7 +34,9 @@ public class SocialringService { private final ActivityRegionRepository activityRegionRepository; private final MemberSocialringRepository memberSocialringRepository; - //소셜링등록 + /** + * 소셜링 등록 + */ @Transactional public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequest postSocialringRequest) { log.info("[SocialringService.createSocialring]"); @@ -66,7 +72,9 @@ public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequ return new PostSocialringResponse(socialring.getSocialringId()); } - //소셜링 수정 + /** + * 소셜링 수정 + */ @Transactional public void modifySocialring(Long memberId, Long socialringId, PatchSocialringModifyRequest patchSocialringModifyRequest) { log.info("[SocialringService.modifySocialring]"); @@ -138,6 +146,49 @@ public void modifySocialring(Long memberId, Long socialringId, PatchSocialringMo } + /** + * 소셜링 상세 조회 + */ + @Transactional + public GetSocialringDetailResponse getSocialringDetail(Long memberId, Long socialringId) { + log.info("[SocialringService.getSocialringDetail]"); + // 상세조회하고자 하는 소셜링 + Socialring socialring = socialringRepository.findBySocialringIdAndStatus(socialringId, BaseStatus.ACTIVE) + .orElseThrow(() -> new SocialringException(CANNOT_FOUND_SOCIALRING)); + // 상세조회하고자 하는 멤버의 멤버소셜링 + MemberSocialring memberSocialring = memberSocialringRepository.findByMember_MemberIdAndSocialring_SocialringIdAndStatus(memberId, + socialringId, BaseStatus.ACTIVE).orElseThrow(() -> new MemberSocialringException(CANNOT_FOUND_MEMBERSOCIALRING)); + // 소셜링에 등록된 멤버 리스트 추출 + List memberSocialringList = memberSocialringRepository.findBySocialring_SocialringIdAndStatus + (socialringId, BaseStatus.ACTIVE).orElseThrow(()-> new MemberSocialringException( CANNOT_FOUND_MEMBERSOCIALRING_LIST)); + // 소셜링에 등록된 멤버 리스트에서 사진만 추출해서 반환 + List memberImgList = memberSocialringList.stream() + .map(MemberSocialring -> new GetSocialringDetailResponse.Socialrings(memberSocialring.getMember().getMemberImg())) + .collect(Collectors.toList()); + + List recommandsList = socialringRepository.findTop3ByActivityRegionIdAndStatus( + socialring.getActivityRegion().getActivityRegionId(), BaseStatus.ACTIVE, Pageable.ofSize(3)) + .stream().map(socialrings -> new GetSocialringDetailResponse.Recommands( + socialrings.getSocialringId(), + socialrings.getSocialringName(), + socialrings.getSocialringImg(), + socialrings.getActivityRegion().getActivityRegionName(), + socialrings.getSocialringDate(), + socialrings.getSocialringCost(), + socialrings.getCommentSimple(), + socialrings.getMemberSocialringList().size(), + socialrings.getTotalRecruits() + )).collect(Collectors.toList()); + + GetSocialringDetailResponse getSocialringDetailResponse = new GetSocialringDetailResponse(memberSocialring.getRole(),socialring.getSocialringName(), + socialring.getSocialringImg(), socialring.getActivityRegion().getActivityRegionName(),socialring.getFacility().getFacilityName(), + socialring.getExercise().getExerciseName(),socialring.getTotalRecruits(),socialring.getSocialringDate(), + socialring.getSocialringCost(),socialring.getComment(),socialring.getCommentSimple(),socialring.getGender(), + socialring.getLevel(),memberImgList,recommandsList); + + return getSocialringDetailResponse; + + } }