Skip to content

Commit

Permalink
feat: 전체 챌린지 리스트 조회 - 종료된 챌린지 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
daeunkwak committed Aug 28, 2023
1 parent 870382f commit 252ae09
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.cmc.domains.image.service.ImageService;
import com.cmc.domains.member.dto.response.SimpleMemberResponseDto;
import com.cmc.domains.member.service.MemberService;
import com.cmc.domains.participate.service.ParticipateService;
import com.cmc.global.resolver.RequestMemberId;
import com.cmc.member.Member;
import com.cmc.oauth.service.TokenProvider;
import com.cmc.participate.Participate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class CertifyController {
private final ImageService imageService;
private final MemberService memberService;
private final ChallengeService challengeService;
private final ParticipateService participateService;

@Tag(name = "certify", description = "챌린지 인증 API")
@Operation(summary = "챌린지 인증 api")
Expand Down Expand Up @@ -159,4 +162,16 @@ private Boolean findIsLike(Certify certify, Long memberId){
return false;
}

@Tag(name = "challenge")
@Operation(summary = "participate-certify 삭제 api (더미데이터 삭제용)")
@DeleteMapping(value="/{participateId}")
public ResponseEntity<CommonResponse> deleteParticipateCertify(@Parameter(hidden = true) @RequestMemberId Long memberId,
@PathVariable("participateId") Long participateId) {

Participate participate = participateService.find(participateId);

certifyService.deleteParticipateCertify(participate);
return ResponseEntity.ok(CommonResponse.from("챌린지가 삭제되었습니다"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import com.cmc.domains.certify.repository.CertifyRepository;
import com.cmc.domains.certifyLike.repository.CertifyLikeRepository;
import com.cmc.domains.challenge.repository.ChallengeRepository;
import com.cmc.domains.image.certify.repository.CertifyImageRepository;
import com.cmc.domains.image.certifyExample.repository.CertifyExampleImageRepository;
import com.cmc.domains.member.repository.MemberRepository;
import com.cmc.domains.participate.repository.ParticipateRepository;
import com.cmc.member.Member;
import com.cmc.participate.Participate;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,6 +30,7 @@
@Service
@Transactional
@RequiredArgsConstructor
@Slf4j
public class CertifyService {

private final CertifyRepository certifyRepository;
Expand All @@ -36,6 +39,7 @@ public class CertifyService {
private final MemberRepository memberRepository;
private final CertifyLikeRepository certifyLikeRepository;
private final CertifyExampleImageRepository certifyExampleImageRepository;
private final CertifyImageRepository certifyImageRepository;

// 인증 생성
public Certify create(Long challengeId, String certifyName, String certifyContent, Long memberId) {
Expand Down Expand Up @@ -145,6 +149,21 @@ public void deleteChallenge(Long memberId, Long challengeId) {
}
}

public void deleteParticipateCertify(Participate participate) {

log.info("participate :::: " + participate.getParticipateId());

for(Certify certify : participate.getCertifies()){

log.info("certify :::: " + certify.getCertifyName());
certifyLikeRepository.deleteAll(certify.getCertifyLikeList());
certifyImageRepository.deleteAll(certify.getCertifyImageList());

certifyRepository.delete(certify);

}
}

private Challenge findChallengeOrThrow(Long challengeId){
return challengeRepository.findById(challengeId).orElseThrow(() -> {
throw new NoSuchIdException("요청하신 챌린지는 존재하지 않습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public List<ChallengeResponseVo> getChallengeByLatest() {

List<Challenge> challenges = jpaQueryFactory
.selectFrom(challenge)
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE))
.or(challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE)))
.groupBy(challenge)
.orderBy(challenge.createdDate.desc())
.fetch();
Expand All @@ -174,8 +173,8 @@ public List<ChallengeResponseVo> getChallengeByParticipate() {

List<Challenge> challenges = jpaQueryFactory
.selectFrom(challenge)
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE))
.or(challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE)))
// .or(challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.fetch();

return makeChallengeResponseVos(challenges);
Expand All @@ -187,8 +186,8 @@ public List<ChallengeResponseVo> getChallengeByLike() {

List<Challenge> challenges = jpaQueryFactory
.selectFrom(challenge)
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE))
.or(challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.where(challenge.challengeStatus.eq(ChallengeStatus.RECRUITING).or(challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE)))
// .or(challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.groupBy(challenge)
.orderBy(challenge.challengeLikes.size().desc())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ private Challenge findChallengeOrThrow(Long challengeId) {
throw new BadRequestException("요청한 챌린지는 존재하지 않습니다.");
});
}

public Participate find(Long participateId) {
return participateRepository.findById(participateId).orElseThrow(() -> {
throw new BadRequestException("요청한 participate는 존재하지 않습니다.");
});
}
}

0 comments on commit 252ae09

Please sign in to comment.