diff --git a/src/docs/asciidoc/MissionGatherBoard-API.adoc b/src/docs/asciidoc/MissionGatherBoard-API.adoc index d19a5ccf..8a29140e 100644 --- a/src/docs/asciidoc/MissionGatherBoard-API.adoc +++ b/src/docs/asciidoc/MissionGatherBoard-API.adoc @@ -12,6 +12,16 @@ operation::mission-gather-controller-test/미션_모아보기_단일_미션[snip == 미션_모아보기_반복_미션 operation::mission-gather-controller-test/미션_모아보기_반복_미션[snippets='http-request,http-response,response-fields'] +--- +[[MissionBoard-팀별-미션-모아보기-단일]] +== 팀별_미션_모아보기_단일_미션 +operation::mission-gather-controller-test/팀별_미션_모아보기_단일_미션[snippets='http-request,http-response,response-fields'] +--- + +[[MissionBoard-팀별-미션-모아보기-반복]] +== 팀별_미션_모아보기_반복_미션 +operation::mission-gather-controller-test/팀별_미션_모아보기_반복_미션[snippets='http-request,http-response,response-fields'] + --- [[MissionBoard-미션-모아보기-팀별]] diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java index dd4756e7..850b9dbb 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java @@ -11,6 +11,7 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.mission.domain.service.MissionSaveService; import com.moing.backend.domain.mission.exception.NoAccessCreateMission; +import com.moing.backend.domain.mission.exception.NoMoreCreateMission; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.team.domain.repository.TeamRepository; import com.moing.backend.global.util.SecurityUtils; @@ -36,6 +37,9 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR if (member.getMemberId().equals(team.getLeaderId())) { Mission mission = MissionMapper.mapToMission(missionReq, member, MissionStatus.ONGOING); // teamRepository 변경 예정 + if (team.getMissions().size() > 3) { + throw new NoMoreCreateMission(); + } mission.setTeam(team); missionSaveService.save(mission); return MissionMapper.mapToMissionCreateRes(mission); @@ -46,6 +50,7 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR + } } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionGatherBoardUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionGatherBoardUseCase.java index f808dd6c..0b502fea 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionGatherBoardUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionGatherBoardUseCase.java @@ -37,6 +37,17 @@ public List getAllActiveRepeatMissions(String userId) { } + public List getTeamActiveSingleMissions(String userId,Long teamId) { + Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId(); + return missionQueryService.findTeamSingleMission(memberId,teamId); + + } + public List getTeamActiveRepeatMissions(String userId,Long teamId) { + Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId(); + return missionQueryService.findTeamRepeatMission(memberId,teamId); + + } + public List getArchivePhotoByTeamRes(String userId) { Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId(); diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java index e545111e..c98198f6 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java @@ -17,7 +17,6 @@ public interface MissionCustomRepository { Optional> findRepeatMissionByMemberId(Long memberId, Listteams); - Optional> findMissionByDueTo(); Optional> findOngoingRepeatMissions(); diff --git a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java index 6d1e4f10..08d13f14 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java @@ -43,6 +43,18 @@ public List findAllSingleMission(Long memberId) { return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new); } + public List findTeamRepeatMission(Long memberId,Long teamId) { + List teams = new ArrayList<>(); + teams.add(teamId); + return missionRepository.findRepeatMissionByMemberId(memberId,teams).orElseThrow(NotFoundMissionException::new); + } + + public List findTeamSingleMission(Long memberId,Long teamId) { + List teams = new ArrayList<>(); + teams.add(teamId); + return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new); + } + /** * 스케쥴러에서 한시간 단위로 실행 * 현재 시간으로부터 1시간 이내 종료 되는 미션 리턴 diff --git a/src/main/java/com/moing/backend/domain/mission/exception/NoMoreCreateMission.java b/src/main/java/com/moing/backend/domain/mission/exception/NoMoreCreateMission.java new file mode 100644 index 00000000..76c525f4 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/exception/NoMoreCreateMission.java @@ -0,0 +1,12 @@ +package com.moing.backend.domain.mission.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NoMoreCreateMission extends MissionException { + + public NoMoreCreateMission() { + super(ErrorCode.NO_MORE_CREATE_MISSION, + HttpStatus.UNAUTHORIZED); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java index d6d623b1..8f278ce6 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java @@ -13,8 +13,10 @@ public enum MissionArchiveResponseMessage { READ_TEAM_ARCHIVE_SUCCESS("팀원 미션 인증 현황 조회를 완료 했습니다."), HEART_UPDATE_SUCCESS("미션 인증 좋아요를 성공적으로 눌렀습니다."), MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS("미션 인증 성공한 인원 상태 조회를 완료 했습니다."), - ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 한번 인증 미션 조회를 완료 했습니다."), - ACTIVE_REPEAT_MISSION_SUCCESS("진행 중인 반복 인증 미션 조회를 완료 했습니다."), + ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 모든 한번 인증 미션 조회를 완료 했습니다."), + ACTIVE_REPEAT_MISSION_SUCCESS("진행 중인 모든 반복 인증 미션 조회를 완료 했습니다."), + ACTIVE_TEAM_SINGLE_MISSION_SUCCESS("진행 중인 팀별 한번 인증 미션 조회를 완료 했습니다."), + ACTIVE_TEAM_REPEAT_MISSION_SUCCESS("진행 중인 팀별 반복 인증 미션 조회를 완료 했습니다."), FINISH_ALL_MISSION_SUCCESS("종료된 미션 조회를 완료하였습니다."), MISSION_ARCHIVE_BY_TEAM("팀별 미션 인증물 사진 조회를 완료했습니다."), GET_MY_TEAM_LIST_SUCCESS("내가 속한 팀을 모두 조회했습니다."); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionGatherController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionGatherController.java index 2c798a35..6a6a2694 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionGatherController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionGatherController.java @@ -13,6 +13,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -36,7 +37,7 @@ public class MissionGatherController { @GetMapping("/my-once") public ResponseEntity>> getMyActiveSingleMission(@AuthenticationPrincipal User user) { - return ResponseEntity.ok(SuccessResponse.create(ACTIVE_SINGLE_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getAllActiveSingleMissions(user.getSocialId()))); + return ResponseEntity.ok(SuccessResponse.create(ACTIVE_TEAM_SINGLE_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getAllActiveSingleMissions(user.getSocialId()))); } /** @@ -45,6 +46,28 @@ public ResponseEntity>> getMyActive * 작성자 : 정승연 */ + @GetMapping("/team-repeat/{teamId}") + public ResponseEntity>> getTeamActiveRepeatMission(@AuthenticationPrincipal User user ,@PathVariable Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(ACTIVE_TEAM_REPEAT_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getTeamActiveRepeatMissions( user.getSocialId(),teamId))); + } + + /** + * 팀별 미션 모아보기 - 단일 미션 + * [GET] my-single + * 작성자 : 정승연 + */ + + @GetMapping("/team-once/{teamId}") + public ResponseEntity>> getTeamActiveSingleMission(@AuthenticationPrincipal User user ,@PathVariable Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(ACTIVE_SINGLE_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getTeamActiveSingleMissions(user.getSocialId(),teamId))); + } + + /** + * 팀별 미션 모아보기 - 반복 미션 + * [GET] my-repeat + * 작성자 : 정승연 + */ + @GetMapping("/my-repeat") public ResponseEntity>> getMyActiveRepeatMission(@AuthenticationPrincipal User user) { return ResponseEntity.ok(SuccessResponse.create(ACTIVE_REPEAT_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getAllActiveRepeatMissions( user.getSocialId()))); 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 f3f29b6f..548f26fe 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -28,7 +28,8 @@ public enum ErrorCode { //미션 관련 에러코드 NO_ACCESS_CREATE_MISSION("M0001", "소모임장만 미션을 생성할 수 있습니다."), NOT_FOUND_MISSION("M0002", "미션을 찾을 수 없습니다."), - NOT_FOUND_END_MISSION("M0002", "기한이 지난 미션을 찾을 수 없습니다."), + NOT_FOUND_END_MISSION("M0003", "기한이 지난 미션을 찾을 수 없습니다."), + NO_MORE_CREATE_MISSION("M0004", "반복미션은 3개까지 생성할 수 없습니다."), NOT_FOUND_MISSION_ARCHIVE("MA0001", "아직 미션을 제출하지 않았습니다."), NO_MORE_ARCHIVE_ERROR("MA0001", "지정한 횟수 이상 미션을 인증할 수 없습니다."), diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionGatherControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionGatherControllerTest.java index 487a7d8a..6103418b 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionGatherControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionGatherControllerTest.java @@ -130,6 +130,105 @@ public class MissionGatherControllerTest extends CommonControllerTest { ) .andReturn(); + } + + @Test + public void 팀별_미션_모아보기_단일_미션() throws Exception { + //given + + List output = Lists.newArrayList(GatherSingleMissionRes.builder() + .missionId(1L) + .teamId(1L) + .dueTo("2023-09-03T21:32:33.888") + .teamName("team name") + .missionTitle("mission title") + .build()); + + given(missionGatherBoardUseCase.getTeamActiveSingleMissions(any(),any())).willReturn(output); + + Long teamId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/team/team-once/{teamId}",teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(ACTIVE_TEAM_SINGLE_MISSION_SUCCESS.getMessage()), + fieldWithPath("data[].missionId").description("미션 아이디"), + fieldWithPath("data[].teamId").description("팀 아이디"), + fieldWithPath("data[].dueTo").description("미션 마감 시각"), + fieldWithPath("data[].teamName").description("팀 이름"), + fieldWithPath("data[].missionTitle").description("미션 제목") + + ) + ) + ) + .andReturn(); + + } + + @Test + public void 팀별_미션_모아보기_반복_미션() throws Exception { + //given + + List output = Lists.newArrayList(GatherRepeatMissionRes.builder() + .missionId(1L) + .teamId(1L) + .teamName("team name") + .missionTitle("mission title") + .doneNum("0") + .totalNum("0") + .build()); + + given(missionGatherBoardUseCase.getTeamActiveRepeatMissions(any(),any())).willReturn(output); + + Long teamId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/team/team-repeat/{teamId}",teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(ACTIVE_TEAM_REPEAT_MISSION_SUCCESS.getMessage()), + fieldWithPath("data[].missionId").description("미션 아이디"), + fieldWithPath("data[].teamId").description("팀 아이디"), + fieldWithPath("data[].teamName").description("팀 이름"), + fieldWithPath("data[].missionTitle").description("미션 제목"), + fieldWithPath("data[].doneNum").description("완료한 횟수"), + fieldWithPath("data[].totalNum").description("전체 횟수") + + + ) + ) + ) + .andReturn(); + } @Test public void 미션_모아보기_팀별() throws Exception {