Skip to content

Commit

Permalink
[Feat] : 스터디 참여 신청 정보 조회(거절)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Mar 3, 2024
1 parent 3dbbe0a commit b6a778d
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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> rejectApplyUserData;

@Builder
public FindRejectApplyResponse(Long totalCount, Slice<RejectApplyUserData> rejectApplyUserData) {
this.totalCount = totalCount;
this.rejectApplyUserData = rejectApplyUserData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,4 +18,6 @@ public interface ApplyRepositoryCustom {
List<ApplyUserData> findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable);

List<RequestApplyData> findApplyByUserId(Long userId, Pageable pageable);

List<RejectApplyUserData> findRejectStudyById(Long studyId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -88,4 +90,23 @@ public List<RequestApplyData> findApplyByUserId(Long userId, Pageable pageable)
.limit(pageable.getPageSize() + 1)
.fetch();
}

@Override
public List<RejectApplyUserData> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,13 +13,15 @@
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;
import kr.co.studyhubinu.studyhubserver.exception.apply.SameUserRequestException;
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;
Expand Down Expand Up @@ -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<ApplyUserData> 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> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ spring:
batch:
jdbc:
initialize-schema: ALWAYS
job:
enabled: false

mail:
host: smtp.gmail.com
Expand Down

0 comments on commit b6a778d

Please sign in to comment.