diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java index b1810cdb..7c1d1f28 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java @@ -4,12 +4,16 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.v3.oas.annotations.Operation; -import kr.co.studyhubinu.studyhubserver.apply.dto.request.*; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.AcceptApplyRequest; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.EnrollApplyRequest; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.RejectApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindRejectApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import kr.co.studyhubinu.studyhubserver.apply.service.ApplyService; -import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; @@ -60,6 +64,12 @@ public FindApplyResponse findStudyEnroll(@RequestParam Long studyId, @RequestPar return applyService.findApply(new FindApplyRequest(studyId, inspection), page, size); } + @Operation(summary = "스터디 참여 신청 정보 조회(거절)", description = "해당 스터디 id를 보내주세요.") + @GetMapping("/v1/study-reject") + public FindRejectApplyResponse findRejectApply(UserId userId, @RequestParam Long studyId, @RequestParam int page, @RequestParam int size) { + return applyService.findRejectApply(userId.getId(), studyId, page, size); + } + @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT 보내주시면 됩니다.") @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "페이지", required = true), diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RejectApplyUserData.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RejectApplyUserData.java new file mode 100644 index 00000000..7635d1ba --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RejectApplyUserData.java @@ -0,0 +1,33 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.data; + +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class RejectApplyUserData { + + private final Long id; + private final String nickname; + private final MajorType major; + private final String imageUrl; + private final String introduce; + private final LocalDateTime createdDate; + private final Inspection inspection; + private final String rejectReason; + + @Builder + public RejectApplyUserData(Long id, String nickname, MajorType major, String imageUrl, String introduce, LocalDateTime createdDate, Inspection inspection, String rejectReason) { + this.id = id; + this.nickname = nickname; + this.major = major; + this.imageUrl = imageUrl; + this.introduce = introduce; + this.createdDate = createdDate; + this.inspection = inspection; + this.rejectReason = rejectReason; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindRejectApplyResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindRejectApplyResponse.java new file mode 100644 index 00000000..98204056 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindRejectApplyResponse.java @@ -0,0 +1,19 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.response; + +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RejectApplyUserData; +import lombok.Builder; +import lombok.Getter; +import org.springframework.data.domain.Slice; + +@Getter +public class FindRejectApplyResponse { + + Long totalCount; + Slice rejectApplyUserData; + + @Builder + public FindRejectApplyResponse(Long totalCount, Slice rejectApplyUserData) { + this.totalCount = totalCount; + this.rejectApplyUserData = rejectApplyUserData; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java index c747277c..85c150ac 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java @@ -2,9 +2,9 @@ import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RejectApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import java.util.List; @@ -18,4 +18,6 @@ public interface ApplyRepositoryCustom { List findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable); List findApplyByUserId(Long userId, Pageable pageable); + + List findRejectStudyById(Long studyId, Pageable pageable); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java index e56024de..c54beb10 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java @@ -4,6 +4,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RejectApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; @@ -13,6 +14,7 @@ import java.util.List; +import static kr.co.studyhubinu.studyhubserver.reject.domain.QRejectEntity.rejectEntity; import static kr.co.studyhubinu.studyhubserver.study.domain.QStudyEntity.studyEntity; import static kr.co.studyhubinu.studyhubserver.studypost.domain.QStudyPostEntity.studyPostEntity; import static kr.co.studyhubinu.studyhubserver.user.domain.QUserEntity.userEntity; @@ -88,4 +90,23 @@ public List findApplyByUserId(Long userId, Pageable pageable) .limit(pageable.getPageSize() + 1) .fetch(); } + + @Override + public List findRejectStudyById(Long studyId, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(RejectApplyUserData.class, + userEntity.id, userEntity.nickname, userEntity.major, userEntity.imageUrl, + applyEntity.introduce, applyEntity.createdDate, applyEntity.inspection, rejectEntity.rejectReason)) + .from(applyEntity) + .innerJoin(userEntity).on(applyEntity.userId.eq(userEntity.id)) + .innerJoin(rejectEntity) + .on(applyEntity.userId.eq(rejectEntity.rejectedUserId) + .and(applyEntity.studyId.eq(rejectEntity.studyId))) + .where(applyEntity.studyId.eq(studyId) + .and(applyEntity.inspection.eq(Inspection.REJECT))) + .orderBy(applyEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) + .fetch(); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java index f2f6671d..76046ae6 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java @@ -4,6 +4,7 @@ import kr.co.studyhubinu.studyhubserver.apply.domain.implementations.ApplyWriter; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RejectApplyUserData; import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; import kr.co.studyhubinu.studyhubserver.apply.dto.request.AcceptApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.request.EnrollApplyRequest; @@ -12,6 +13,7 @@ import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindRejectApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; import kr.co.studyhubinu.studyhubserver.common.dto.Converter; import kr.co.studyhubinu.studyhubserver.exception.apply.ApplyNotFoundException; @@ -19,6 +21,7 @@ import kr.co.studyhubinu.studyhubserver.exception.study.PostNotFoundException; import kr.co.studyhubinu.studyhubserver.exception.study.StudyNotFoundException; import kr.co.studyhubinu.studyhubserver.exception.study.StudyPostClosedException; +import kr.co.studyhubinu.studyhubserver.exception.user.UserNotAccessRightException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; import kr.co.studyhubinu.studyhubserver.reject.repository.RejectRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; @@ -64,10 +67,22 @@ public void enroll(UserId userId, EnrollApplyRequest request) { public FindApplyResponse findApply(FindApplyRequest request, final int page, final int size) { Pageable pageable = PageRequest.of(page, size); Slice userData = Converter.toSlice(pageable, applyRepository.findStudyByIdAndInspection(request, pageable)); - return new FindApplyResponse((long) size, userData); } + public FindRejectApplyResponse findRejectApply(Long userId, Long studyId, int page, int size) { + UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + StudyEntity study = studyRepository.findById(studyId).orElseThrow(StudyNotFoundException::new); + validIsMasterUserOfStudy(user, study); + Pageable pageable = PageRequest.of(page, size); + Slice rejectApplyUserData = Converter.toSlice(pageable, applyRepository.findRejectStudyById(studyId, pageable)); + return new FindRejectApplyResponse((long) size, rejectApplyUserData); + } + + private void validIsMasterUserOfStudy(UserEntity user, StudyEntity study) { + if (!study.isMasterOfUser(user.getId())) throw new UserNotAccessRightException(); + } + public FindParticipateApplyResponse getParticipateApply(final UserId userId, final int page, final int size) { UserEntity user = userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); final Pageable pageable = PageRequest.of(page, size); diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java index 8e368d32..688cc77a 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java @@ -50,4 +50,7 @@ public StudyEntity(Long id, String title, String content, LocalDate studyStartDa this.major = major; } + public boolean isMasterOfUser(Long userId) { + return this.masterUserId.equals(userId); + } } diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index a8e2ddc4..cfd8ef26 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -29,6 +29,8 @@ spring: batch: jdbc: initialize-schema: ALWAYS + job: + enabled: false mail: host: smtp.gmail.com