From 9c3a141214e79a5977528bb2126698a298d8145a Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sun, 22 Oct 2023 15:35:36 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=B0=8F=20=EC=86=8C?= =?UTF-8?q?=EB=AA=A8=EC=9E=84=20=EC=83=9D=EC=84=B1=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BoardCustomRepositoryImpl.java | 10 +++-- .../dto/response/GetMyPageResponse.java | 23 +++++++++++ .../dto/response/GetMyPageTeamBlock.java | 14 +++++++ .../application/mapper/MyPageMapper.java | 25 ++++++++++++ .../service/GetMyPageUserCase.java | 40 +++++++++++++++++++ .../mypage/presentation/MyPageController.java | 19 ++++++--- .../constant/MypageResponseMessage.java | 1 + .../repository/TeamCustomRepository.java | 2 + .../repository/TeamCustomRepositoryImpl.java | 22 ++++++++-- .../team/domain/service/TeamGetService.java | 5 +++ .../exception/AlreadyJoinTeamException.java | 11 +++++ .../AlreadyWithdrawTeamException.java | 11 +++++ .../domain/service/TeamMemberSaveService.java | 26 +++++++++--- .../backend/global/response/ErrorCode.java | 2 + 14 files changed, 193 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageResponse.java create mode 100644 src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageTeamBlock.java create mode 100644 src/main/java/com/moing/backend/domain/mypage/application/mapper/MyPageMapper.java create mode 100644 src/main/java/com/moing/backend/domain/mypage/application/service/GetMyPageUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/team/exception/AlreadyJoinTeamException.java create mode 100644 src/main/java/com/moing/backend/domain/team/exception/AlreadyWithdrawTeamException.java diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java index 8a3001a5..7dbf0074 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java @@ -70,16 +70,18 @@ public GetAllBoardResponse findBoardAll(Long teamId, Long memberId) { public Integer findUnReadBoardNum(Long teamId, Long memberId) { // 전체 게시글 수 Long allBoards = queryFactory - .selectFrom(board) + .select(board.count()) + .from(board) .where(board.team.teamId.eq(teamId)) - .fetchCount(); + .fetchFirst(); // 멤버가 읽은 게시글 수 Long readBoards = queryFactory - .selectFrom(boardRead) + .select(boardRead.count()) + .from(boardRead) .where(boardRead.member.memberId.eq(memberId)) .where(boardRead.board.team.teamId.eq(teamId)) - .fetchCount(); + .fetchFirst(); return Math.toIntExact(allBoards - readBoards); } diff --git a/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageResponse.java b/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageResponse.java new file mode 100644 index 00000000..79baebbd --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageResponse.java @@ -0,0 +1,23 @@ +package com.moing.backend.domain.mypage.application.dto.response; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.team.domain.constant.Category; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class GetMyPageResponse { + private String profileImage; + private String nickName; + private String introduction; + private List categories=new ArrayList<>(); + private List getMyPageTeamBlocks = new ArrayList<>(); +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageTeamBlock.java b/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageTeamBlock.java new file mode 100644 index 00000000..a05783c9 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mypage/application/dto/response/GetMyPageTeamBlock.java @@ -0,0 +1,14 @@ +package com.moing.backend.domain.mypage.application.dto.response; + +import com.moing.backend.domain.team.domain.constant.Category; +import lombok.*; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class GetMyPageTeamBlock { + private Long teamId; + private String teamName; + private Category category; +} diff --git a/src/main/java/com/moing/backend/domain/mypage/application/mapper/MyPageMapper.java b/src/main/java/com/moing/backend/domain/mypage/application/mapper/MyPageMapper.java new file mode 100644 index 00000000..fd09f4ed --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mypage/application/mapper/MyPageMapper.java @@ -0,0 +1,25 @@ +package com.moing.backend.domain.mypage.application.mapper; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; +import com.moing.backend.domain.team.domain.constant.Category; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@RequiredArgsConstructor +public class MyPageMapper { + + public GetMyPageResponse toGetMyPageResponse(Member member, List categories, List blocks) { + return GetMyPageResponse.builder() + .profileImage(member.getProfileImage()) + .nickName(member.getNickName()) + .introduction(member.getIntroduction()) + .categories(categories) + .getMyPageTeamBlocks(blocks) + .build(); + } +} diff --git a/src/main/java/com/moing/backend/domain/mypage/application/service/GetMyPageUserCase.java b/src/main/java/com/moing/backend/domain/mypage/application/service/GetMyPageUserCase.java new file mode 100644 index 00000000..818d1843 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mypage/application/service/GetMyPageUserCase.java @@ -0,0 +1,40 @@ +package com.moing.backend.domain.mypage.application.service; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; +import com.moing.backend.domain.mypage.application.mapper.MyPageMapper; +import com.moing.backend.domain.team.domain.constant.Category; +import com.moing.backend.domain.team.domain.service.TeamGetService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Transactional +@RequiredArgsConstructor +public class GetMyPageUserCase { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final MyPageMapper myPageMapper; + + public GetMyPageResponse getMyPageResponse(String socialId) { + Member member = memberGetService.getMemberBySocialId(socialId); + List getMyPageTeamBlocks = teamGetService.getMyPageTeamBlockByMemberId(member.getMemberId()); + return myPageMapper.toGetMyPageResponse(member, calculateCategory(getMyPageTeamBlocks), getMyPageTeamBlocks); + } + + private List calculateCategory(List getMyPageTeamBlocks) { + return getMyPageTeamBlocks.stream() + .map(GetMyPageTeamBlock::getCategory) + .distinct() + .limit(2) + .collect(Collectors.toList()); + } + +} diff --git a/src/main/java/com/moing/backend/domain/mypage/presentation/MyPageController.java b/src/main/java/com/moing/backend/domain/mypage/presentation/MyPageController.java index bfc89771..928980fc 100644 --- a/src/main/java/com/moing/backend/domain/mypage/presentation/MyPageController.java +++ b/src/main/java/com/moing/backend/domain/mypage/presentation/MyPageController.java @@ -3,11 +3,9 @@ import com.moing.backend.domain.mypage.application.dto.request.UpdateProfileRequest; import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest; import com.moing.backend.domain.mypage.application.dto.response.GetAlarmResponse; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse; import com.moing.backend.domain.mypage.application.dto.response.GetProfileResponse; -import com.moing.backend.domain.mypage.application.service.AlarmUserCase; -import com.moing.backend.domain.mypage.application.service.ProfileUserCase; -import com.moing.backend.domain.mypage.application.service.SignOutUserCase; -import com.moing.backend.domain.mypage.application.service.WithdrawUserCase; +import com.moing.backend.domain.mypage.application.service.*; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -28,8 +26,9 @@ public class MyPageController { private final WithdrawUserCase withdrawService; private final ProfileUserCase profileUserCase; private final AlarmUserCase alarmUserCase; + private final GetMyPageUserCase getMyPageUserCase; - //TODO 마이페이지 조회, 알림설정 수정 + //TODO 알림설정 수정 /** * 로그아웃 @@ -54,6 +53,16 @@ public ResponseEntity withdraw(@AuthenticationPrincipal User us return ResponseEntity.ok(SuccessResponse.create(WITHDRAWAL_SUCCESS.getMessage())); } + /** + * 마이페이지 조회 + * [GET] api/mypage + * 작성자: 김민수 + */ + @GetMapping + public ResponseEntity> getMyPage(@AuthenticationPrincipal User user){ + return ResponseEntity.ok(SuccessResponse.create(GET_MYPAGE_SUCCESS.getMessage(), this.getMyPageUserCase.getMyPageResponse(user.getSocialId()))); + } + /** * 프로필 조회 * [GET] api/mypage/profile diff --git a/src/main/java/com/moing/backend/domain/mypage/presentation/constant/MypageResponseMessage.java b/src/main/java/com/moing/backend/domain/mypage/presentation/constant/MypageResponseMessage.java index 463f5ddb..085033a7 100644 --- a/src/main/java/com/moing/backend/domain/mypage/presentation/constant/MypageResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/mypage/presentation/constant/MypageResponseMessage.java @@ -8,6 +8,7 @@ public enum MypageResponseMessage { SIGN_OUT_SUCCESS("로그아웃을 했습니다"), WITHDRAWAL_SUCCESS("회원탈퇴를 했습니다"), + GET_MYPAGE_SUCCESS("마이페이지를 조회했습니다"), GET_PROFILE_SUCCESS("프로필을 조회했습니다"), UPDATE_PROFILE_SUCCESS("프로필을 수정했습니다"), GET_ALARM_SUCCESS("알람 정보를 조회했습니다"), diff --git a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepository.java b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepository.java index fdbd1a88..43d7b559 100644 --- a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepository.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.team.domain.repository; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; import com.moing.backend.domain.team.application.dto.response.GetTeamDetailResponse; import com.moing.backend.domain.team.application.dto.response.GetTeamResponse; import com.moing.backend.domain.team.domain.entity.Team; @@ -11,4 +12,5 @@ public interface TeamCustomRepository { GetTeamResponse findTeamByMemberId(Long memberId); Optional findTeamByTeamId(Long TeamId); List findTeamIdByMemberId(Long memberId); + List findMyPageTeamByMemberId(Long memberId); } diff --git a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java index be1b15ab..6d14e618 100644 --- a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java @@ -1,14 +1,15 @@ package com.moing.backend.domain.team.domain.repository; -import com.moing.backend.domain.member.domain.entity.QMember; -import com.moing.backend.domain.team.application.dto.response.*; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; +import com.moing.backend.domain.team.application.dto.response.GetTeamResponse; +import com.moing.backend.domain.team.application.dto.response.QTeamBlock; +import com.moing.backend.domain.team.application.dto.response.TeamBlock; import com.moing.backend.domain.team.domain.constant.ApprovalStatus; import com.moing.backend.domain.team.domain.entity.Team; -import com.querydsl.jpa.JPAExpressions; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; -import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -59,6 +60,19 @@ public List findTeamIdByMemberId(Long memberId){ .fetch(); } + @Override + public List findMyPageTeamByMemberId(Long memberId) { + return queryFactory + .select(Projections.constructor(GetMyPageTeamBlock.class, + team.teamId, team.name, team.category)) + .from(teamMember) + .innerJoin(teamMember.team, team) + .on(teamMember.member.memberId.eq(memberId)) + .where(team.approvalStatus.eq(ApprovalStatus.APPROVAL)) // 승인 되었고 + .orderBy(team.missions.size().desc()) + .fetch(); + } + private List getTeamBlock(Long memberId) { LocalDateTime threeDaysAgo = LocalDateTime.now().minusDays(3); diff --git a/src/main/java/com/moing/backend/domain/team/domain/service/TeamGetService.java b/src/main/java/com/moing/backend/domain/team/domain/service/TeamGetService.java index 56e9e372..90e530fd 100644 --- a/src/main/java/com/moing/backend/domain/team/domain/service/TeamGetService.java +++ b/src/main/java/com/moing/backend/domain/team/domain/service/TeamGetService.java @@ -1,6 +1,7 @@ package com.moing.backend.domain.team.domain.service; import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; import com.moing.backend.domain.team.application.dto.response.GetTeamResponse; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.team.domain.repository.TeamRepository; @@ -28,4 +29,8 @@ public List getTeamIdByMemberId(Long memberId) { public Team getTeamByTeamId(Long teamId){ return teamRepository.findTeamByTeamId(teamId).orElseThrow(()->new NotFoundByTeamIdException()); } + + public List getMyPageTeamBlockByMemberId(Long memberId){ + return teamRepository.findMyPageTeamByMemberId(memberId); + } } diff --git a/src/main/java/com/moing/backend/domain/team/exception/AlreadyJoinTeamException.java b/src/main/java/com/moing/backend/domain/team/exception/AlreadyJoinTeamException.java new file mode 100644 index 00000000..4c12a0ac --- /dev/null +++ b/src/main/java/com/moing/backend/domain/team/exception/AlreadyJoinTeamException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.team.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class AlreadyJoinTeamException extends TeamException{ + public AlreadyJoinTeamException(){ + super(ErrorCode.ALREADY_JOIN_ERROR, + HttpStatus.UNAUTHORIZED); + } +} diff --git a/src/main/java/com/moing/backend/domain/team/exception/AlreadyWithdrawTeamException.java b/src/main/java/com/moing/backend/domain/team/exception/AlreadyWithdrawTeamException.java new file mode 100644 index 00000000..218d7e3b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/team/exception/AlreadyWithdrawTeamException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.team.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class AlreadyWithdrawTeamException extends TeamException{ + public AlreadyWithdrawTeamException(){ + super(ErrorCode.ALREADY_WITHDRAW_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberSaveService.java b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberSaveService.java index 13e6851a..f3ca19d0 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberSaveService.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberSaveService.java @@ -2,20 +2,36 @@ import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.team.exception.AlreadyJoinTeamException; +import com.moing.backend.domain.team.exception.AlreadyWithdrawTeamException; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import com.moing.backend.domain.teamMember.domain.repository.TeamMemberRepository; import com.moing.backend.global.annotation.DomainService; import lombok.RequiredArgsConstructor; +import javax.transaction.Transactional; +import java.util.Optional; + @DomainService @RequiredArgsConstructor +@Transactional public class TeamMemberSaveService { private final TeamMemberRepository teamMemberRepository; public void addTeamMember(Team team, Member member){ - TeamMember teamMember=new TeamMember(); - teamMember.updateMember(member); - teamMember.updateTeam(team); - team.addTeamMember(); - this.teamMemberRepository.save(teamMember); + Optional existingTeamMemberOpt = teamMemberRepository.findTeamMemberByTeamAndMember(team, member); + + TeamMember teamMember = existingTeamMemberOpt.orElseGet(() -> { + TeamMember newMember = new TeamMember(); + newMember.updateMember(member); + newMember.updateTeam(team); + team.addTeamMember(); + return teamMemberRepository.save(newMember); + }); + + if (teamMember.isDeleted()) { + throw new AlreadyWithdrawTeamException(); + } else { + throw new AlreadyJoinTeamException(); + } } } diff --git a/src/main/java/com/moing/backend/global/response/ErrorCode.java b/src/main/java/com/moing/backend/global/response/ErrorCode.java index d3ffc8dd..45b306d2 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -39,6 +39,8 @@ public enum ErrorCode { //팀 관련 에러 코드 NOT_FOUND_BY_TEAM_ID_ERROR("T0001", "해당 teamId인 팀이 존재하지 않습니다."), NOT_AUTH_BY_TEAM_ERROR("T0002","권한이 없습니다."), + ALREADY_WITHDRAW_ERROR("T0003","이미 탈퇴한 회원입니다."), + ALREADY_JOIN_ERROR("T0004","이미 가입한 회원입니다."), //게시글 관련 에러 코드 NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 게시글이 존재하지 않습니다."), From 5b2da5ccc853695e8a5a015eaac3d37d388e6527 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sun, 22 Oct 2023 15:48:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EC=86=8C=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/domain/repository/TeamCustomRepositoryImpl.java | 3 +++ .../domain/repository/TeamMemberCustomRepositoryImpl.java | 1 + 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java index 6d14e618..f0132576 100644 --- a/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java @@ -56,6 +56,7 @@ public List findTeamIdByMemberId(Long memberId){ .where(teamMember.isDeleted.eq(false)) // 탈퇴하지 않았다면 .where(team.isDeleted.eq(false) // 강제종료되지 않았거나 .or(team.deletionTime.after(threeDaysAgo))) // 강제종료된 경우 3일이 지나지 않았다면 + .groupBy(team.teamId) .orderBy(team.approvalTime.asc()) .fetch(); } @@ -70,6 +71,7 @@ public List findMyPageTeamByMemberId(Long memberId) { .on(teamMember.member.memberId.eq(memberId)) .where(team.approvalStatus.eq(ApprovalStatus.APPROVAL)) // 승인 되었고 .orderBy(team.missions.size().desc()) + .groupBy(team.teamId) .fetch(); } @@ -92,6 +94,7 @@ private List getTeamBlock(Long memberId) { .or(team.deletionTime.isNotNull() .or(team.deletionTime.after(threeDaysAgo)))) // 강제종료된 경우 3일이 지나지 않았다면 .orderBy(team.approvalTime.asc()) + .groupBy(team.teamId) .fetch(); } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java index cd5cbaf2..c8d7cf6b 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java @@ -66,6 +66,7 @@ public List findTeamMemberInfoByTeamId(Long teamId){ .innerJoin(teamMember.team, team) // innerJoin을 사용하여 최적화 .where(teamMember.team.teamId.eq(teamId) // where 절을 하나로 합침 .and(teamMember.isDeleted.eq(false))) + .groupBy(teamMember.member.memberId) .fetch(); } } From d413ef91ca9ba8649884ec05b6bd37f610c256d9 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sun, 22 Oct 2023 16:00:32 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20test=20docs=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Mypage-API.adoc | 4 ++ .../presentation/MypageControllerTest.java | 69 +++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/docs/asciidoc/Mypage-API.adoc b/src/docs/asciidoc/Mypage-API.adoc index 58e5ef94..59e4d843 100644 --- a/src/docs/asciidoc/Mypage-API.adoc +++ b/src/docs/asciidoc/Mypage-API.adoc @@ -11,6 +11,10 @@ operation::mypage-controller-test/sign_out[snippets='http-request,http-response, === Mypage 회원탈퇴 operation::mypage-controller-test/withdraw[snippets='http-request,request-fields,http-response,response-fields'] +[[Mypage-전체-조회]] +=== Mypage 전체 조회 +operation::mypage-controller-test/get_mypage[snippets='http-request,http-response,response-fields'] + [[Mypage-프로필-조회]] === Mypage 프로필 조회 operation::mypage-controller-test/get_profile[snippets='http-request,http-response,response-fields'] diff --git a/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java b/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java index 277100a0..161680db 100644 --- a/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java +++ b/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java @@ -3,18 +3,21 @@ import com.moing.backend.config.CommonControllerTest; import com.moing.backend.domain.mypage.application.dto.request.UpdateProfileRequest; import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; import com.moing.backend.domain.mypage.application.dto.response.GetProfileResponse; -import com.moing.backend.domain.mypage.application.service.AlarmUserCase; -import com.moing.backend.domain.mypage.application.service.ProfileUserCase; -import com.moing.backend.domain.mypage.application.service.SignOutUserCase; -import com.moing.backend.domain.mypage.application.service.WithdrawUserCase; +import com.moing.backend.domain.mypage.application.service.*; import com.moing.backend.domain.team.application.dto.response.CreateTeamResponse; +import com.moing.backend.domain.team.domain.constant.Category; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; +import java.util.ArrayList; +import java.util.List; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -37,6 +40,9 @@ public class MypageControllerTest extends CommonControllerTest { @MockBean private AlarmUserCase alarmUserCase; + @MockBean + private GetMyPageUserCase getMyPageUserCase; + @Test public void sign_out() throws Exception { //when @@ -101,6 +107,61 @@ public void withdraw() throws Exception { ); } + @Test + public void get_mypage() throws Exception{ + //given + List categoryList=new ArrayList<>(); + categoryList.add(Category.SPORTS); + + List getMyPageTeamBlocks=new ArrayList<>(); + GetMyPageTeamBlock blocks= GetMyPageTeamBlock.builder() + .teamId(1L) + .teamName("소모임이름") + .category(Category.SPORTS) + .build(); + getMyPageTeamBlocks.add(blocks); + + GetMyPageResponse output = GetMyPageResponse.builder() + .profileImage("PROFILE_IMAGE_URL") + .introduction("INTRODUCTION") + .nickName("NICKNAME") + .categories(categoryList) + .getMyPageTeamBlocks(getMyPageTeamBlocks) + .build(); + + given(getMyPageUserCase.getMyPageResponse(any())).willReturn(output); + + //when + ResultActions actions = mockMvc.perform( + get("/api/mypage") + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + ); + + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("마이페이지를 조회했습니다"), + fieldWithPath("data.profileImage").description("프로필 이미지 URL"), + fieldWithPath("data.nickName").description("닉네임"), + fieldWithPath("data.introduction").description("한줄 소개"), + fieldWithPath("data.categories[0]").description("내 열정의 불 해시태그"), + fieldWithPath("data.getMyPageTeamBlocks[0].teamId").description("소모임 아이디"), + fieldWithPath("data.getMyPageTeamBlocks[0].teamName").description("소모임 이름"), + fieldWithPath("data.getMyPageTeamBlocks[0].category").description("소모임 카테고리") + ) + ) + ); + } + @Test public void get_profile() throws Exception { //given