Skip to content

Commit

Permalink
[merge] 게스트에 해당하는 참가한 모임 조회 API 구현
Browse files Browse the repository at this point in the history
[feat] 게스트에 해당하는 참가한 모임 조회 API 구현
  • Loading branch information
lreowy authored Jul 12, 2024
2 parents 892718d + 24de6c9 commit 3417a15
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.pickple.server.api.moim.dto.response.MoimDetailResponse;
import com.pickple.server.api.moim.service.MoimCommandService;
import com.pickple.server.api.moim.service.MoimQueryService;
import com.pickple.server.api.moimsubmission.dto.response.SubmittedMoimByGuestResponse;
import com.pickple.server.api.moimsubmission.dto.response.MoimByGuestResponse;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.response.ApiResponseDto;
import com.pickple.server.global.response.enums.SuccessCode;
Expand Down Expand Up @@ -44,7 +44,7 @@ public ApiResponseDto<MoimDetailResponse> getMoimDetail(@PathVariable Long moimI
}

@GetMapping("/v1/submitted-moim/{moimId}")
public ApiResponseDto<SubmittedMoimByGuestResponse> getSubmittedMoimDetail(@PathVariable Long moimId) {
public ApiResponseDto<MoimByGuestResponse> getSubmittedMoimDetail(@PathVariable Long moimId) {
return ApiResponseDto.success(SuccessCode.SUBMITTED_MOIM_DETAIL_GET_SUCCESS,
moimQueryService.getSubmittedMoimDetail(moimId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.pickple.server.api.moim.dto.response.MoimDescriptionResponse;
import com.pickple.server.api.moim.dto.response.MoimDetailResponse;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.moimsubmission.dto.response.SubmittedMoimByGuestResponse;
import com.pickple.server.api.moimsubmission.dto.response.MoimByGuestResponse;
import com.pickple.server.global.util.DateUtil;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -38,9 +38,9 @@ public MoimDetailResponse getMoimDetail(final Long moimId) {
.build();
}

public SubmittedMoimByGuestResponse getSubmittedMoimDetail(final Long moimId) {
public MoimByGuestResponse getSubmittedMoimDetail(final Long moimId) {
Moim moim = moimRepository.findMoimByIdOrThrow(moimId);
return SubmittedMoimByGuestResponse.builder()
return MoimByGuestResponse.builder()
.title(moim.getTitle())
.hostNickname(moim.getHost().getNickname())
.isOffline(moim.isOffline())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ public ApiResponseDto getSubmittedMoimListByGuest(
return ApiResponseDto.success(SuccessCode.SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS,
moimSubmissionQueryService.getSubmittedMoimListByGuest(guestId, moimSubmissionState));
}

@GetMapping("/v1/guest/{guestId}/completed-moim-list")
public ApiResponseDto getCompletedMoimListByGuest(
@PathVariable Long guestId
) {
return ApiResponseDto.success(SuccessCode.COMPLETED_MOIM_LIST_BY_GUEST_GET_SUCCESS,
moimSubmissionQueryService.getCompletedMoimListByGuest(guestId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Builder;

@Builder
public record SubmittedMoimByGuestResponse(
public record MoimByGuestResponse(
String title,
String hostNickname,
boolean isOffline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MoimSubmissionRepository extends JpaRepository<MoimSubmission, Long> {
boolean existsByMoimAndMoimSubmissionState(Moim moim, MoimSubmissionState moimSubmissionState);

List<MoimSubmission> findAllByGuestId(Long guestId);

List<MoimSubmission> findAllByMoimSubmissionState(MoimSubmissionState moimSubmissionState);

@Query("SELECT ms FROM MoimSubmission ms WHERE ms.guestId = :guestId AND ms.moimSubmissionState = 'COMPLETED'")
List<MoimSubmission> findCompletedMoimSubmissionsByGuest(@Param("guestId") Long guestId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,26 @@ public List<SubmittedMoimByGuestResponse> getSubmittedMoimListByGuest(final Long
.build())
.collect(Collectors.toList());
}

public List<SubmittedMoimByGuestResponse> getCompletedMoimListByGuest(final Long guestId) {
Guest guest = guestRepository.findGuestByIdOrThrow(guestId);
List<MoimSubmission> moimSubmissionList = moimSubmissionRepository.findCompletedMoimSubmissionsByGuest(
guest.getId());

if (moimSubmissionList.isEmpty()) {
throw new CustomException(ErrorCode.MOIM_BY_STATE_NOT_FOUND);
}

return moimSubmissionList.stream()
.map(oneMoimSubmission -> SubmittedMoimByGuestResponse.builder()
.moimId(oneMoimSubmission.getMoim().getId())
.moimSubmissionState(oneMoimSubmission.getMoimSubmissionState())
.title(oneMoimSubmission.getMoim().getTitle())
.hostNickname(oneMoimSubmission.getMoim().getHost().getNickname())
.dateList(oneMoimSubmission.getMoim().getDateList())
.fee(oneMoimSubmission.getMoim().getFee())
.imageUrl(oneMoimSubmission.getMoim().getImageList().getImageUrl1())
.build())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum SuccessCode {
MOIM_BANNER_GET_SUCCESS(20016, HttpStatus.OK, "홈 배너 조회 성공"),
HOST_BY_MOIM_GET_SUCCESS(20017, HttpStatus.OK, "모임에 해당하는 호스트 정보 조회 성공"),
SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20018, HttpStatus.OK, "게스트에 해당하는 신청한 모임 리스트 조회 성공"),
COMPLETED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20019, HttpStatus.OK, "게스트에 해당하는 참가한 모임 리스트 조회 성공"),

//201 Created
MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공");
Expand Down

0 comments on commit 3417a15

Please sign in to comment.