diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/MissionRecommendRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/MissionRecommendRes.java new file mode 100644 index 00000000..33663c13 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/MissionRecommendRes.java @@ -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; +} 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 850b9dbb..4062d51c 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 @@ -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; @@ -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); @@ -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(); + } + } 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 c98198f6..45b842f0 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 @@ -21,4 +21,7 @@ public interface MissionCustomRepository { Optional> findOngoingRepeatMissions(); + boolean findRepeatMissionsByTeamId(Long teamId); + + } \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java index 9cb1ff84..74fa2095 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java @@ -104,4 +104,15 @@ public Optional> 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; + } + } 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 08d13f14..3190e252 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 @@ -66,4 +66,8 @@ public List findMissionByDueTo() { public List findOngoingRepeatMissions() { return missionRepository.findOngoingRepeatMissions().orElseThrow(NotFoundOngoingMissionException::new); } + + public boolean isAbleCreateRepeatMission(Long teamId) { + return missionRepository.findRepeatMissionsByTeamId(teamId); + } } 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 548f26fe..28fe9bd0 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -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", "지정한 횟수 이상 미션을 인증할 수 없습니다."),