Skip to content

Commit

Permalink
Merge pull request #48 from Likelion12/12-be-소셜링-상세-조회
Browse files Browse the repository at this point in the history
Feat : 소셜링 상세 조회
  • Loading branch information
jsilver01 authored Aug 2, 2024
2 parents d151a64 + 24c35d4 commit 98f8ade
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 관련
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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;
import com.example.likelion12.service.SocialringService;
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
Expand Down Expand Up @@ -45,4 +45,15 @@ public BaseResponse<Void> modifySocialring(@RequestHeader("Authorization") Strin
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

/**
* 소셜링 상세 조회
*/
@GetMapping("")
public BaseResponse<GetSocialringDetailResponse> getSocialringDetail(@RequestHeader("Authorization") String authorization,
@RequestParam Long socialringId){
log.info("[SocialringController.getSocialringDetail]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.getSocialringDetail(memberId, socialringId));
}

}
Original file line number Diff line number Diff line change
@@ -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<GetSocialringDetailResponse.Socialrings> members;
private List<GetSocialringDetailResponse.Recommands> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberSocialring, Long> {
//Optional<MemberSocialring> findByMemberIdAndSocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);

Optional<MemberSocialring> findByMember_MemberIdAndSocialring_SocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);
Optional<List<MemberSocialring>> findBySocialring_SocialringIdAndStatus(Long socialringId, BaseStatus baseStatus);
}


Original file line number Diff line number Diff line change
Expand Up @@ -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<Socialring, Long> {

Expand All @@ -17,4 +18,9 @@ public interface SocialringRepository extends JpaRepository<Socialring, Long> {
Optional<List<Socialring>> findTop4ByOrderBySocialringDate();

Optional<Socialring> 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<Socialring> findTop3ByActivityRegionIdAndStatus(@Param("activityRegionId") Long activityRegionId, @Param("status") BaseStatus status, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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]");
Expand Down Expand Up @@ -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]");
Expand Down Expand Up @@ -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<MemberSocialring> memberSocialringList = memberSocialringRepository.findBySocialring_SocialringIdAndStatus
(socialringId, BaseStatus.ACTIVE).orElseThrow(()-> new MemberSocialringException( CANNOT_FOUND_MEMBERSOCIALRING_LIST));
// 소셜링에 등록된 멤버 리스트에서 사진만 추출해서 반환
List<GetSocialringDetailResponse.Socialrings> memberImgList = memberSocialringList.stream()
.map(MemberSocialring -> new GetSocialringDetailResponse.Socialrings(memberSocialring.getMember().getMemberImg()))
.collect(Collectors.toList());

List<GetSocialringDetailResponse.Recommands> 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;

}
}

0 comments on commit 98f8ade

Please sign in to comment.