Skip to content

Commit

Permalink
Merge pull request #65 from Modagbul/feat/mission
Browse files Browse the repository at this point in the history
fix : 반복미션만 3개 제한으로 로직 변경
  • Loading branch information
seungueonn authored Nov 8, 2023
2 parents 4d61859 + b1b3818 commit 2db80ce
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moing.backend.domain.mission.application.dto.res;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Builder
@Getter
@Setter
public class MissionRecommendRes {
String category;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mission.application.dto.req.MissionReq;
import com.moing.backend.domain.mission.application.dto.res.MissionCreateRes;
import com.moing.backend.domain.mission.application.dto.res.MissionRecommendRes;
import com.moing.backend.domain.mission.application.mapper.MissionMapper;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
import com.moing.backend.domain.mission.domain.service.MissionQueryService;
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.domain.team.domain.service.TeamGetService;
import com.moing.backend.global.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -25,19 +28,21 @@
public class MissionCreateUseCase {

private final MissionSaveService missionSaveService;
private final TeamRepository teamRepository;
private final MissionQueryService missionQueryService;
private final TeamGetService teamGetService;
private final MemberGetService memberGetService;

public MissionCreateRes createMission(String userSocialId, Long teamId, MissionReq missionReq) {

Member member = memberGetService.getMemberBySocialId(userSocialId);
Team team = teamRepository.findById(teamId).orElseThrow();
Team team = teamGetService.getTeamByTeamId(teamId);

// 소모임 장 확인
if (member.getMemberId().equals(team.getLeaderId())) {
Mission mission = MissionMapper.mapToMission(missionReq, member, MissionStatus.ONGOING);
// teamRepository 변경 예정
if (team.getMissions().size() > 3) {

if (missionQueryService.isAbleCreateRepeatMission(team.getTeamId())) {
throw new NoMoreCreateMission();
}
mission.setTeam(team);
Expand All @@ -53,4 +58,12 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR

}

public MissionRecommendRes getCategoryByTeam(Long teamId) {
Team team = teamGetService.getTeamByTeamId(teamId);

return MissionRecommendRes.builder()
.category(team.getCategory().name())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public interface MissionCustomRepository {

Optional<List<Long>> findOngoingRepeatMissions();

boolean findRepeatMissionsByTeamId(Long teamId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,15 @@ public Optional<List<GatherSingleMissionRes>> findSingleMissionByMemberId(Long m
.fetch());
}

public boolean findRepeatMissionsByTeamId(Long teamId) {
return queryFactory
.select(mission)
.from(mission)
.where(
mission.team.teamId.eq(teamId),
mission.type.eq(MissionType.REPEAT),
mission.status.eq(MissionStatus.ONGOING)
).fetchCount() < 3;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public List<Mission> findMissionByDueTo() {
public List<Long> findOngoingRepeatMissions() {
return missionRepository.findOngoingRepeatMissions().orElseThrow(NotFoundOngoingMissionException::new);
}

public boolean isAbleCreateRepeatMission(Long teamId) {
return missionRepository.findRepeatMissionsByTeamId(teamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum ErrorCode {
NO_ACCESS_CREATE_MISSION("M0001", "소모임장만 미션을 생성할 수 있습니다."),
NOT_FOUND_MISSION("M0002", "미션을 찾을 수 없습니다."),
NOT_FOUND_END_MISSION("M0003", "기한이 지난 미션을 찾을 수 없습니다."),
NO_MORE_CREATE_MISSION("M0004", "반복미션은 3개까지 생성할 수 없습니다."),
NO_MORE_CREATE_MISSION("M0004", "반복미션은 3개까지 생성할 수 있습니다."),
NOT_FOUND_MISSION_ARCHIVE("MA0001", "아직 미션을 제출하지 않았습니다."),
NO_MORE_ARCHIVE_ERROR("MA0001", "지정한 횟수 이상 미션을 인증할 수 없습니다."),

Expand Down

0 comments on commit 2db80ce

Please sign in to comment.