Skip to content

Commit

Permalink
[feat] 게스트에 해당하는 신청한 모임 조회 API 구현
Browse files Browse the repository at this point in the history
[feat] 게스트에 해당하는 신청한 모임 조회 API 구현
  • Loading branch information
lreowy authored Jul 12, 2024
2 parents 63e1575 + 80b4fe7 commit 3166860
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.pickple.server.api.moim.domain.enums.Category;
import com.pickple.server.api.moim.dto.request.MoimCreateRequest;
import com.pickple.server.api.moim.dto.response.MoimDetailResponse;
import com.pickple.server.api.moim.dto.response.SubmittedMoimResponse;
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.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<SubmittedMoimResponse> getSubmittedMoimDetail(@PathVariable Long moimId) {
public ApiResponseDto<SubmittedMoimByGuestResponse> 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
@@ -0,0 +1,17 @@
package com.pickple.server.api.moim.dto.response;

import com.pickple.server.api.moim.domain.DateInfo;
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import lombok.Builder;

@Builder
public record SubmittedMoimByGuestResponse(
Long moimId,
MoimSubmissionState moimSubmissionState,
String title,
String hostNickname,
DateInfo dateList,
int fee,
String imageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.pickple.server.api.moim.dto.response.MoimByCategoryResponse;
import com.pickple.server.api.moim.dto.response.MoimDescriptionResponse;
import com.pickple.server.api.moim.dto.response.MoimDetailResponse;
import com.pickple.server.api.moim.dto.response.SubmittedMoimResponse;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.moimsubmission.dto.response.SubmittedMoimByGuestResponse;
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 SubmittedMoimResponse getSubmittedMoimDetail(final Long moimId) {
public SubmittedMoimByGuestResponse getSubmittedMoimDetail(final Long moimId) {
Moim moim = moimRepository.findMoimByIdOrThrow(moimId);
return SubmittedMoimResponse.builder()
return SubmittedMoimByGuestResponse.builder()
.title(moim.getTitle())
.hostNickname(moim.getHost().getNickname())
.isOffline(moim.isOffline())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.pickple.server.api.moimsubmission.controller;

import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import com.pickple.server.api.moimsubmission.dto.request.MoimSubmitRequest;
import com.pickple.server.api.moimsubmission.service.MoimSubmissionCommandService;
import com.pickple.server.api.moimsubmission.service.MoimSubmissionQueryService;
import com.pickple.server.global.common.annotation.GuestId;
import com.pickple.server.global.response.ApiResponseDto;
import com.pickple.server.global.response.enums.SuccessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -18,6 +22,7 @@
public class MoimSubmissionController {

private final MoimSubmissionCommandService moimSubmissionCommandService;
private final MoimSubmissionQueryService moimSubmissionQueryService;

@PostMapping("/v1/moim/{moimId}")
public ApiResponseDto createMoimSubmission(
Expand All @@ -28,4 +33,13 @@ public ApiResponseDto createMoimSubmission(
moimSubmissionCommandService.createMoimSubmission(moimId, guestId, moimSubmitRequest);
return ApiResponseDto.success(SuccessCode.MOIM_SUBMISSION_POST_SUCCESS);
}

@GetMapping("/v1/guest/{guestId}/submitted-moim-list")
public ApiResponseDto getSubmittedMoimListByGuest(
@PathVariable Long guestId,
@RequestParam MoimSubmissionState moimSubmissionState
) {
return ApiResponseDto.success(SuccessCode.SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS,
moimSubmissionQueryService.getSubmittedMoimListByGuest(guestId, moimSubmissionState));
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.pickple.server.api.moim.dto.response;
package com.pickple.server.api.moimsubmission.dto.response;

import com.pickple.server.api.moim.domain.DateInfo;
import lombok.Builder;

@Builder
public record SubmittedMoimResponse(
public record SubmittedMoimByGuestResponse(
String title,
String hostNickname,
boolean isOffline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moimsubmission.domain.MoimSubmission;
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

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

List<MoimSubmission> findAllByGuestId(Long guestId);

List<MoimSubmission> findAllByMoimSubmissionState(MoimSubmissionState moimSubmissionState);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.pickple.server.api.moimsubmission.service;

import com.pickple.server.api.guest.domain.Guest;
import com.pickple.server.api.guest.repository.GuestRepository;
import com.pickple.server.api.moim.dto.response.SubmittedMoimByGuestResponse;
import com.pickple.server.api.moimsubmission.domain.MoimSubmission;
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import com.pickple.server.api.moimsubmission.repository.MoimSubmissionRepository;
import com.pickple.server.global.exception.CustomException;
import com.pickple.server.global.response.enums.ErrorCode;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MoimSubmissionQueryService {

private final GuestRepository guestRepository;
private final MoimSubmissionRepository moimSubmissionRepository;

public List<SubmittedMoimByGuestResponse> getSubmittedMoimListByGuest(final Long guestId,
final MoimSubmissionState moimSubmissionState) {
Guest guest = guestRepository.findGuestByIdOrThrow(guestId);
List<MoimSubmission> moimSubmissionList;

if (moimSubmissionState.equals(MoimSubmissionState.ALL)) {
moimSubmissionList = moimSubmissionRepository.findAllByGuestId(guest.getId());
} else {
moimSubmissionList = moimSubmissionRepository.findAllByMoimSubmissionState(moimSubmissionState);
}

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 @@ -30,7 +30,7 @@ public enum ErrorCode {
GUEST_NOT_FOUND(40403, HttpStatus.NOT_FOUND, "존재하지 않는 게스트입니다"),
MOIM_NOT_FOUND(40404, HttpStatus.NOT_FOUND, "존재하지 않는 모임입니다."),
HOST_NOT_FOUND(40405, HttpStatus.NOT_FOUND, "존재하지 않는 호스트입니다"),

MOIM_BY_STATE_NOT_FOUND(40406, HttpStatus.NOT_FOUND, "상태에 맞는 모임이 없습니다"),
// Method Not Allowed Error 405
METHOD_NOT_ALLOWED(40500, HttpStatus.METHOD_NOT_ALLOWED, "지원하지 않는 메소드입니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum SuccessCode {
NOTICE_LIST_GET_SUCCESS(20011, HttpStatus.OK, "공지사항 리스트 조회 성공"),
MOIM_DESCRIPTION_GET_SUCCESS(20012, HttpStatus.OK, "모임에 해당하는 소개 조회 성공"),
MOIM_QUESTION_LIST_GET_SUCCESS(20013, HttpStatus.OK, "모임 질문 목록 조회 성공"),
SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20014, HttpStatus.OK, "게스트에 해당하는 신청한 모임 리스트 조회 성공"),
MOIM_BANNER_GET_SUCCESS(30014, HttpStatus.OK, "홈 배너 조회 성공"),

//201 Created
Expand Down

0 comments on commit 3166860

Please sign in to comment.