Skip to content

Commit

Permalink
fix: 챌린지 삭제 api - 인증 예시 이미지 삭제 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
daeunkwak committed Aug 26, 2023
1 parent 2fc901f commit e8d2d2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.certifyExample.repository.CertifyExampleImageRepository;
import com.cmc.domains.member.repository.MemberRepository;
import com.cmc.domains.participate.repository.ParticipateRepository;
import com.cmc.member.Member;
Expand All @@ -34,6 +35,7 @@ public class CertifyService {
private final ChallengeRepository challengeRepository;
private final MemberRepository memberRepository;
private final CertifyLikeRepository certifyLikeRepository;
private final CertifyExampleImageRepository certifyExampleImageRepository;

// 인증 생성
public Certify create(Long challengeId, String certifyName, String certifyContent, Long memberId) {
Expand Down Expand Up @@ -130,16 +132,17 @@ public void deleteChallenge(Long memberId, Long challengeId) {
}

// TODO : 생성자 검토
// for(Participate participate : member.getParticipates()){
// if(participate.getChallenge().equals(challenge)){
// if(!participate.getIsCreator()){
// throw new CiderException("챌린지를 삭제할 권한이 없습니다.");
// }
// else{
// challengeRepository.deleteById(challengeId);
// }
// }
// }
for(Participate participate : member.getParticipates()){
if(participate.getChallenge().equals(challenge)){
if(!participate.getIsCreator()){
throw new CiderException("챌린지를 삭제할 권한이 없습니다.");
}
else{
certifyExampleImageRepository.deleteAll(challenge.getCertifyExampleImageList());
challengeRepository.deleteById(challengeId);
}
}
}
}

private Challenge findChallengeOrThrow(Long challengeId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -13,6 +14,7 @@
@Data
@Builder
@AllArgsConstructor
@Slf4j
public class OngoingChallengeResponseDto {

@Schema(description = "챌린지 제목", example = "소비습관 고치기")
Expand All @@ -32,6 +34,7 @@ public class OngoingChallengeResponseDto {

public static OngoingChallengeResponseDto from(Challenge challenge, Integer certifyNum){

log.info("challengeID :::::::: " + challenge.getChallengeId());
return new OngoingChallengeResponseDtoBuilder()
.challengeName(challenge.getChallengeName())
.challengeBranch(String.valueOf(challenge.getChallengeBranch()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public List<Challenge> getMyOngoingChallenge(Long memberId) {
return jpaQueryFactory.selectFrom(challenge)
.leftJoin(participate).on(challenge.challengeId.eq(participate.challenge.challengeId))
.where(participate.participateStatus.eq(ParticipateStatus.ONGOING)
.and(participate.challenge.challengeStatus.eq(ChallengeStatus.POSSIBLE)
.or(participate.challenge.challengeStatus.eq(ChallengeStatus.IMPOSSIBLE)))
.and(participate.member.memberId.eq(memberId)))
.fetch();
}
Expand Down

0 comments on commit e8d2d2c

Please sign in to comment.