Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 챌린지 참가 버그 수정 #327

Merged
merged 1 commit into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ccc.keewedomain.service.insight.query.InsightQueryDomainService;
import ccc.keewedomain.service.user.query.ProfileQueryDomainService;
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;
Expand All @@ -45,6 +46,7 @@
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Slf4j
public class ChallengeApiService {

private final ChallengeParticipateQueryDomainService challengeParticipateQueryDomainService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public static Challenge of(User writer, String name, String interest, String int

public ChallengeParticipation participate(User challenger, String myTopic, int insightPerWeek, int duration) {
ChallengeParticipation participation = ChallengeParticipation.of(
challenger,
this,
myTopic,
insightPerWeek,
duration);
challenger,
this,
myTopic,
insightPerWeek,
duration
);
getParticipationList().add(participation);
this.deleted = false;
return participation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ccc.keewedomain.persistence.domain.challenge.Challenge;
import ccc.keewedomain.persistence.domain.challenge.ChallengeParticipation;
import ccc.keewedomain.persistence.domain.user.User;
import ccc.keewedomain.persistence.repository.challenge.ChallengeParticipationRepository;
import ccc.keewedomain.persistence.repository.challenge.ChallengeRepository;
import ccc.keewedomain.service.challenge.query.ChallengeParticipateQueryDomainService;
import ccc.keewedomain.service.challenge.query.ChallengeQueryDomainService;
Expand All @@ -19,15 +20,18 @@
import java.time.Period;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

@RequiredArgsConstructor
@Service
@Slf4j
public class ChallengeCommandDomainService {

private final ChallengeRepository challengeRepository;
private final ChallengeParticipationRepository challengeParticipationRepository;
private final ChallengeQueryDomainService challengeQueryDomainService;
private final ChallengeParticipateQueryDomainService challengeParticipateQueryDomainService;
private final UserDomainService userDomainService;
Expand All @@ -54,7 +58,11 @@ public ChallengeParticipation participate(ChallengeParticipateDto dto) {
Assert.isTrue(!challenger.isDeleted(), "탈퇴한 사용자는 챌린지에 참여할 수 없어요.");
this.exitCurrentChallengeIfExist(challenger);
Challenge challenge = challengeQueryDomainService.getByIdOrElseThrow(dto.getChallengeId());
return challenge.participate(challenger, dto.getMyTopic(), dto.getInsightPerWeek(), dto.getDuration());
ChallengeParticipation participate = challenge.participate(challenger, dto.getMyTopic(), dto.getInsightPerWeek(), dto.getDuration());
challengeRepository.save(challenge);
challengeParticipationRepository.save(participate);
log.info("[ChallengeCommandDomainService] 챌린지 참여 완료 - userId({}), challengeId({})", challenger.getId(), challenge.getId());
return participate;
});
}

Expand Down