From 38aece1af1476a699b14f5f27b25fc04e96e2711 Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 01:45:48 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20apply=20=EC=9D=98=20quryDsl=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../banggabgo/repository/ApplyRepository.java | 2 +- .../repository/ApplyRepositoryCustom.java | 10 ++++++ .../repository/impl/ApplyRepositoryImpl.java | 32 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java create mode 100644 src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java diff --git a/src/main/java/com/fab/banggabgo/repository/ApplyRepository.java b/src/main/java/com/fab/banggabgo/repository/ApplyRepository.java index fad4179..f21eb50 100644 --- a/src/main/java/com/fab/banggabgo/repository/ApplyRepository.java +++ b/src/main/java/com/fab/banggabgo/repository/ApplyRepository.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Repository; @Repository -public interface ApplyRepository extends JpaRepository { +public interface ApplyRepository extends JpaRepository, ApplyRepositoryCustom { boolean existsByApplicantUserIdAndArticleId(Integer applicantUserId, Integer articleId); } diff --git a/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java b/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java new file mode 100644 index 0000000..2acb2e6 --- /dev/null +++ b/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java @@ -0,0 +1,10 @@ +package com.fab.banggabgo.repository; + +import com.fab.banggabgo.entity.Apply; +import java.util.List; +import org.springframework.data.domain.Pageable; + +public interface ApplyRepositoryCustom { + + List getMyApplicant(Pageable pageable, Integer userId); +} diff --git a/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java b/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java new file mode 100644 index 0000000..adebac8 --- /dev/null +++ b/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java @@ -0,0 +1,32 @@ +package com.fab.banggabgo.repository.impl; + +import com.fab.banggabgo.entity.Apply; +import com.fab.banggabgo.entity.QApply; +import com.fab.banggabgo.repository.ApplyRepositoryCustom; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; + +@RequiredArgsConstructor +public class ApplyRepositoryImpl implements ApplyRepositoryCustom { + + private final JPAQueryFactory jpaQueryFactory; + + QApply qApply = QApply.apply; + + @Override + public List getMyApplicant(Pageable pageable, Integer userId) { + var pageQuery = jpaQueryFactory.selectFrom(qApply) + .leftJoin(qApply.applicantUser) + .fetchJoin() + .leftJoin(qApply.article) + .fetchJoin() + .where(qApply.article.user.id.eq(userId)) + .orderBy(qApply.lastModifiedDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()); + + return pageQuery.fetch(); + } +} From 4b14c3b45ef12836dddb5405cdea7c9dde4ea08a Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 01:48:42 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EB=82=98=EC=97=90=EA=B2=8C=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=ED=95=9C=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20pag?= =?UTF-8?q?e=EB=A1=9C=20=EA=B0=80=EC=A0=B8=EC=98=A8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyContentController.java | 15 ++++++- .../dto/apply/ApplyListResultDto.java | 41 +++++++++++++++++++ .../banggabgo/service/MyContentService.java | 4 +- .../service/impl/MyContentServiceImpl.java | 16 +++++++- 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java diff --git a/src/main/java/com/fab/banggabgo/controller/MyContentController.java b/src/main/java/com/fab/banggabgo/controller/MyContentController.java index 10a96a6..a9d8c2a 100644 --- a/src/main/java/com/fab/banggabgo/controller/MyContentController.java +++ b/src/main/java/com/fab/banggabgo/controller/MyContentController.java @@ -10,16 +10,19 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; 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 @RequiredArgsConstructor @RequestMapping("api/my") @PermitAll +@Validated public class MyContentController { private final MyContentService myContentService; @@ -49,11 +52,19 @@ public ResponseEntity PatchMyNickName(@AuthenticationPrincipal User user, @Re var result = myContentService.patchNickname(user, PatchMyNicknameForm.toDto(form)); return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } + @PatchMapping public ResponseEntity patchMyInfo(@AuthenticationPrincipal User user, - @RequestBody PatchMyInfoForm form){ //내정보 변경 - var result = myContentService.patchMyInfo(user,PatchMyInfoForm.toDto(form)); + @RequestBody PatchMyInfoForm form) { //내정보 변경 + var result = myContentService.patchMyInfo(user, PatchMyInfoForm.toDto(form)); return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } + @GetMapping("/applicants") + public ResponseEntity getMyApplicant(@AuthenticationPrincipal User user, + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size) { + var result = myContentService.getMyApplicant(user, page, size); + return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); + } } diff --git a/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java new file mode 100644 index 0000000..c36d9ac --- /dev/null +++ b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java @@ -0,0 +1,41 @@ +package com.fab.banggabgo.dto.apply; + +import com.fab.banggabgo.entity.Apply; +import java.util.List; +import java.util.stream.Collectors; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ApplyListResultDto { + + Integer applyId; + Integer articleId; + String articleTitle; + Integer otherUserId; + String otherUserName; + String matchStatus; + + public static List toDtoList(List applyPage) { + return applyPage.stream().map(ApplyListResultDto::toDto) + .collect(Collectors.toList()); + } + + public static ApplyListResultDto toDto(Apply apply) { + return ApplyListResultDto.builder() + .applyId(apply.getId()) + .articleId(apply.getArticle().getId()) + .articleTitle(apply.getArticle().getTitle()) + .otherUserId(apply.getApplicantUser().getId()) + .otherUserName(apply.getApplicantUser().getNickname()) + .matchStatus(apply.getApproveStatus().getValue()) + .build(); + } +} diff --git a/src/main/java/com/fab/banggabgo/service/MyContentService.java b/src/main/java/com/fab/banggabgo/service/MyContentService.java index 3b7abdf..a7dc943 100644 --- a/src/main/java/com/fab/banggabgo/service/MyContentService.java +++ b/src/main/java/com/fab/banggabgo/service/MyContentService.java @@ -1,11 +1,11 @@ package com.fab.banggabgo.service; import com.fab.banggabgo.common.exception.CustomException; +import com.fab.banggabgo.dto.apply.ApplyListResultDto; import com.fab.banggabgo.dto.mycontent.FavoriteArticleDto; import com.fab.banggabgo.dto.mycontent.MyArticleDto; import com.fab.banggabgo.dto.mycontent.MyInfoDto; import com.fab.banggabgo.dto.mycontent.PatchMyInfoDto; -import com.fab.banggabgo.dto.mycontent.PatchMyInfoForm; import com.fab.banggabgo.dto.mycontent.PatchMyInfoResultDto; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameDto; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameResult; @@ -24,4 +24,6 @@ public interface MyContentService { PatchMyNicknameResult patchNickname(User user, PatchMyNicknameDto toDto) throws CustomException; PatchMyInfoResultDto patchMyInfo(User user, PatchMyInfoDto form); + + List getMyApplicant(User user, Integer page, Integer size); } diff --git a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java index 314ee04..4cfc815 100644 --- a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java +++ b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java @@ -2,6 +2,7 @@ import com.fab.banggabgo.common.exception.CustomException; import com.fab.banggabgo.common.exception.ErrorCode; +import com.fab.banggabgo.dto.apply.ApplyListResultDto; import com.fab.banggabgo.dto.mycontent.FavoriteArticleDto; import com.fab.banggabgo.dto.mycontent.MyArticleDto; import com.fab.banggabgo.dto.mycontent.MyInfoDto; @@ -10,6 +11,7 @@ import com.fab.banggabgo.dto.mycontent.PatchMyNicknameDto; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameResult; import com.fab.banggabgo.entity.User; +import com.fab.banggabgo.repository.ApplyRepository; import com.fab.banggabgo.repository.ArticleRepository; import com.fab.banggabgo.repository.UserRepository; import com.fab.banggabgo.service.MyContentService; @@ -21,6 +23,8 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service @@ -29,6 +33,7 @@ public class MyContentServiceImpl implements MyContentService { private final ArticleRepository articleRepository; private final UserRepository userRepository; + private final ApplyRepository applyRepository; @Override public List getMyArticle(User user) { @@ -63,7 +68,7 @@ public PatchMyNicknameResult patchNickname(User user, PatchMyNicknameDto dto) @Override public PatchMyInfoResultDto patchMyInfo(User user, PatchMyInfoDto dto) { - var converted_user=convertUserData(user,dto); + var converted_user = convertUserData(user, dto); return PatchMyInfoResultDto.from(userRepository.save(converted_user)); } @@ -78,9 +83,16 @@ public User convertUserData(User user, PatchMyInfoDto dto) { changed_user.setActivityTime(ActivityTime.fromValue(dto.getActivityTime())); changed_user.setTag(new HashSet<>(dto.getTags())); changed_user.setDetail(dto.getDetail()); - }catch (Exception e){ + } catch (Exception e) { throw new CustomException(ErrorCode.PATCH_MY_INFO_CONVERT_FAIL); } return changed_user; } + + public List getMyApplicant(User user, Integer page, Integer size) { + page = page > 0 ? page - 1 : 0; + + Pageable pageable = PageRequest.of(page, size); + return ApplyListResultDto.toDtoList(applyRepository.getMyApplicant(pageable, user.getId())); + } } From 6b5b846137fd5f437459ed30b887966ae1056321 Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 01:49:24 +0900 Subject: [PATCH 3/7] =?UTF-8?q?test:=20=EB=82=98=EC=97=90=EA=B2=8C=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=ED=95=9C=20=EB=AA=A9=EB=A1=9D=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyContentControllerTest.java | 68 +++++++++++---- .../impl/MyContentServiceImplTest.java | 84 +++++++++++++------ 2 files changed, 111 insertions(+), 41 deletions(-) diff --git a/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java b/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java index afc57ed..3c04fee 100644 --- a/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java +++ b/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java @@ -1,24 +1,17 @@ package com.fab.banggabgo.controller; -import static com.querydsl.core.types.ExpressionUtils.any; -import static org.junit.jupiter.api.Assertions.*; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fab.banggabgo.dto.mycontent.PatchMyInfoForm; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameForm; -import com.fab.banggabgo.repository.ArticleRepository; import com.fab.banggabgo.service.MyContentService; -import com.fab.banggabgo.service.impl.MyContentServiceImpl; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; 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.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -63,27 +56,28 @@ void getMyInfo() throws Exception { mockMvc.perform(get("/api/my")) .andExpect(status().isOk()); } + @Test @WithMockUser @DisplayName("닉네임 변경") void patchMyNickname() throws Exception { - PatchMyNicknameForm form=PatchMyNicknameForm.builder() + PatchMyNicknameForm form = PatchMyNicknameForm.builder() .nickname("test") .build(); - //given + //given mockMvc.perform(patch("/api/my/nickname") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(form))) .andExpect(status().isOk()); - //when - //then + //when + //then } @Test @DisplayName("닉네임 변경- 로그인 안되어있을경우") void patchMyNickname_notAuthenticated() throws Exception { - PatchMyNicknameForm form=PatchMyNicknameForm.builder() + PatchMyNicknameForm form = PatchMyNicknameForm.builder() .nickname("test") .build(); //given @@ -95,6 +89,7 @@ void patchMyNickname_notAuthenticated() throws Exception { //when //then } + @Test @DisplayName("닉네임 변경- 입력폼이없을경우") @WithMockUser @@ -107,31 +102,70 @@ void patchMyNickname_form() throws Exception { //when //then } + @Test @DisplayName("내정보 변경- 폼이없는경우") @WithMockUser void patchMyInfo_without_form() throws Exception { - //given + //given mockMvc.perform(patch("/api/my") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is4xxClientError()); - //when - //then + //when + //then } + @Test @DisplayName("내정보 변경 - 정상") @WithMockUser void patchMyInfo() throws Exception { - PatchMyInfoForm form=PatchMyInfoForm.builder() + PatchMyInfoForm form = PatchMyInfoForm.builder() .build(); //given mockMvc.perform(patch("/api/my") .with(SecurityMockMvcRequestPostProcessors.csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(form))) + .content(objectMapper.writeValueAsString(form))) .andExpect(status().isOk()); //when //then } + + @Nested + @DisplayName("내가받은 신청자리스트") + class applicantList { + + @Test + @DisplayName("신청자리스트 - 성공") + @WithMockUser + void successGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/applicants?page=1&size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청자리스트 - 성공 페이지 누락") + @WithMockUser + void successLostPageGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/applicants?size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청자리스트 - 성공 사이즈 누락") + @WithMockUser + void successLostSizeGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/applicants?page=1") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청자리스트 - 실패 계정 누락") + void FailNonAuthGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/applicants?page=1&size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isUnauthorized()); + } + } } \ No newline at end of file diff --git a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java index 6bfc182..ef32d0d 100644 --- a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java +++ b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -13,12 +14,13 @@ import com.fab.banggabgo.dto.mycontent.FavoriteArticleDto; import com.fab.banggabgo.dto.mycontent.MyArticleDto; import com.fab.banggabgo.dto.mycontent.PatchMyInfoForm; -import com.fab.banggabgo.dto.mycontent.PatchMyNicknameDto; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameForm; +import com.fab.banggabgo.entity.Apply; import com.fab.banggabgo.entity.User; +import com.fab.banggabgo.repository.ApplyRepository; import com.fab.banggabgo.repository.ArticleRepository; import com.fab.banggabgo.repository.UserRepository; -import io.jsonwebtoken.lang.Assert; +import com.fab.banggabgo.type.ApproveStatus; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -31,9 +33,12 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.test.context.support.WithMockUser; @ExtendWith(MockitoExtension.class) class MyContentServiceImplTest { @@ -42,6 +47,8 @@ class MyContentServiceImplTest { private ArticleRepository articleRepository; @Mock private UserRepository userRepository; + @Mock + private ApplyRepository applyRepository; @InjectMocks private MyContentServiceImpl myContentService; @@ -59,6 +66,7 @@ void init() { lenient().when(securityContext.getAuthentication()).thenReturn(auth); SecurityContextHolder.setContext(securityContext); } + @Test void getMyArticle() { // 내 아티클 가져오기 //given @@ -73,7 +81,7 @@ void getMyArticle() { // 내 아티클 가져오기 //when when(articleRepository.getMyArticle(any(User.class))).thenReturn(stub_list); //then - assertEquals(myContentService.getMyArticle(stub_user),stub_list); + assertEquals(myContentService.getMyArticle(stub_user), stub_list); } @Test @@ -89,28 +97,32 @@ void getMyFavoriteArticle() { // 좋아요 한글 가져오기 //when when(articleRepository.getFavoriteArticle(any(User.class))).thenReturn(stub_list); //then - assertEquals(myContentService.getMyFavoriteArticle(stub_user),stub_list); + assertEquals(myContentService.getMyFavoriteArticle(stub_user), stub_list); } + @Nested @DisplayName("내정보 불러오기") - class MyInfo{ + class MyInfo { + @Test @DisplayName("특정 데이터가 null일경우") - void null_test(){ - //given - //when - var result=myContentService.getMyInfo(stub_user); - //then + void null_test() { + //given + //when + var result = myContentService.getMyInfo(stub_user); + //then System.out.println(result.toString()); } } + @Nested @DisplayName("닉네임 변경") - class PatchNick{ + class PatchNick { + @Test @DisplayName("닉네임 변경 성공케이스") - void Patch_nick_success(){ + void Patch_nick_success() { //given var form = PatchMyNicknameForm.builder() @@ -119,13 +131,14 @@ void Patch_nick_success(){ //when when(userRepository.save(stub_user)).thenReturn(stub_user); - var result=myContentService.patchNickname(stub_user,PatchMyNicknameForm.toDto(form)); + var result = myContentService.patchNickname(stub_user, PatchMyNicknameForm.toDto(form)); //then - assertEquals(result.getNickname(),"당당한무지"); + assertEquals(result.getNickname(), "당당한무지"); } + @Test @DisplayName("닉네임 변경 실패(이미 존재하는 닉네임일경우)") - void Patch_nick_duplicate(){ + void Patch_nick_duplicate() { //given var form = PatchMyNicknameForm.builder() .nickname("당당한무지") @@ -133,13 +146,16 @@ void Patch_nick_duplicate(){ //when when(userRepository.save(stub_user)).thenThrow(DataIntegrityViolationException.class); //then - Assertions.assertThrows(CustomException.class,() -> myContentService.patchNickname(stub_user,PatchMyNicknameForm.toDto(form))); + Assertions.assertThrows(CustomException.class, + () -> myContentService.patchNickname(stub_user, PatchMyNicknameForm.toDto(form))); } } + @Nested @DisplayName("내정보 변경") - class patchMyInfo{ - PatchMyInfoForm form= PatchMyInfoForm.builder() + class patchMyInfo { + + PatchMyInfoForm form = PatchMyInfoForm.builder() .gender("남성") .region("강남구") .activityTime("오후") @@ -151,28 +167,48 @@ class patchMyInfo{ .maxAge(25) .minAge(21) .build(); + @Test @DisplayName("- 성공케이스") - void patch_my_info_success(){ + void patch_my_info_success() { //given //when when(userRepository.save(stub_user)).thenReturn(stub_user); //then - var result=myContentService.patchMyInfo(stub_user,PatchMyInfoForm.toDto(form)); + var result = myContentService.patchMyInfo(stub_user, PatchMyInfoForm.toDto(form)); - verify(userRepository,times(1)).save(any(User.class)); - assertEquals(result.getMbti(),"INFP"); + verify(userRepository, times(1)).save(any(User.class)); + assertEquals(result.getMbti(), "INFP"); } + @Test @DisplayName("- form 값이 잘못된경우") - void patch_my_info_missedValue_form(){ + void patch_my_info_missedValue_form() { //given form.setActivityTime(null); //when //then - assertThrows(CustomException.class,() -> myContentService.patchMyInfo(stub_user,PatchMyInfoForm.toDto(form))); + assertThrows(CustomException.class, + () -> myContentService.patchMyInfo(stub_user, PatchMyInfoForm.toDto(form))); } } + @Test + @DisplayName("getApplicants - 성공") + @WithMockUser + void getApplicantsSuccess() { + when(applyRepository.getMyApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() + .approveStatus(ApproveStatus.WAIT) + .build(), + Apply.builder() + .approveStatus(ApproveStatus.APPROVAL) + .build())); + + var result = applyRepository.getMyApplicant(PageRequest.of(1, 4), 1); + + verify(applyRepository, times(1)).getMyApplicant(any(Pageable.class), any(Integer.class)); + assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); + assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + } } \ No newline at end of file From befc947788c187a030bb30a492cf634aa27e2ccd Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 02:54:17 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=ED=95=9C=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../banggabgo/controller/MyContentController.java | 11 +++++++++-- .../banggabgo/dto/apply/ApplyListResultDto.java | 15 +++++++++++++++ .../repository/ApplyRepositoryCustom.java | 1 + .../repository/impl/ApplyRepositoryImpl.java | 13 +++++++++++++ .../fab/banggabgo/service/MyContentService.java | 2 ++ .../service/impl/MyContentServiceImpl.java | 6 ++++++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fab/banggabgo/controller/MyContentController.java b/src/main/java/com/fab/banggabgo/controller/MyContentController.java index a9d8c2a..aa77066 100644 --- a/src/main/java/com/fab/banggabgo/controller/MyContentController.java +++ b/src/main/java/com/fab/banggabgo/controller/MyContentController.java @@ -60,11 +60,18 @@ public ResponseEntity patchMyInfo(@AuthenticationPrincipal User user, return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } - @GetMapping("/applicants") - public ResponseEntity getMyApplicant(@AuthenticationPrincipal User user, + @GetMapping("/from-applicants") + public ResponseEntity getMyFromApplicant(@AuthenticationPrincipal User user, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { var result = myContentService.getMyApplicant(user, page, size); return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } + @GetMapping("/to-applicants") + public ResponseEntity getMyToApplicant(@AuthenticationPrincipal User user, + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size) { + var result = myContentService.getMyToApplicant(user, page, size); + return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); + } } diff --git a/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java index c36d9ac..d1c41f7 100644 --- a/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java +++ b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java @@ -38,4 +38,19 @@ public static ApplyListResultDto toDto(Apply apply) { .matchStatus(apply.getApproveStatus().getValue()) .build(); } + public static List toToDtoList(List applyPage) { + return applyPage.stream().map(ApplyListResultDto::toToDto) + .collect(Collectors.toList()); + } + + public static ApplyListResultDto toToDto(Apply apply) { + return ApplyListResultDto.builder() + .applyId(apply.getId()) + .articleId(apply.getArticle().getId()) + .articleTitle(apply.getArticle().getTitle()) + .otherUserId(apply.getArticle().getUser().getId()) + .otherUserName(apply.getArticle().getUser().getNickname()) + .matchStatus(apply.getApproveStatus().getValue()) + .build(); + } } diff --git a/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java b/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java index 2acb2e6..ac31195 100644 --- a/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java +++ b/src/main/java/com/fab/banggabgo/repository/ApplyRepositoryCustom.java @@ -7,4 +7,5 @@ public interface ApplyRepositoryCustom { List getMyApplicant(Pageable pageable, Integer userId); + List getMyToApplicant(Pageable pageable, Integer userId); } diff --git a/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java b/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java index adebac8..b3e275a 100644 --- a/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java +++ b/src/main/java/com/fab/banggabgo/repository/impl/ApplyRepositoryImpl.java @@ -29,4 +29,17 @@ public List getMyApplicant(Pageable pageable, Integer userId) { return pageQuery.fetch(); } + @Override + public List getMyToApplicant(Pageable pageable, Integer userId) { + var pageQuery = jpaQueryFactory.selectFrom(qApply) + .leftJoin(qApply.article) + .fetchJoin() + .leftJoin(qApply.article.user) + .where(qApply.applicantUser.id.eq(userId)) + .orderBy(qApply.lastModifiedDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()); + + return pageQuery.fetch(); + } } diff --git a/src/main/java/com/fab/banggabgo/service/MyContentService.java b/src/main/java/com/fab/banggabgo/service/MyContentService.java index a7dc943..86368b2 100644 --- a/src/main/java/com/fab/banggabgo/service/MyContentService.java +++ b/src/main/java/com/fab/banggabgo/service/MyContentService.java @@ -26,4 +26,6 @@ public interface MyContentService { PatchMyInfoResultDto patchMyInfo(User user, PatchMyInfoDto form); List getMyApplicant(User user, Integer page, Integer size); + + List getMyToApplicant(User user, Integer page, Integer size); } diff --git a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java index 4cfc815..c30a0fb 100644 --- a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java +++ b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java @@ -95,4 +95,10 @@ public List getMyApplicant(User user, Integer page, Integer Pageable pageable = PageRequest.of(page, size); return ApplyListResultDto.toDtoList(applyRepository.getMyApplicant(pageable, user.getId())); } + public List getMyToApplicant(User user, Integer page, Integer size) { + page = page > 0 ? page - 1 : 0; + + Pageable pageable = PageRequest.of(page, size); + return ApplyListResultDto.toToDtoList(applyRepository.getMyToApplicant(pageable, user.getId())); + } } From fa296aedd5a0f75467d719620c3141df2e530eac Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 02:55:13 +0900 Subject: [PATCH 5/7] =?UTF-8?q?test:=20=EB=82=B4=EA=B0=80=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=ED=95=9C=20=EB=AA=A9=EB=A1=9D=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyContentControllerTest.java | 44 +++++++++++-- .../impl/MyContentServiceImplTest.java | 61 ++++++++++++++----- 2 files changed, 85 insertions(+), 20 deletions(-) diff --git a/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java b/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java index 3c04fee..4b5c936 100644 --- a/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java +++ b/src/test/java/com/fab/banggabgo/controller/MyContentControllerTest.java @@ -140,7 +140,7 @@ class applicantList { @DisplayName("신청자리스트 - 성공") @WithMockUser void successGetApplicantList() throws Exception{ - mockMvc.perform(get("/api/my/applicants?page=1&size=4") + mockMvc.perform(get("/api/my/from-applicants?page=1&size=4") .with(SecurityMockMvcRequestPostProcessors.csrf())) .andExpect(status().isOk()); } @@ -148,7 +148,7 @@ void successGetApplicantList() throws Exception{ @DisplayName("신청자리스트 - 성공 페이지 누락") @WithMockUser void successLostPageGetApplicantList() throws Exception{ - mockMvc.perform(get("/api/my/applicants?size=4") + mockMvc.perform(get("/api/my/from-applicants?size=4") .with(SecurityMockMvcRequestPostProcessors.csrf())) .andExpect(status().isOk()); } @@ -156,14 +156,50 @@ void successLostPageGetApplicantList() throws Exception{ @DisplayName("신청자리스트 - 성공 사이즈 누락") @WithMockUser void successLostSizeGetApplicantList() throws Exception{ - mockMvc.perform(get("/api/my/applicants?page=1") + mockMvc.perform(get("/api/my/from-applicants?page=1") .with(SecurityMockMvcRequestPostProcessors.csrf())) .andExpect(status().isOk()); } @Test @DisplayName("신청자리스트 - 실패 계정 누락") void FailNonAuthGetApplicantList() throws Exception{ - mockMvc.perform(get("/api/my/applicants?page=1&size=4") + mockMvc.perform(get("/api/my/from-applicants?page=1&size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isUnauthorized()); + } + } + @Nested + @DisplayName("내가신청한 신청자리스트") + class toApplicantList { + + @Test + @DisplayName("신청한리스트 - 성공") + @WithMockUser + void successGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/to-applicants?page=1&size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청한리스트 - 성공 페이지 누락") + @WithMockUser + void successLostPageGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/to-applicants?size=4") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청한리스트 - 성공 사이즈 누락") + @WithMockUser + void successLostSizeGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/to-applicants?page=1") + .with(SecurityMockMvcRequestPostProcessors.csrf())) + .andExpect(status().isOk()); + } + @Test + @DisplayName("신청한리스트 - 실패 계정 누락") + void FailNonAuthGetApplicantList() throws Exception{ + mockMvc.perform(get("/api/my/to-applicants?page=1&size=4") .with(SecurityMockMvcRequestPostProcessors.csrf())) .andExpect(status().isUnauthorized()); } diff --git a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java index ef32d0d..307c75c 100644 --- a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java +++ b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java @@ -194,21 +194,50 @@ void patch_my_info_missedValue_form() { } - @Test - @DisplayName("getApplicants - 성공") - @WithMockUser - void getApplicantsSuccess() { - when(applyRepository.getMyApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() - .approveStatus(ApproveStatus.WAIT) - .build(), - Apply.builder() - .approveStatus(ApproveStatus.APPROVAL) - .build())); - - var result = applyRepository.getMyApplicant(PageRequest.of(1, 4), 1); - - verify(applyRepository, times(1)).getMyApplicant(any(Pageable.class), any(Integer.class)); - assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); - assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + @Nested + @DisplayName("신청자 목록 불러오기") + class fromApplicant { + + @Test + @DisplayName("신청자 목록 - 성공") + @WithMockUser + void getApplicantsSuccess() { + when(applyRepository.getMyApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() + .approveStatus(ApproveStatus.WAIT) + .build(), + Apply.builder() + .approveStatus(ApproveStatus.APPROVAL) + .build())); + + var result = applyRepository.getMyApplicant(PageRequest.of(1, 4), 1); + + verify(applyRepository, times(1)).getMyApplicant(any(Pageable.class), any(Integer.class)); + assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); + assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + } + } + + @Nested + @DisplayName("신청한 목록 불러오기") + class toApplicant { + + @Test + @DisplayName("신청한 - 성공") + @WithMockUser + void getApplicantsSuccess() { + when(applyRepository.getMyToApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() + .approveStatus(ApproveStatus.WAIT) + .build(), + Apply.builder() + .approveStatus(ApproveStatus.APPROVAL) + .build())); + + var result = applyRepository.getMyToApplicant(PageRequest.of(1, 4), 1); + + verify(applyRepository, times(1)).getMyToApplicant(any(Pageable.class), any(Integer.class)); + assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); + assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + } } + } \ No newline at end of file From 153fe7d53096edf29d98cd765728f52a3173f674 Mon Sep 17 00:00:00 2001 From: sjdlr Date: Sat, 17 Jun 2023 03:14:05 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20=EB=82=B4=EA=B0=80=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=ED=95=9C,=20=EC=8B=A0=EC=B2=AD=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MyContentServiceImplTest.java | 155 ++++++++++++++++-- 1 file changed, 139 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java index 307c75c..2d4316c 100644 --- a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java +++ b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java @@ -16,12 +16,22 @@ import com.fab.banggabgo.dto.mycontent.PatchMyInfoForm; import com.fab.banggabgo.dto.mycontent.PatchMyNicknameForm; import com.fab.banggabgo.entity.Apply; +import com.fab.banggabgo.entity.Article; import com.fab.banggabgo.entity.User; import com.fab.banggabgo.repository.ApplyRepository; import com.fab.banggabgo.repository.ArticleRepository; import com.fab.banggabgo.repository.UserRepository; +import com.fab.banggabgo.type.ActivityTime; import com.fab.banggabgo.type.ApproveStatus; +import com.fab.banggabgo.type.Gender; +import com.fab.banggabgo.type.MatchStatus; +import com.fab.banggabgo.type.Mbti; +import com.fab.banggabgo.type.Period; +import com.fab.banggabgo.type.Seoul; +import com.fab.banggabgo.type.UserRole; +import com.fab.banggabgo.type.UserType; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -33,7 +43,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; @@ -198,45 +207,159 @@ void patch_my_info_missedValue_form() { @DisplayName("신청자 목록 불러오기") class fromApplicant { + private final User loginUser = User.builder() + .id(1) + .email("test@email.com") + .password("abcd1234") + .nickname("테스트") + .userType(UserType.NORMAL) + .image("http://image_uri") + .matchStatus(MatchStatus.ACTIVITY) + .isSmoker(true) + .activityTime(ActivityTime.MORNING) + .gender(Gender.MALE) + .region(Seoul.DOBONG) + .mbti(Mbti.ENFP) + .minAge(20) + .maxAge(30) + .myAge(25) + .tag(new HashSet<>()) + .detail("abcdef") + .roles(List.of(UserRole.USER_ROLE)) + .build(); + + private final User appliedUser = User.builder() + .id(2) + .email("test2@email.com") + .password("abcdf12345") + .nickname("테스트2") + .userType(UserType.NORMAL) + .image("http://image_uri2") + .matchStatus(MatchStatus.ACTIVITY) + .isSmoker(true) + .activityTime(ActivityTime.MORNING) + .gender(Gender.MALE) + .region(Seoul.DOBONG) + .mbti(Mbti.ENFP) + .minAge(22) + .maxAge(28) + .myAge(26) + .tag(new HashSet<>()) + .detail("abcdeffdaa") + .roles(List.of(UserRole.USER_ROLE)) + .build(); + + private Article article = Article.builder() + .id(1) + .user(loginUser) + .title("테스트 게시글") + .content("test test test") + .region(Seoul.DOBONG) + .period(Period.ONETOTHREE) + .price(10000000) + .gender(Gender.MALE) + .isRecruiting(true) + .isDeleted(false) + .build(); @Test @DisplayName("신청자 목록 - 성공") @WithMockUser void getApplicantsSuccess() { + when(applyRepository.getMyApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() .approveStatus(ApproveStatus.WAIT) - .build(), - Apply.builder() - .approveStatus(ApproveStatus.APPROVAL) + .article(article) + .applicantUser(appliedUser) + .approveStatus(ApproveStatus.WAIT) .build())); - var result = applyRepository.getMyApplicant(PageRequest.of(1, 4), 1); + var result = myContentService.getMyApplicant(loginUser, 4, 1); verify(applyRepository, times(1)).getMyApplicant(any(Pageable.class), any(Integer.class)); - assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); - assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + assertEquals(result.get(0).getMatchStatus(), ApproveStatus.WAIT.getValue()); + assertEquals(result.get(0).getArticleTitle(), article.getTitle()); + assertEquals(result.get(0).getArticleId(), article.getId()); + assertEquals(result.get(0).getOtherUserName(), appliedUser.getNickname()); + assertEquals(result.get(0).getOtherUserId(), appliedUser.getId()); } } @Nested @DisplayName("신청한 목록 불러오기") class toApplicant { + private final User loginUser = User.builder() + .id(1) + .email("test@email.com") + .password("abcd1234") + .nickname("테스트") + .userType(UserType.NORMAL) + .image("http://image_uri") + .matchStatus(MatchStatus.ACTIVITY) + .isSmoker(true) + .activityTime(ActivityTime.MORNING) + .gender(Gender.MALE) + .region(Seoul.DOBONG) + .mbti(Mbti.ENFP) + .minAge(20) + .maxAge(30) + .myAge(25) + .tag(new HashSet<>()) + .detail("abcdef") + .roles(List.of(UserRole.USER_ROLE)) + .build(); + + private final User appliedUser = User.builder() + .id(2) + .email("test2@email.com") + .password("abcdf12345") + .nickname("테스트2") + .userType(UserType.NORMAL) + .image("http://image_uri2") + .matchStatus(MatchStatus.ACTIVITY) + .isSmoker(true) + .activityTime(ActivityTime.MORNING) + .gender(Gender.MALE) + .region(Seoul.DOBONG) + .mbti(Mbti.ENFP) + .minAge(22) + .maxAge(28) + .myAge(26) + .tag(new HashSet<>()) + .detail("abcdeffdaa") + .roles(List.of(UserRole.USER_ROLE)) + .build(); + private Article article = Article.builder() + .id(1) + .user(appliedUser) + .title("테스트 게시글") + .content("test test test") + .region(Seoul.DOBONG) + .period(Period.ONETOTHREE) + .price(10000000) + .gender(Gender.MALE) + .isRecruiting(true) + .isDeleted(false) + .build(); @Test - @DisplayName("신청한 - 성공") + @DisplayName("신청한 목록 - 성공") @WithMockUser void getApplicantsSuccess() { when(applyRepository.getMyToApplicant(any(), anyInt())).thenReturn(List.of(Apply.builder() - .approveStatus(ApproveStatus.WAIT) - .build(), - Apply.builder() - .approveStatus(ApproveStatus.APPROVAL) - .build())); + .approveStatus(ApproveStatus.WAIT) + .article(article) + .applicantUser(loginUser) + .approveStatus(ApproveStatus.WAIT) + .build())); - var result = applyRepository.getMyToApplicant(PageRequest.of(1, 4), 1); + var result = myContentService.getMyToApplicant(loginUser, 4, 1); verify(applyRepository, times(1)).getMyToApplicant(any(Pageable.class), any(Integer.class)); - assertEquals(result.get(0).getApproveStatus(), ApproveStatus.WAIT); - assertEquals(result.get(1).getApproveStatus(), ApproveStatus.APPROVAL); + assertEquals(result.get(0).getMatchStatus(), ApproveStatus.WAIT.getValue()); + assertEquals(result.get(0).getArticleTitle(), article.getTitle()); + assertEquals(result.get(0).getArticleId(), article.getId()); + assertEquals(result.get(0).getOtherUserName(), appliedUser.getNickname()); + assertEquals(result.get(0).getOtherUserId(), appliedUser.getId()); } } From 5c31efce4bf86b30341d73958bfddca4b24c95ff Mon Sep 17 00:00:00 2001 From: sjdlr Date: Mon, 19 Jun 2023 16:24:29 +0900 Subject: [PATCH 7/7] =?UTF-8?q?style:=20=EB=82=B4=EA=B0=80=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=ED=95=9C,=20=EC=8B=A0=EC=B2=AD=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=ED=95=A0=EC=88=98=20=EC=9E=88=EA=B2=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../banggabgo/controller/MyContentController.java | 6 +++--- .../fab/banggabgo/dto/apply/ApplyListResultDto.java | 12 ++++++------ .../com/fab/banggabgo/service/MyContentService.java | 4 ++-- .../banggabgo/service/impl/MyContentServiceImpl.java | 11 +++++++---- .../service/impl/MyContentServiceImplTest.java | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/fab/banggabgo/controller/MyContentController.java b/src/main/java/com/fab/banggabgo/controller/MyContentController.java index aa77066..c79a8f9 100644 --- a/src/main/java/com/fab/banggabgo/controller/MyContentController.java +++ b/src/main/java/com/fab/banggabgo/controller/MyContentController.java @@ -64,14 +64,14 @@ public ResponseEntity patchMyInfo(@AuthenticationPrincipal User user, public ResponseEntity getMyFromApplicant(@AuthenticationPrincipal User user, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { - var result = myContentService.getMyApplicant(user, page, size); + var result = myContentService.getMyFromApplicantList(user, page, size); return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } @GetMapping("/to-applicants") - public ResponseEntity getMyToApplicant(@AuthenticationPrincipal User user, + public ResponseEntity getMyToApplicantList(@AuthenticationPrincipal User user, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { - var result = myContentService.getMyToApplicant(user, page, size); + var result = myContentService.getMyToApplicantList(user, page, size); return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity(); } } diff --git a/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java index d1c41f7..934765c 100644 --- a/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java +++ b/src/main/java/com/fab/banggabgo/dto/apply/ApplyListResultDto.java @@ -23,12 +23,12 @@ public class ApplyListResultDto { String otherUserName; String matchStatus; - public static List toDtoList(List applyPage) { - return applyPage.stream().map(ApplyListResultDto::toDto) + public static List toFromApplicantDtoList(List applyPage) { + return applyPage.stream().map(ApplyListResultDto::toFromApplicantDto) .collect(Collectors.toList()); } - public static ApplyListResultDto toDto(Apply apply) { + public static ApplyListResultDto toFromApplicantDto(Apply apply) { return ApplyListResultDto.builder() .applyId(apply.getId()) .articleId(apply.getArticle().getId()) @@ -38,12 +38,12 @@ public static ApplyListResultDto toDto(Apply apply) { .matchStatus(apply.getApproveStatus().getValue()) .build(); } - public static List toToDtoList(List applyPage) { - return applyPage.stream().map(ApplyListResultDto::toToDto) + public static List toToApplicantDtoList(List applyPage) { + return applyPage.stream().map(ApplyListResultDto::toToApplicantDto) .collect(Collectors.toList()); } - public static ApplyListResultDto toToDto(Apply apply) { + public static ApplyListResultDto toToApplicantDto(Apply apply) { return ApplyListResultDto.builder() .applyId(apply.getId()) .articleId(apply.getArticle().getId()) diff --git a/src/main/java/com/fab/banggabgo/service/MyContentService.java b/src/main/java/com/fab/banggabgo/service/MyContentService.java index 86368b2..8d148f9 100644 --- a/src/main/java/com/fab/banggabgo/service/MyContentService.java +++ b/src/main/java/com/fab/banggabgo/service/MyContentService.java @@ -25,7 +25,7 @@ public interface MyContentService { PatchMyInfoResultDto patchMyInfo(User user, PatchMyInfoDto form); - List getMyApplicant(User user, Integer page, Integer size); + List getMyFromApplicantList(User user, Integer page, Integer size); - List getMyToApplicant(User user, Integer page, Integer size); + List getMyToApplicantList(User user, Integer page, Integer size); } diff --git a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java index c30a0fb..9110669 100644 --- a/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java +++ b/src/main/java/com/fab/banggabgo/service/impl/MyContentServiceImpl.java @@ -89,16 +89,19 @@ public User convertUserData(User user, PatchMyInfoDto dto) { return changed_user; } - public List getMyApplicant(User user, Integer page, Integer size) { + public List getMyFromApplicantList(User user, Integer page, Integer size) { page = page > 0 ? page - 1 : 0; Pageable pageable = PageRequest.of(page, size); - return ApplyListResultDto.toDtoList(applyRepository.getMyApplicant(pageable, user.getId())); + return ApplyListResultDto.toFromApplicantDtoList( + applyRepository.getMyApplicant(pageable, user.getId())); } - public List getMyToApplicant(User user, Integer page, Integer size) { + + public List getMyToApplicantList(User user, Integer page, Integer size) { page = page > 0 ? page - 1 : 0; Pageable pageable = PageRequest.of(page, size); - return ApplyListResultDto.toToDtoList(applyRepository.getMyToApplicant(pageable, user.getId())); + return ApplyListResultDto.toToApplicantDtoList( + applyRepository.getMyToApplicant(pageable, user.getId())); } } diff --git a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java index 2d4316c..a7bea2f 100644 --- a/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java +++ b/src/test/java/com/fab/banggabgo/service/impl/MyContentServiceImplTest.java @@ -273,7 +273,7 @@ void getApplicantsSuccess() { .approveStatus(ApproveStatus.WAIT) .build())); - var result = myContentService.getMyApplicant(loginUser, 4, 1); + var result = myContentService.getMyFromApplicantList(loginUser, 4, 1); verify(applyRepository, times(1)).getMyApplicant(any(Pageable.class), any(Integer.class)); assertEquals(result.get(0).getMatchStatus(), ApproveStatus.WAIT.getValue()); @@ -352,7 +352,7 @@ void getApplicantsSuccess() { .approveStatus(ApproveStatus.WAIT) .build())); - var result = myContentService.getMyToApplicant(loginUser, 4, 1); + var result = myContentService.getMyToApplicantList(loginUser, 4, 1); verify(applyRepository, times(1)).getMyToApplicant(any(Pageable.class), any(Integer.class)); assertEquals(result.get(0).getMatchStatus(), ApproveStatus.WAIT.getValue());