Skip to content
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 @@ -36,14 +36,13 @@ public FestivalVerifyResponse verifyFestival(FestivalVerifyRequest request) {
public FestivalInfoResponse getFestivalInfo(Long userId, Long festivalId) {
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
participantService.validateParticipation(user, festival);
participantService.getParticipantOrThrow(user, festival);
return FestivalInfoResponse.of(festival);
}

@Transactional
public FestivalResponse createFestival(Long userId, FestivalRequest request) {
User host = userService.getUserByIdOrThrow(userId);

festivalService.validateCreateFestival(request);

Festival festival = festivalService.createFestival(host, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ public void modifyMessage(Long userId, Long festivalId, MessageRequest request)
public Participant getParticipant(Long userId, Long festivalId) {
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = participantService.getParticipant(user, festival);
if (participant == null) {
throw new FestimateException(ResponseError.PARTICIPANT_NOT_FOUND);
}
return participant;
return participantService.getParticipantOrThrow(user, festival);
}

@Transactional(readOnly = true)
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/festimate/team/api/facade/PointFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class PointFacade {

@Transactional(readOnly = true)
public PointHistoryResponse getMyPointHistory(Long userId, Long festivalId) {
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = getExistingParticipantOrThrow(userId, festival);
Participant participant = participantService.getParticipantOrThrow(user, festival);
return pointService.getPointHistory(participant);
}

Expand All @@ -53,15 +54,6 @@ public void rechargePoints(Long userId, Long festivalId, RechargePointRequest re
pointService.rechargePoint(participant, request.point());
}

private Participant getExistingParticipantOrThrow(Long userId, Festival festival) {
User user = userService.getUserByIdOrThrow(userId);
Participant participant = participantService.getParticipant(user, festival);
if (participant == null) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
return participant;
}

private void isHost(User user, Festival festival) {
if (!festivalService.isHost(user, festival)) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.festimate.team.domain.point.service.PointService;
import org.festimate.team.domain.user.entity.Gender;
import org.festimate.team.domain.user.service.UserService;
import org.festimate.team.global.exception.FestimateException;
import org.festimate.team.global.response.ResponseError;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -42,7 +40,9 @@ public class MatchingServiceImpl implements MatchingService {
@Transactional
public MatchingStatusResponse createMatching(Long userId, Long festivalId) {
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = getExistingParticipantOrThrow(userId, festival);
Participant participant = participantService.getParticipantOrThrow(
userService.getUserByIdOrThrow(userId), festival
);

isMatchingDateValid(LocalDateTime.now(), festival.getMatchingStartAt());

Expand All @@ -58,22 +58,14 @@ public MatchingStatusResponse createMatching(Long userId, Long festivalId) {
@Override
public MatchingListResponse getMatchingList(Long userId, Long festivalId) {
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = getExistingParticipantOrThrow(userId, festival);
Participant participant = participantService.getParticipantOrThrow(
userService.getUserByIdOrThrow(userId), festival
);

List<MatchingInfo> matchings = getMatchingListByParticipant(participant);
return MatchingListResponse.from(matchings);
}

private Participant getExistingParticipantOrThrow(Long userId, Festival festival) {
Participant participant = participantService.getParticipant(
userService.getUserByIdOrThrow(userId), festival
);
if (participant == null) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
return participant;
}

@Transactional
protected Matching saveMatching(Festival festival, Optional<Participant> targetParticipantOptional, Participant participant) {
Matching matching;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public interface ParticipantService {
@Transactional
Participant createParticipant(User user, Festival festival, ProfileRequest request);

Participant getParticipant(User user, Festival festival);
Participant getParticipantOrThrow(User user, Festival festival);

void validateParticipation(User user, Festival festival);
Participant getParticipant(User user, Festival festival);

Participant getParticipantById(Long participantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -46,10 +47,9 @@ public Participant getParticipant(User user, Festival festival) {
}

@Override
public void validateParticipation(User user, Festival festival) {
if (getParticipant(user, festival) == null) {
throw new FestimateException(ResponseError.PARTICIPANT_NOT_FOUND);
}
public Participant getParticipantOrThrow(User user, Festival festival) {
return Optional.ofNullable(participantRepository.getParticipantByUserAndFestival(user, festival))
.orElseThrow(() -> new FestimateException(ResponseError.PARTICIPANT_NOT_FOUND));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void setUp() {
void entryFestival_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);

var response = participantFacade.entryFestival(1L, 1L);

Expand All @@ -86,7 +86,7 @@ void createParticipant_success() {
void getParticipantProfile_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);

var response = participantFacade.getParticipantProfile(1L, 1L);

Expand All @@ -98,7 +98,7 @@ void getParticipantProfile_success() {
void getParticipantSummary_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);
when(pointService.getTotalPointByParticipant(participant)).thenReturn(10);

var response = participantFacade.getParticipantSummary(1L, 1L);
Expand All @@ -111,7 +111,7 @@ void getParticipantSummary_success() {
void getParticipantType_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);

var response = participantFacade.getParticipantType(1L, 1L);

Expand All @@ -123,7 +123,7 @@ void getParticipantType_success() {
void modifyMessage_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);

MessageRequest request = new MessageRequest("새로운 소개", "새로운 메세지");

Expand All @@ -138,7 +138,8 @@ void modifyMessage_success() {
void getParticipant_fail() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(null);
when(participantService.getParticipantOrThrow(user, festival))
.thenThrow(new FestimateException(ResponseError.PARTICIPANT_NOT_FOUND));

assertThatThrownBy(() -> participantFacade.getParticipant(1L, 1L))
.isInstanceOf(FestimateException.class)
Expand All @@ -148,20 +149,15 @@ void getParticipant_fail() {
@Test
@DisplayName("같은 유저가 같은 페스티벌에 중복 참가하려고 하면 예외가 발생해야 한다")
void createParticipant_duplicate_fail() {
// given
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
// 이미 참가자가 존재한다고 설정
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipant(user, festival)).thenReturn(participant); // 이미 존재

// createParticipant 호출 시 예외를 직접 발생시키도록 설정
when(participantService.createParticipant(any(), any(), any()))
.thenThrow(new FestimateException(ResponseError.PARTICIPANT_ALREADY_EXISTS));

// when & then
assertThatThrownBy(() -> participantFacade.createParticipant(1L, 1L,
new ProfileRequest(TypeResult.HEALING, "자기소개", "메시지")))
.isInstanceOf(FestimateException.class)
.hasMessageContaining(ResponseError.PARTICIPANT_ALREADY_EXISTS.getMessage());

verify(participantService, never()).createParticipant(any(), any(), any());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void getMyPointHistory_success() {
// given
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(userService.getUserByIdOrThrow(2L)).thenReturn(participantUser);
when(participantService.getParticipant(participantUser, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(participantUser, festival)).thenReturn(participant);

PointHistoryResponse dummyResponse = PointHistoryResponse.from(5, List.of());
when(pointService.getPointHistory(participant)).thenReturn(dummyResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void getMatchingList_success() {

when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(participantService.getParticipantOrThrow(user, festival)).thenReturn(participant);
when(matchingRepository.findAllMatchingsByApplicantParticipant(participant))
.thenReturn(List.of(matching2, matching1));

Expand Down