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 cb44d67b..e25ed878 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 @@ -6,6 +6,8 @@ import io.swagger.v3.oas.annotations.Operation; import kr.co.studyhubinu.studyhubserver.apply.dto.request.*; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; +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; @@ -26,48 +28,56 @@ public class ApplyController { @Operation(summary = "스터디 참여 신청", description = "studyId와 신청자가 작성한 글을 json 형태로 입력해주세요.") @PostMapping("/v1/study") public ResponseEntity enrollStudy(UserId userId, EnrollApplyRequest request) { - applyService.enroll(userId.getId(), request); - return ResponseEntity.ok().build(); - } - - @Operation(summary = "스터디 참여 신청 정보 수정", - description = "참여 신청한 유저의 Id, 해당 스터디 Id, 변경하려는 상태(ACCEPT, STANDBY, REJECT)를 보내주세요") - @PutMapping("/v1/study") - public ResponseEntity updateStudyInspection(UpdateApplyRequest request) { - applyService.update(request); + applyService.enroll(userId, request); return ResponseEntity.ok().build(); } @Operation(summary = "스터디 참여 신청 거절", - description = "JWT토큰 헤더에 보내주시면 됩니다!") + description = "JWT 헤더에 보내주시면 됩니다!") @PutMapping("/v1/study-reject") public ResponseEntity rejectApply(@RequestBody @Valid final RejectApplyRequest rejectApplyRequest, final UserId userId) { - applyService.rejectApply(rejectApplyRequest, userId.getId()); + applyService.rejectApply(rejectApplyRequest, userId); return ResponseEntity.ok().build(); } - @Operation(summary = "스터디 참여 신청 거절", - description = "JWT토큰 헤더에 보내주시면 됩니다!") + @Operation(summary = "스터디 참여 신청 수락", + description = "JWT 헤더에 보내주시면 됩니다!") @PutMapping("/v1/study-accept") public ResponseEntity acceptApply(@RequestBody @Valid final AcceptApplyRequest acceptApplyRequest, final UserId userId) { - applyService.acceptApply(acceptApplyRequest, userId.getId()); + applyService.acceptApply(acceptApplyRequest, userId); return ResponseEntity.ok().build(); } - @Operation(summary = "스터디 참여 신청 정보 조회", description = "해당 스터디 Id를 보내주세요.") + @Operation(summary = "스터디 참여 신청 정보 조회", description = "해당 스터디 Id, 신청 정보를 파라미터로 보내주세요.") @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "페이지", required = true), - @ApiImplicitParam(name = "size", value = "사이즈", required = true) + @ApiImplicitParam(name = "size", value = "사이즈", required = true), + @ApiImplicitParam(name = "studyId", value = "스터디 식별자", required = true), + @ApiImplicitParam(name = "inspection", value = "상태", required = true) }) - @GetMapping("/v1/study") - public FindApplyResponse findStudyEnroll(FindApplyRequest request, @RequestParam int page, @RequestParam int size) { - return applyService.findApply(request, page, size); + @GetMapping("/v2/study") + public FindApplyResponse findStudyEnroll(@RequestParam Long studyId, @RequestParam Inspection inspection, @RequestParam int page, @RequestParam int size) { + return applyService.findApply(new FindApplyRequest(studyId, inspection), page, size); } - @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT토큰 보내주시면 됩니다") + @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT 보내주시면 됩니다.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "페이지", required = true), + @ApiImplicitParam(name = "size", value = "사이즈", required = true) + }) @GetMapping("/v1/participated-study") public ResponseEntity getParticipateApply(UserId userId, @RequestParam int page, @RequestParam int size) { - return ResponseEntity.ok().body(applyService.getParticipateApply(userId.getId(), page, size)); + return ResponseEntity.ok().body(applyService.getParticipateApply(userId, page, size)); + } + + @Operation(summary = "내가 신청한 스터디 목록", description = "헤더에 JWT 보내주시면 됩니다.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "페이지", required = true), + @ApiImplicitParam(name = "size", value = "사이즈", required = true) + }) + @GetMapping("/v1/study-request") + public ResponseEntity getMyRequestApply(UserId userId, @RequestParam int page, @RequestParam int size) { + return ResponseEntity.ok(applyService.getMyRequestApply(userId, page, size)); } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java new file mode 100644 index 00000000..5129d871 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java @@ -0,0 +1,20 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.data; + +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import lombok.Getter; + +@Getter +public class RequestApplyData { + + private final Long studyId; + private final String studyTitle; + private final Inspection inspection; + private final String introduce; + + public RequestApplyData(Long studyId, String studyTitle, Inspection inspection, String introduce) { + this.studyId = studyId; + this.studyTitle = studyTitle; + this.inspection = inspection; + this.introduce = introduce; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java index c3cd7743..ed335b51 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java @@ -1,15 +1,18 @@ package kr.co.studyhubinu.studyhubserver.apply.dto.request; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import lombok.Builder; import lombok.Getter; @Getter public class FindApplyRequest { - private Long studyId; + private final Long studyId; + private final Inspection inspection; @Builder - public FindApplyRequest(Long studyId) { + public FindApplyRequest(Long studyId, Inspection inspection) { this.studyId = studyId; + this.inspection = inspection; } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java new file mode 100644 index 00000000..52ed48a7 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java @@ -0,0 +1,18 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.response; + +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; +import lombok.Getter; +import org.springframework.data.domain.Slice; + +@Getter +public class FindMyRequestApplyResponse { + + private Long totalCount; + Slice requestStudyData; + + public FindMyRequestApplyResponse(Long totalCount, Slice requestStudyData) { + this.totalCount = totalCount; + this.requestStudyData = requestStudyData; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java index 10498708..f86a97c3 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java @@ -8,6 +8,7 @@ public class FindParticipateApplyResponse { private Long totalCount; Slice participateStudyData; + public FindParticipateApplyResponse(Long totalCount, Slice participateStudyData) { this.totalCount = totalCount; this.participateStudyData = participateStudyData; 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 ad55c00d..c747277c 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,6 +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.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; @@ -11,4 +14,8 @@ public interface ApplyRepositoryCustom { List findByStudy(Long studyId, Pageable pageable); List findByUserIdAndInspection(Long userId, Pageable pageable); + + List findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable); + + List findApplyByUserId(Long userId, 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 93dfd726..ee2760a4 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,8 @@ 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.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -39,20 +41,50 @@ public List findByStudy(Long studyId, final Pageable pageable) { @Override public List findByUserIdAndInspection(Long userId, Pageable pageable) { - return jpaQueryFactory - .select(Projections.constructor(ParticipateApplyData.class, - studyEntity.major, studyEntity.title, studyEntity.content, studyEntity.chatUrl, - applyEntity.inspection, studyPostEntity.id.as("postId"))) - .from(applyEntity) - .innerJoin(studyEntity).on(applyEntity.studyId.eq(studyEntity.id)) - .innerJoin(studyPostEntity).on(studyEntity.id.eq(studyPostEntity.studyId)) - .where( - applyEntity.userId.eq(userId) - .and(applyEntity.inspection.eq(Inspection.ACCEPT)) - ) - .orderBy(applyEntity.createdDate.desc()) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize() + 1) - .fetch(); + return jpaQueryFactory + .select(Projections.constructor(ParticipateApplyData.class, + studyEntity.major, studyEntity.title, studyEntity.content, studyEntity.chatUrl, + applyEntity.inspection, studyPostEntity.id.as("postId"))) + .from(applyEntity) + .innerJoin(studyEntity).on(applyEntity.studyId.eq(studyEntity.id)) + .innerJoin(studyPostEntity).on(studyEntity.id.eq(studyPostEntity.studyId)) + .where( + applyEntity.userId.eq(userId) + .and(applyEntity.inspection.eq(Inspection.ACCEPT)) + ) + .orderBy(applyEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) + .fetch(); + } + + @Override + public List findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(ApplyUserData.class, + userEntity.id, userEntity.nickname, userEntity.major, userEntity.imageUrl, + applyEntity.introduce, applyEntity.createdDate, applyEntity.inspection)) + .from(applyEntity) + .innerJoin(userEntity).on(applyEntity.userId.eq(userEntity.id)) + .where(applyEntity.studyId.eq(request.getStudyId()) + .and(applyEntity.inspection.eq(request.getInspection()))) + .orderBy(applyEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) + .fetch(); + } + + @Override + public List findApplyByUserId(Long userId, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(RequestApplyData.class, + applyEntity.studyId, studyEntity.title, applyEntity.inspection, applyEntity.introduce)) + .from(applyEntity) + .innerJoin(studyEntity).on(applyEntity.studyId.eq(studyEntity.id)) + .where(applyEntity.userId.eq(userId)) + .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 abd8aeac..b0dd6190 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 @@ -3,21 +3,21 @@ import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; 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.RequestApplyData; import kr.co.studyhubinu.studyhubserver.apply.dto.request.*; 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.repository.ApplyRepository; import kr.co.studyhubinu.studyhubserver.apply.repository.RejectRepository; 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.PostNotFoundExceptionByStudyId; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; -import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostEntity; -import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; @@ -36,43 +36,26 @@ public class ApplyService { private final UserRepository userRepository; private final StudyRepository studyRepository; private final ApplyRepository applyRepository; - private final StudyPostRepository studyPostRepository; private final RejectRepository rejectRepository; @Transactional - public void enroll(Long userId, EnrollApplyRequest request) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public void enroll(UserId userId, EnrollApplyRequest request) { + UserEntity user = userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(request.getStudyId()).orElseThrow(); validateSameRequest(user, study); applyRepository.save(ApplyEntity.of(user.getId(), study.getId(), request.getIntroduce())); } - @Transactional - public void update(UpdateApplyRequest request) { - UserEntity user = userRepository.findById(request.getUserId()).orElseThrow(UserNotFoundException::new); - StudyEntity study = studyRepository.findById(request.getStudyId()).orElseThrow(); - ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).orElseThrow(ApplyNotFoundException::new); - - isAccept(request); - applyEntity.update(request.getInspection()); - } - public FindApplyResponse findApply(FindApplyRequest request, final int page, final int size) { Pageable pageable = PageRequest.of(page, size); - Slice userData = Converter.toSlice(pageable, applyRepository.findByStudy(request.getStudyId(), pageable)); + Slice userData = Converter.toSlice(pageable, applyRepository.findStudyByIdAndInspection(request, pageable)); return new FindApplyResponse((long) size, userData); } - private void validateSameRequest(UserEntity user, StudyEntity study) { - if(applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).isPresent()) { - throw new SameUserRequestException(); - } - } - - public FindParticipateApplyResponse getParticipateApply(final Long userId, final int page, final int size) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + 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); Long totalCount = applyRepository.countByUserIdAndInspection(user.getId(), ACCEPT); Slice participateApplyData = Converter.toSlice @@ -80,16 +63,10 @@ public FindParticipateApplyResponse getParticipateApply(final Long userId, final return new FindParticipateApplyResponse(totalCount, participateApplyData); } - private void isAccept(UpdateApplyRequest request) { - if(request.getInspection().equals(ACCEPT)) { - StudyPostEntity post = studyPostRepository.findByStudyId(request.getStudyId()).orElseThrow(PostNotFoundExceptionByStudyId::new); - post.minusRemainingSeat(); - } - } @Transactional - public void rejectApply(final RejectApplyRequest rejectApplyRequest, final Long userId) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public void rejectApply(final RejectApplyRequest rejectApplyRequest, final UserId userId) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(rejectApplyRequest.getStudyId()).orElseThrow(); ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(rejectApplyRequest.getRejectedUserId(), study.getId()).orElseThrow(ApplyNotFoundException::new); applyEntity.updateReject(); @@ -97,10 +74,24 @@ public void rejectApply(final RejectApplyRequest rejectApplyRequest, final Long } @Transactional - public void acceptApply(AcceptApplyRequest acceptApplyRequest, Long userId) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public void acceptApply(AcceptApplyRequest acceptApplyRequest, UserId userId) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(acceptApplyRequest.getStudyId()).orElseThrow(); ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(acceptApplyRequest.getRejectedUserId(), study.getId()).orElseThrow(ApplyNotFoundException::new); applyEntity.updateAccept(); } + + public FindMyRequestApplyResponse getMyRequestApply(UserId userId, int page, int size) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); + final Pageable pageable = PageRequest.of(page, size); + Slice requestApplyData = Converter.toSlice(pageable, applyRepository.findApplyByUserId(userId.getId(), pageable)); + + return new FindMyRequestApplyResponse((long) size, requestApplyData); + } + + private void validateSameRequest(UserEntity user, StudyEntity study) { + if(applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).isPresent()) { + throw new SameUserRequestException(); + } + } } diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java index 99150fb5..5409097d 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java @@ -16,6 +16,9 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; +import java.util.HashMap; +import java.util.Map; + import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -39,7 +42,7 @@ class ApplyControllerTest extends ControllerRequest { @Test void 스터디_가입_요청_성공() throws Exception { // given - doNothing().when(applyService).enroll(anyLong(), any()); + doNothing().when(applyService).enroll(any(), any()); EnrollApplyRequest request = EnrollApplyRequest.builder() .studyId(1L) .build(); @@ -52,35 +55,23 @@ class ApplyControllerTest extends ControllerRequest { .andDo(print()); } - @Test - void 스터디_요청상태_수정() throws Exception { - // given - doNothing().when(applyService).update(any()); - UpdateApplyRequest request = UpdateApplyRequest.builder() - .studyId(1L) - .userId(1L) - .inspection(Inspection.ACCEPT) - .build(); - - // when - ResultActions resultActions = performPutRequest("/api/v1/study", request); - - // then - resultActions.andExpect(status().isOk()) - .andDo(print()); - } - @Test void 스터디_요청상태_조회() throws Exception { // given FindApplyResponse findApplyResponse = FindApplyResponse.builder().build(); FindApplyRequest findApplyRequest = FindApplyRequest.builder() .studyId(1L) + .inspection(Inspection.ACCEPT) .build(); Mockito.when(applyService.findApply(any(), anyInt(), anyInt())).thenReturn(findApplyResponse); + Map params = new HashMap<>(); + params.put("studyId", "1"); + params.put("inspection", "ACCEPT"); + params.put("page", "0"); + params.put("size", "5"); // when - ResultActions resultActions = performPostRequest("/api/v1/study", findApplyRequest); + ResultActions resultActions = performGetRequest("/api/v2/study", params); // then resultActions.andExpect(status().isOk()) diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java new file mode 100644 index 00000000..a81b03ee --- /dev/null +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java @@ -0,0 +1,56 @@ +package kr.co.studyhubinu.studyhubserver.apply.service; + +import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; +import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; +import kr.co.studyhubinu.studyhubserver.support.fixture.StudyEntityFixture; +import kr.co.studyhubinu.studyhubserver.support.fixture.UserEntityFixture; +import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; +import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class ApplyServiceIntegrationTest { + + @Autowired + ApplyService applyService; + + @Autowired + UserRepository userRepository; + + @Autowired + ApplyRepository applyRepository; + + @Autowired + StudyRepository studyRepository; + + @Test + void 내가_신청한_스터디목록_조회() { + UserEntity user = UserEntityFixture.YEONGJAE.UserEntity_생성(); + StudyEntity study = studyRepository.save(StudyEntityFixture.INU.studyEntity_생성()); + userRepository.save(user); + applyRepository.save(ApplyEntity.builder() + .userId(user.getId()).introduce("안녕") + .studyId(study.getId()) + .inspection(Inspection.ACCEPT) + .build()); + + + FindMyRequestApplyResponse applyResponse = applyService.getMyRequestApply(new UserId(user.getId()), 0, 3); + RequestApplyData applyData = applyResponse.getRequestStudyData().getContent().get(0); + + assertThat(applyData.getInspection()).isEqualTo(Inspection.ACCEPT); + assertThat(applyData.getIntroduce()).isEqualTo("안녕"); + + } +} diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java index 03b5e85f..6086e974 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java @@ -13,12 +13,14 @@ import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.PageRequest; import java.util.List; import java.util.Optional; @@ -65,7 +67,7 @@ class ApplyServiceTest { .build()); // when, then - applyService.enroll(user.getId(), request); + applyService.enroll(new UserId(1L), request); } /** @@ -97,13 +99,17 @@ class ApplyServiceTest { // given FindApplyRequest request = FindApplyRequest.builder() .studyId(1L) + .inspection(Inspection.ACCEPT) + .build(); + ApplyUserData data1 = ApplyUserData.builder() + .nickname("liljay") + .inspection(Inspection.ACCEPT) .build(); - ApplyUserData data1 = ApplyUserData.builder().nickname("liljay").build(); ApplyUserData data2 = ApplyUserData.builder().build(); List applyEntities = List.of(data1, data2); - when(applyRepository.findByStudy(any(), any())).thenReturn(applyEntities); + when(applyRepository.findStudyByIdAndInspection(request, PageRequest.of(0,5))).thenReturn(applyEntities); // when FindApplyResponse applyResponse = applyService.findApply(request, 0, 5); diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java b/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java index f1474a79..f936643d 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java @@ -7,7 +7,7 @@ public enum StudyEntityFixture { - INU("인천대학교 스터디", "반가워요 잘해봐요", LocalDate.of(2024, 1, 3), LocalDate.of(2024, 1, 5), "asdadsa", 1L, MajorType.COMPUTER_SCIENCE_ENGINEERING); + INU("인천대학교 스터디", "반가워요 잘해봐요", LocalDate.of(2025, 1, 3), LocalDate.of(2025, 1, 5), "asdadsa", 1L, MajorType.COMPUTER_SCIENCE_ENGINEERING); private String title; private String content;