Skip to content

Commit

Permalink
[�merge] 모임에 해당하는 신청자 전체 조회 api 구현
Browse files Browse the repository at this point in the history
[feat] 모임에 해당하는 신청자 전체 조회 api 구현
  • Loading branch information
bo-ram-bo-ram authored Jul 13, 2024
2 parents 57ee2a8 + 59d83a9 commit 65edc87
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface MoimRepository extends JpaRepository<Moim, Long> {

List<Moim> findMoimByHostId(Long hostId);

List<Moim> findMoimListById(Long Id);

default Moim findMoimByIdOrThrow(Long id) {
return findMoimById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public ApiResponseDto getCompletedMoimListByGuest(
moimSubmissionQueryService.getCompletedMoimListByGuest(guestId));
}

@GetMapping("/v1/moim/{moimId}/submitter-list")
public ApiResponseDto getSubmitterListByMoim(@PathVariable Long moimId) {
return ApiResponseDto.success(SuccessCode.SUBMITTER_LIST_BY_MOIM_GET_SUCCESS,
moimSubmissionQueryService.getSubmitterListByMoim(moimId));

@PatchMapping("/v1/moim/{moimId}/submitter/{submitterId}")
public ApiResponseDto updateSubmitterState(@PathVariable Long moimId, @PathVariable Long submitterId) {
moimSubmissionCommandService.updateSubmissionState(moimId, submitterId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pickple.server.api.moimsubmission.domain;

public record SubmitterInfo(
Long submitterId, //guest id
String nickname, //신청자 닉네임
String submitterImageUrl, //신청자 프로필 이미지
String submittedDate //신청한 날짜 및 시간
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pickple.server.api.moimsubmission.dto.response;

import com.pickple.server.api.moimsubmission.domain.SubmitterInfo;
import lombok.Builder;

@Builder
public record MoimSubmissionByMoimResponse(
int maxGuest, //신청자 최대 인원
Boolean isApprovable, //승인가능여부
SubmitterInfo submitterList //신청자 리스트
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface MoimSubmissionRepository extends JpaRepository<MoimSubmission,

MoimSubmission findBymoimIdAndGuestId(Long moimId, Long guestId);

List<MoimSubmission> findMoimListByMoimId(Long moimId);

@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 @@ -3,12 +3,19 @@
import com.pickple.server.api.guest.domain.Guest;
import com.pickple.server.api.guest.repository.GuestRepository;
import com.pickple.server.api.host.dto.response.SubmittionDetailResponse;
import com.pickple.server.api.moim.domain.Moim;
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.domain.SubmitterInfo;
import com.pickple.server.api.moimsubmission.dto.response.MoimSubmissionByMoimResponse;
import com.pickple.server.api.moimsubmission.repository.MoimSubmissionRepository;
import com.pickple.server.global.exception.CustomException;
import com.pickple.server.global.response.enums.ErrorCode;
import com.pickple.server.global.util.DateTimeUtil;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -85,4 +92,49 @@ public List<SubmittedMoimByGuestResponse> getCompletedMoimListByGuest(final Long
.build())
.collect(Collectors.toList());
}

public List<MoimSubmissionByMoimResponse> getSubmitterListByMoim(Long moimId) {
List<MoimSubmission> moimSubmissionList = moimSubmissionRepository.findMoimListByMoimId(moimId);

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

return moimSubmissionList.stream()
.map(oneMoimSubmission -> MoimSubmissionByMoimResponse.builder()
.maxGuest(oneMoimSubmission.getMoim().getMaxGuest())
.isApprovable(isApprovable(oneMoimSubmission.getMoim()))
.submitterList(getSubmitterInfo(oneMoimSubmission.getGuestId()))
.build())
.collect(Collectors.toList());
}

private boolean isApprovable(Moim moim) {
// 모임일
System.out.println(moim.getId());
LocalDate date = moim.getDateList().getDate();

// 마감일: 신청일 + 3일의 자정
LocalDateTime deadline = date.minusDays(3).atTime(LocalTime.MIDNIGHT);

// 현재 시간
LocalDateTime now = LocalDateTime.now();

// 승인 가능 여부: 현재 시간이 마감일 이후인지 확인
return now.isAfter(deadline);
}

public SubmitterInfo getSubmitterInfo(Long guestId) {
// Guest 객체를 가져옴
Guest guest = guestRepository.findById(guestId)
.orElseThrow(() -> new CustomException(ErrorCode.GUEST_NOT_FOUND));

// SubmitterInfo 객체 생성
return new SubmitterInfo(
guest.getId(),
guest.getNickname(),
guest.getImageUrl(),
DateTimeUtil.refineDateAndTime(guest.getCreatedAt())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum ErrorCode {
MISSING_REQUIRED_HEADER(40005, HttpStatus.BAD_REQUEST, "필수 헤더가 누락되었습니다."),
MISSING_REQUIRED_PARAMETER(40006, HttpStatus.BAD_REQUEST, "필수 파라미터가 누락되었습니다."),
DUPLICATION_MOIM_SUBMISSION(40007, HttpStatus.BAD_REQUEST, "이미 대기중인 모임입니다."),
MOIM_SUBMISSION_NOT_FOUND(40008, HttpStatus.BAD_REQUEST, "해당 모임에 신청한 내역이 없습니다."),
SUBMITTER_BY_MOIM_NOT_FOUND(40009, HttpStatus.BAD_REQUEST, "해당 모임에 신청자가 없습니다."),

// 401 Unauthorized
ACCESS_TOKEN_EXPIRED(40100, HttpStatus.UNAUTHORIZED, "액세스 토큰이 만료되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum SuccessCode {
SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20018, HttpStatus.OK, "게스트에 해당하는 신청한 모임 리스트 조회 성공"),
SUBMISSION_DETAIL_GET_SUCCESS(20019, HttpStatus.OK, "신청자 해당하는 신청 내역 조회 성공"),
COMPLETED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20019, HttpStatus.OK, "게스트에 해당하는 참가한 모임 리스트 조회 성공"),
SUBMITTER_LIST_BY_MOIM_GET_SUCCESS(20020, HttpStatus.OK, "모임에 해당하는 신청자 전체 조회 성공"),
SUBMITTER_APPROVE_SUCCESS(20020, HttpStatus.OK, "신청자 승인 성공"),

//201 Created
Expand Down

0 comments on commit 65edc87

Please sign in to comment.