Skip to content

Commit

Permalink
Merge pull request #64 from Modagbul/feat/mission
Browse files Browse the repository at this point in the history
Feat/mission
  • Loading branch information
seungueonn authored Nov 6, 2023
2 parents 927611d + a12865c commit 4d61859
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/docs/asciidoc/MissionGatherBoard-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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-미션-모아보기-팀별]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -46,6 +50,7 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR




}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public List<GatherRepeatMissionRes> getAllActiveRepeatMissions(String userId) {

}

public List<GatherSingleMissionRes> getTeamActiveSingleMissions(String userId,Long teamId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
return missionQueryService.findTeamSingleMission(memberId,teamId);

}
public List<GatherRepeatMissionRes> getTeamActiveRepeatMissions(String userId,Long teamId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
return missionQueryService.findTeamRepeatMission(memberId,teamId);

}

public List<MissionArchivePhotoRes> getArchivePhotoByTeamRes(String userId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public interface MissionCustomRepository {

Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long memberId, List<Long>teams);


Optional<List<Mission>> findMissionByDueTo();

Optional<List<Long>> findOngoingRepeatMissions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public List<GatherSingleMissionRes> findAllSingleMission(Long memberId) {
return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new);
}

public List<GatherRepeatMissionRes> findTeamRepeatMission(Long memberId,Long teamId) {
List<Long> teams = new ArrayList<>();
teams.add(teamId);
return missionRepository.findRepeatMissionByMemberId(memberId,teams).orElseThrow(NotFoundMissionException::new);
}

public List<GatherSingleMissionRes> findTeamSingleMission(Long memberId,Long teamId) {
List<Long> teams = new ArrayList<>();
teams.add(teamId);
return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new);
}

/**
* 스케쥴러에서 한시간 단위로 실행
* 현재 시간으로부터 1시간 이내 종료 되는 미션 리턴
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("내가 속한 팀을 모두 조회했습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +37,7 @@ public class MissionGatherController {

@GetMapping("/my-once")
public ResponseEntity<SuccessResponse<List<GatherSingleMissionRes>>> 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())));
}

/**
Expand All @@ -45,6 +46,28 @@ public ResponseEntity<SuccessResponse<List<GatherSingleMissionRes>>> getMyActive
* 작성자 : 정승연
*/

@GetMapping("/team-repeat/{teamId}")
public ResponseEntity<SuccessResponse<List<GatherRepeatMissionRes>>> 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<SuccessResponse<List<GatherSingleMissionRes>>> 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<SuccessResponse<List<GatherRepeatMissionRes>>> getMyActiveRepeatMission(@AuthenticationPrincipal User user) {
return ResponseEntity.ok(SuccessResponse.create(ACTIVE_REPEAT_MISSION_SUCCESS.getMessage(), this.missionGatherBoardUseCase.getAllActiveRepeatMissions( user.getSocialId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "지정한 횟수 이상 미션을 인증할 수 없습니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,105 @@ public class MissionGatherControllerTest extends CommonControllerTest {
)
.andReturn();

}

@Test
public void 팀별_미션_모아보기_단일_미션() throws Exception {
//given

List<GatherSingleMissionRes> 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<GatherRepeatMissionRes> 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 {
Expand Down

0 comments on commit 4d61859

Please sign in to comment.