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 @@ -28,15 +28,15 @@ public FestivalVerifyResponse verifyFestival(FestivalVerifyRequest request) {

@Transactional(readOnly = true)
public FestivalInfoResponse getFestivalInfo(Long userId, Long festivalId) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
participantService.validateParticipation(user, festival);
return FestivalInfoResponse.of(festival);
}

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

festivalService.validateCreateFestival(request);

Expand All @@ -46,7 +46,7 @@ public FestivalResponse createFestival(Long userId, FestivalRequest request) {

@Transactional(readOnly = true)
public List<UserFestivalResponse> getUserFestivals(Long userId, String status) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
return participantService.getFestivalsByUser(user, status)
.stream()
.map(UserFestivalResponse::from)
Expand All @@ -55,7 +55,7 @@ public List<UserFestivalResponse> getUserFestivals(Long userId, String status) {

@Transactional(readOnly = true)
public List<AdminFestivalResponse> getAllFestivals(Long userId) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
List<Festival> festivals = festivalService.getAllFestivals(user);
return festivals.stream()
.map(AdminFestivalResponse::of)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class ParticipantFacade {

@Transactional(readOnly = true)
public EntryResponse entryFestival(Long userId, Long festivalId) {
User user = userService.getUserById(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = participantService.getParticipant(user, festival);
Participant participant = getParticipant(userId, festivalId);
return EntryResponse.of(participant);
}

@Transactional
public EntryResponse createParticipant(Long userId, Long festivalId, ProfileRequest request) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);

if (participantService.getParticipant(user, festival) != null) {
throw new FestimateException(ResponseError.PARTICIPANT_ALREADY_EXISTS);
}
Participant participant = participantService.createParticipant(user, festival, request);
matchingService.matchPendingParticipants(participant);

Expand Down Expand Up @@ -74,7 +74,7 @@ public void modifyMessage(Long userId, Long festivalId, MessageRequest request)

@Transactional(readOnly = true)
public Participant getParticipant(Long userId, Long festivalId) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = participantService.getParticipant(user, festival);
if (participant == null) {
Expand All @@ -85,7 +85,7 @@ public Participant getParticipant(Long userId, Long festivalId) {

@Transactional(readOnly = true)
public List<SearchParticipantResponse> getParticipantByNickname(Long userId, Long festivalId, String nickname) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
isHost(user, festival);
List<Participant> participants = participantService.getParticipantByNickname(festival, nickname);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/festimate/team/api/facade/PointFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public PointHistoryResponse getMyPointHistory(Long userId, Long festivalId) {

@Transactional(readOnly = true)
public PointHistoryResponse getParticipantPointHistory(Long userId, Long festivalId, Long participantId) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
isHost(user, festival);
Participant participant = participantService.getParticipantById(participantId);
Expand All @@ -42,7 +42,7 @@ public PointHistoryResponse getParticipantPointHistory(Long userId, Long festiva

@Transactional
public void rechargePoints(Long userId, Long festivalId, RechargePointRequest request) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
isHost(user, festival);

Expand All @@ -54,7 +54,7 @@ public void rechargePoints(Long userId, Long festivalId, RechargePointRequest re
}

private Participant getExistingParticipantOrThrow(Long userId, Festival festival) {
User user = userService.getUserById(userId);
User user = userService.getUserByIdOrThrow(userId);
Participant participant = participantService.getParticipant(user, festival);
if (participant == null) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MatchingListResponse getMatchingList(Long userId, Long festivalId) {

private Participant getExistingParticipantOrThrow(Long userId, Festival festival) {
Participant participant = participantService.getParticipant(
userService.getUserById(userId), festival
userService.getUserByIdOrThrow(userId), festival
);
if (participant == null) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface UserService {

String getUserNickname(Long userId);

User getUserById(Long userId);
User getUserByIdOrThrow(Long userId);

void validateRefreshToken(User user, String refreshToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public User signUp(SignUpRequest request, String platformId) {

@Override
public String getUserNickname(Long userId) {
getUserById(userId);
getUserByIdOrThrow(userId);
return userRepository.findNicknameByUserId(userId);
}

@Override
public User getUserById(Long userId) {
public User getUserByIdOrThrow(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new FestimateException(ResponseError.USER_NOT_FOUND));
}
Expand All @@ -69,7 +69,7 @@ public Long getUserIdByPlatformId(String platformId) {
@Override
@Transactional
public void updateRefreshToken(Long userId, String refreshToken) {
User user = getUserById(userId);
User user = getUserByIdOrThrow(userId);
user.updateRefreshToken(refreshToken);
userRepository.save(user);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/festimate/team/infra/jwt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private String buildRefreshToken(Long userId, SecretKey secretKey) {
@Transactional
public TokenResponse reIssueToken(final String refreshToken) {
Long userId = parseTokenAndGetUserId(refreshToken);
User findUser = userService.getUserById(userId);
User findUser = userService.getUserByIdOrThrow(userId);
String extractPrefixToken = refreshToken.split(" ")[1];
isValidRefreshToken(findUser, extractPrefixToken);
String renewRefreshToken = createRefreshToken(userId);
Expand All @@ -100,7 +100,7 @@ public Long parseTokenAndGetUserId(String token) {
SecretKey secretKey = getSecretKey();
Long userId = parseTokenAndGetUserId(secretKey, splitToken);

if (userService.getUserById(userId).getRefreshToken() == null) {
if (userService.getUserByIdOrThrow(userId).getRefreshToken() == null) {
throw new FestimateException(ResponseError.INVALID_TOKEN);
}
return userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void getFestivalInfo_success() {
// given
Festival festival = MockFactory.mockFestival(user, 1L, LocalDate.now(), LocalDate.now().plusDays(1));

when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);

// user가 참가자인지 검증
Expand Down Expand Up @@ -97,7 +97,7 @@ void createFestival_success() {

Festival festival = MockFactory.mockFestival(user, 100L, request.startDate(), request.endDate());

when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.createFestival(user, request)).thenReturn(festival);

// when
Expand All @@ -113,7 +113,7 @@ void getUserFestivals_success() {
// given
Festival festival = MockFactory.mockFestival(user, 200L, LocalDate.now(), LocalDate.now().plusDays(2));

when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(participantService.getFestivalsByUser(user, "ALL")).thenReturn(List.of(festival));

// when
Expand All @@ -131,7 +131,7 @@ void getAllFestivals_success() {
Festival festival1 = MockFactory.mockFestival(user, 1L, LocalDate.now(), LocalDate.now().plusDays(1));
Festival festival2 = MockFactory.mockFestival(user, 2L, LocalDate.now().minusDays(1), LocalDate.now().plusDays(2));

when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getAllFestivals(user)).thenReturn(List.of(festival1, festival2));

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.festimate.team.api.facade;

import org.festimate.team.api.participant.dto.MessageRequest;
import org.festimate.team.api.participant.dto.ProfileRequest;
import org.festimate.team.common.mock.MockFactory;
import org.festimate.team.domain.festival.entity.Festival;
import org.festimate.team.domain.festival.service.FestivalService;
Expand Down Expand Up @@ -58,7 +59,7 @@ void setUp() {
@Test
@DisplayName("참가자 입장 성공")
void entryFestival_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);

Expand All @@ -70,7 +71,7 @@ void entryFestival_success() {
@Test
@DisplayName("참가자 생성 성공")
void createParticipant_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.createParticipant(any(), any(), any())).thenReturn(participant);

Expand All @@ -83,7 +84,7 @@ void createParticipant_success() {
@Test
@DisplayName("내 프로필 조회 성공")
void getParticipantProfile_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);

Expand All @@ -95,7 +96,7 @@ void getParticipantProfile_success() {
@Test
@DisplayName("포인트 포함 요약정보 조회 성공")
void getParticipantSummary_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(pointService.getTotalPointByParticipant(participant)).thenReturn(10);
Expand All @@ -108,7 +109,7 @@ void getParticipantSummary_success() {
@Test
@DisplayName("자세한 프로필 조회 성공")
void getParticipantType_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);

Expand All @@ -120,7 +121,7 @@ void getParticipantType_success() {
@Test
@DisplayName("메시지 수정 성공")
void modifyMessage_success() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);

Expand All @@ -135,12 +136,32 @@ void modifyMessage_success() {
@Test
@DisplayName("참가자 조회 실패 시 예외 발생")
void getParticipant_fail() {
when(userService.getUserById(1L)).thenReturn(user);
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(null);

assertThatThrownBy(() -> participantFacade.getParticipant(1L, 1L))
.isInstanceOf(FestimateException.class)
.hasMessageContaining(ResponseError.PARTICIPANT_NOT_FOUND.getMessage());
}

@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);

// 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());
}
}
10 changes: 5 additions & 5 deletions src/test/java/org/festimate/team/api/facade/PointFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void setUp() {
void getMyPointHistory_success() {
// given
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(userService.getUserById(2L)).thenReturn(participantUser);
when(userService.getUserByIdOrThrow(2L)).thenReturn(participantUser);
when(participantService.getParticipant(participantUser, festival)).thenReturn(participant);

PointHistoryResponse dummyResponse = PointHistoryResponse.from(5, List.of());
Expand All @@ -78,7 +78,7 @@ void getMyPointHistory_success() {
@DisplayName("다른 참가자의 포인트 내역 조회 성공 (호스트 권한)")
void getParticipantPointHistory_success() {
// given
when(userService.getUserById(1L)).thenReturn(host);
when(userService.getUserByIdOrThrow(1L)).thenReturn(host);
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(festivalService.isHost(host, festival)).thenReturn(true);
when(participantService.getParticipantById(200L)).thenReturn(participant);
Expand All @@ -99,7 +99,7 @@ void rechargePoints_success() {
// given
RechargePointRequest request = new RechargePointRequest(200L, 5);

when(userService.getUserById(1L)).thenReturn(host);
when(userService.getUserByIdOrThrow(1L)).thenReturn(host);
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(festivalService.isHost(host, festival)).thenReturn(true);
when(participantService.getParticipantById(200L)).thenReturn(participant);
Expand All @@ -117,7 +117,7 @@ void rechargePoints_notHost_throws() {
User attacker = MockFactory.mockUser("악당", Gender.MAN, 999L);
RechargePointRequest request = new RechargePointRequest(200L, 5);

when(userService.getUserById(999L)).thenReturn(attacker);
when(userService.getUserByIdOrThrow(999L)).thenReturn(attacker);
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(festivalService.isHost(attacker, festival)).thenReturn(false);

Expand All @@ -135,7 +135,7 @@ void rechargePoints_participantMismatch_throws() {

RechargePointRequest request = new RechargePointRequest(300L, 5);

when(userService.getUserById(1L)).thenReturn(host);
when(userService.getUserByIdOrThrow(1L)).thenReturn(host);
when(festivalService.getFestivalByIdOrThrow(100L)).thenReturn(festival);
when(festivalService.isHost(host, festival)).thenReturn(true);
when(participantService.getParticipantById(300L)).thenReturn(otherParticipant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void getMatchingList_success() {
.build();

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