diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherRepeatMissionRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherRepeatMissionRes.java index 993fd70e..1859d7d1 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherRepeatMissionRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherRepeatMissionRes.java @@ -4,6 +4,8 @@ import lombok.Builder; import lombok.Getter; +import java.util.List; + @Getter @Builder @AllArgsConstructor @@ -16,6 +18,8 @@ public class GatherRepeatMissionRes { private String totalNum; private String doneNum; private String status; + private String donePeople; + private String totalPeople; } diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherSingleMissionRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherSingleMissionRes.java index 0b173365..718a4b87 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherSingleMissionRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/GatherSingleMissionRes.java @@ -3,9 +3,11 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.ToString; @Getter @Builder +@ToString @AllArgsConstructor public class GatherSingleMissionRes { private Long missionId; @@ -14,6 +16,16 @@ public class GatherSingleMissionRes { private String missionTitle; private String dueTo; private String status; + private Long done; + private Long total; - + public GatherSingleMissionRes(Long missionId, Long teamId, String teamName, String missionTitle, String dueTo, String status, Long total) { + this.missionId = missionId; + this.teamId = teamId; + this.teamName = teamName; + this.missionTitle = missionTitle; + this.dueTo = dueTo; + this.status = status; + this.total = total; + } } 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 4f2d2a33..c4d223ec 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 @@ -49,7 +49,7 @@ public MissionCreateRes createMission(String socialId, Long teamId, MissionReq m throw new NoAccessCreateMission(); // 반복미션은 최대 2개 생성 가능 } else if (missionQueryService.isAbleCreateRepeatMission(team.getTeamId())) { - throw new NoAccessCreateMission(); + throw new NoMoreCreateMission(); } // 반복미션 유예 해제 mission.updateStatus(MissionStatus.ONGOING); diff --git a/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java b/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java index c609fdff..d5d6c80f 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java @@ -6,7 +6,6 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionRead.domain.entity.MissionRead; -import com.moing.backend.domain.missionState.domain.entity.MissionState; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.global.entity.BaseTimeEntity; import lombok.AllArgsConstructor; @@ -56,9 +55,6 @@ public class Mission extends BaseTimeEntity { @OneToMany(mappedBy = "mission") List missionArchiveList = new ArrayList<>(); - - @OneToMany(mappedBy = "mission") - List missionStateList = new ArrayList<>(); @OneToMany(mappedBy = "mission") List missionReads=new ArrayList<>(); 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 cf525072..606f5ed3 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 @@ -10,21 +10,24 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.NumberPath; +import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; + import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.TemporalAdjusters; -import java.util.List; -import java.util.Optional; +import java.util.*; import static com.moing.backend.domain.mission.domain.entity.QMission.mission; import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.missionArchive; -import static com.moing.backend.domain.missionState.domain.entity.QMissionState.missionState; import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember; +import static com.querydsl.jpa.JPAExpressions.select; public class MissionCustomRepositoryImpl implements MissionCustomRepository{ @@ -48,7 +51,7 @@ public Long findMissionsCountByTeam(Long teamId) { @Override public Optional> findRepeatMissionByMemberId(Long memberId,Listteams) { - BooleanExpression dateInRange = createRepeatTypeConditionByState(); + BooleanExpression dateInRange = createRepeatTypeConditionByArchive(); return Optional.ofNullable(queryFactory .select(Projections.constructor(GatherRepeatMissionRes.class, @@ -57,13 +60,26 @@ public Optional> findRepeatMissionByMemberId(Long m mission.team.name, mission.title, mission.number.stringValue(), - missionState.count().stringValue(), - mission.status.stringValue() + missionArchive.count.max().coalesce(0L).stringValue(), + missionArchive.status.coalesce(mission.status).stringValue(), + + JPAExpressions + .select(teamMember.member.countDistinct().stringValue()) + .from(teamMember) + .where( + teamMember.team.eq(mission.team), + teamMember.member.memberId.in(RepeatMissionDonePeopleByWeek(mission.id)) + .or(teamMember.member.memberId.in(RepeatMissionDonePeopleByDay(mission.id))), + teamMember.isDeleted.ne(Boolean.TRUE) + ), + + mission.team.numOfMember.stringValue() + )) .from(mission) - .leftJoin(missionState) - .on(missionState.mission.eq(mission), - missionState.member.memberId.eq(memberId), + .leftJoin(missionArchive) + .on(missionArchive.mission.eq(mission), + missionArchive.member.memberId.eq(memberId), dateInRange ) .where( @@ -72,13 +88,42 @@ public Optional> findRepeatMissionByMemberId(Long m mission.type.eq(MissionType.REPEAT) ) - .groupBy(mission.id,mission.number) - .having(missionState.count().lt(mission.number) - ) // HAVING 절을 사용하여 조건 적용 - .orderBy(missionState.count().desc()) + .groupBy(mission) + .orderBy(mission.createdDate.desc()) .fetch()); } + private JPQLQuery RepeatMissionDonePeopleByDay(NumberPath missionId) { + + BooleanExpression dateInRange = createRepeatTypeConditionByArchive(); + BooleanExpression hasAlreadyVerifiedToday = hasAlreadyVerifiedToday(); + + return + select(missionArchive.member.memberId) + .from(missionArchive) + .where( + missionArchive.mission.id.eq(missionId), + (missionArchive.mission.type.eq(MissionType.REPEAT).and(dateInRange).and(hasAlreadyVerifiedToday)) + ).distinct(); + } + + private JPQLQuery RepeatMissionDonePeopleByWeek(NumberPath missionId) { + + BooleanExpression dateInRange = createRepeatTypeConditionByArchive(); + + return select(missionArchive.member.memberId) + .from(missionArchive) + .where( + missionArchive.mission.id.eq(missionId), + (missionArchive.mission.type.eq(MissionType.REPEAT).and(dateInRange)) + ) + .groupBy(missionArchive.mission.number, missionArchive.count) + .having( + missionArchive.count.max().goe(missionArchive.mission.number)) + .distinct(); + + } + @Override public Optional> findMissionByDueTo() { @@ -135,6 +180,7 @@ public Optional> findRepeatMissionByStatus(MissionStatus missionSt @Override public Optional> findSingleMissionByMemberId(Long memberId, List teams) { + BooleanExpression dateInRange = createRepeatTypeConditionByArchive(); return Optional.ofNullable(queryFactory .select(Projections.constructor(GatherSingleMissionRes.class, @@ -143,18 +189,29 @@ public Optional> findSingleMissionByMemberId(Long m mission.team.name, mission.title, mission.dueTo.stringValue(), - mission.status.stringValue() + missionArchive.status.coalesce(mission.status).stringValue(), + + JPAExpressions + .select(missionArchive.member.count().longValue()) + .from(missionArchive) + .where( + missionArchive.mission.id.eq(mission.id), + missionArchive.mission.type.eq(MissionType.REPEAT).and(dateInRange) + .or(missionArchive.mission.type.eq(MissionType.ONCE)) + ), + + mission.team.numOfMember.longValue() )) .from(mission) - .leftJoin(missionState).on( - mission.eq(missionState.mission), - missionState.member.memberId.eq(memberId) - ) + .leftJoin(missionArchive) + .on( + mission.eq(missionArchive.mission), + missionArchive.member.memberId.eq(memberId) + ) .where( mission.team.teamId.in(teams), mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)), - mission.type.eq(MissionType.ONCE), - missionState.id.isNull() + mission.type.eq(MissionType.ONCE) ) .orderBy(mission.dueTo.asc()) .fetch()); @@ -171,6 +228,8 @@ public boolean findRepeatMissionsByTeamId(Long teamId) { ).fetchCount() > 2; } + + @Override public Optional findByIds(Long memberId, Long missionId) { @@ -270,34 +329,25 @@ public Long getYesterdayRepeatMissions() { } + + private BooleanExpression createRepeatTypeConditionByArchive() { LocalDate now = LocalDate.now(); DayOfWeek firstDayOfWeek = DayOfWeek.MONDAY; LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); LocalDate endOfWeek = startOfWeek.plusDays(6); - // MissionType.REPEAT 인 경우의 추가적인 날짜 범위 조건 -// BooleanExpression isRepeatType = missionArchive.mission.type.eq(MissionType.REPEAT); - BooleanExpression dateInRange = missionArchive.createdDate.goe(startOfWeek.atStartOfDay()) + return missionArchive.createdDate.goe(startOfWeek.atStartOfDay()) .and(missionArchive.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1))); - // 조건이 MissionType.REPEAT 인 경우에만 날짜 범위 조건 적용 - return dateInRange.and(dateInRange); } - private BooleanExpression createRepeatTypeConditionByState() { - LocalDate now = LocalDate.now(); - DayOfWeek firstDayOfWeek = DayOfWeek.MONDAY; - LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); - LocalDate endOfWeek = startOfWeek.plusDays(6); - - // MissionType.REPEAT 인 경우의 추가적인 날짜 범위 조건 -// BooleanExpression isRepeatType = missionArchive.mission.type.eq(MissionType.REPEAT); - BooleanExpression dateInRange = missionState.createdDate.goe(startOfWeek.atStartOfDay()) - .and(missionState.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1))); + private BooleanExpression hasAlreadyVerifiedToday() { + LocalDateTime today = LocalDateTime.now(); + LocalDateTime startOfToday = today.withHour(0).withMinute(0).withSecond(0).withNano(0); + LocalDateTime endOfToday = today.withHour(23).withMinute(59).withSecond(59).withNano(999999999); - // 조건이 MissionType.REPEAT 인 경우에만 날짜 범위 조건 적용 - return dateInRange.and(dateInRange); + return missionArchive.createdDate.between(startOfToday, endOfToday); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index 4d4ba925..618a02c7 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -10,13 +10,9 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveSaveService; import com.moing.backend.domain.missionArchive.exception.NoMoreMissionArchiveException; -import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; -import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; -import com.moing.backend.domain.missionHeart.domain.service.MissionHeartQueryService; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.teamScore.application.service.TeamScoreUpdateUseCase; import com.moing.backend.domain.teamScore.domain.entity.ScoreStatus; @@ -36,8 +32,6 @@ public class MissionArchiveCreateUseCase { private final MissionQueryService missionQueryService; private final MemberGetService memberGetService; - private final MissionStateUseCase missionStateUseCase; - private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; public MissionArchiveRes createArchive(String userSocialId, Long missionId, MissionArchiveReq missionReq) { @@ -64,8 +58,6 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss } newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId) + 1); - missionStateUseCase.updateMissionState(member, mission, newArchive); - missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive), memberId); } @@ -79,8 +71,6 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss } newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId)+1); - missionStateUseCase.updateMissionState(member, mission, newArchive); - missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive), memberId); // 인증 후 n/n명 인증 성공 리턴값 업데이트 @@ -137,4 +127,4 @@ private boolean isAbleToFinishOnceMission(Mission mission) { } -} +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java index 58ebc08d..362fec96 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java @@ -1,16 +1,11 @@ package com.moing.backend.domain.missionArchive.application.service; -import com.moing.backend.domain.infra.image.application.service.IssuePresignedUrlUseCase; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; 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.entity.constant.MissionWay; import com.moing.backend.domain.mission.domain.service.MissionQueryService; -import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; -import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; -import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; @@ -18,11 +13,6 @@ import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveSaveService; import com.moing.backend.domain.missionArchive.exception.NoAccessMissionArchiveException; import com.moing.backend.domain.missionHeart.domain.service.MissionHeartQueryService; -import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import com.moing.backend.domain.missionState.domain.service.MissionStateDeleteService; -import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; -import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.teamScore.application.service.TeamScoreUpdateUseCase; import com.moing.backend.domain.teamScore.domain.entity.ScoreStatus; @@ -38,18 +28,11 @@ @RequiredArgsConstructor public class MissionArchiveDeleteUseCase { - private final MissionArchiveSaveService missionArchiveSaveService; private final MissionArchiveQueryService missionArchiveQueryService; private final MissionArchiveDeleteService missionArchiveDeleteService; - private final MissionHeartQueryService missionHeartQueryService; - private final MissionQueryService missionQueryService; private final MemberGetService memberGetService; - - private final MissionStateDeleteService missionStateDeleteService; - private final MissionStateQueryService missionStateQueryService; - private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; private final UpdateUtils updateUtils; @@ -62,10 +45,8 @@ public Long deleteArchive(String userSocialId, Long missionId,Long count) { Long memberId = member.getMemberId(); Mission mission = missionQueryService.findMissionById(missionId); - Team team = mission.getTeam(); MissionArchive deleteArchive = missionArchiveQueryService.findOneMyArchive(memberId, missionId,count); - MissionState missionState = missionStateQueryService.findMissionState(member, mission); LocalDateTime createdDate = deleteArchive.getCreatedDate(); LocalDateTime today = LocalDateTime.now(); @@ -81,8 +62,6 @@ public Long deleteArchive(String userSocialId, Long missionId,Long count) { } missionArchiveDeleteService.deleteMissionArchive(deleteArchive); - missionStateDeleteService.deleteMissionState(missionState); - teamScoreUpdateUseCase.gainScoreOfArchive(mission, ScoreStatus.MINUS); return deleteArchive.getId(); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java index 4b459cd3..2d7222e7 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java @@ -1,23 +1,16 @@ package com.moing.backend.domain.missionArchive.application.service; -import com.moing.backend.domain.infra.image.application.service.IssuePresignedUrlUseCase; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; 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.entity.constant.MissionWay; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveSaveService; -import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; -import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; -import com.moing.backend.domain.missionHeart.domain.service.MissionHeartQueryService; import com.moing.backend.domain.missionArchive.exception.NoAccessMissionArchiveException; import com.moing.backend.domain.team.domain.entity.Team; import lombok.RequiredArgsConstructor; @@ -33,18 +26,11 @@ public class MissionArchiveUpdateUseCase { private final MissionArchiveSaveService missionArchiveSaveService; private final MissionArchiveQueryService missionArchiveQueryService; - private final MissionArchiveDeleteService missionArchiveDeleteService; - private final MissionHeartQueryService missionHeartQueryService; private final MissionQueryService missionQueryService; private final MemberGetService memberGetService; - private final IssuePresignedUrlUseCase getPresignedUrlUseCase; - - private final MissionStateSaveService missionStateSaveService; - private final MissionStateUseCase missionStateUseCase; - // 미션 재인증 (수정하기도 포함됨) -> 사용하지 않음 public MissionArchiveRes updateArchive(String userSocialId, Long missionId, MissionArchiveReq missionReq) { 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 4be74d90..88ab1b4d 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 @@ -14,6 +14,7 @@ public enum MissionArchiveResponseMessage { READ_TEAM_ARCHIVE_SUCCESS("팀원 미션 인증 현황 조회를 완료 했습니다."), HEART_UPDATE_SUCCESS("미션 인증 좋아요를 성공적으로 눌렀습니다."), MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS("미션 인증 성공한 인원 상태 조회를 완료 했습니다."), + MISSION_ARCHIVE_MY_STATUS_SUCCESS("미션 인증 성공한 나의 현황 조회를 완료 했습니다."), ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 모든 한번 인증 미션 조회를 완료 했습니다."), ACTIVE_REPEAT_MISSION_SUCCESS("진행 중인 모든 반복 인증 미션 조회를 완료 했습니다."), ACTIVE_TEAM_SINGLE_MISSION_SUCCESS("진행 중인 팀별 한번 인증 미션 조회를 완료 했습니다."), diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 9e016dfe..b222e0f2 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -37,7 +37,7 @@ import static com.moing.backend.domain.mission.domain.entity.QMission.mission; import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.missionArchive; -import static com.moing.backend.domain.missionState.domain.entity.QMissionState.missionState; +//import static com.moing.backend.domain.missionState.domain.entity.QMissionState.missionState; import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember; @Slf4j @@ -68,13 +68,13 @@ public Optional> findSingleMissionInComplete(Long me .from(mission) .where(mission.notIn (JPAExpressions - .select(missionState.mission) - .from(missionState) - .where(missionState.member.memberId.eq(memberId), - missionState.mission.team.teamId.eq(teamId), - missionState.mission.type.eq(MissionType.ONCE), - missionState.mission.status.eq(MissionStatus.SUCCESS) - .or(missionState.mission.status.eq(MissionStatus.ONGOING)) + .select(missionArchive.mission) + .from(missionArchive) + .where(missionArchive.member.memberId.eq(memberId), + missionArchive.mission.team.teamId.eq(teamId), + missionArchive.mission.type.eq(MissionType.ONCE), + missionArchive.mission.status.eq(MissionStatus.SUCCESS) + .or(missionArchive.mission.status.eq(MissionStatus.ONGOING)) )), mission.type.eq(MissionType.ONCE), mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)), @@ -269,16 +269,16 @@ public Optional> findRepeatMissionArchivesByMemberId mission.id, mission.title, // missionState.count().coalesce(0L).as("done"), - missionState.count(), + missionArchive.count(), mission.number, mission.way.stringValue(), mission.status.stringValue(), isReadExpression.as("isRead") )) .from(mission) - .leftJoin(missionState) - .on(missionState.mission.eq(mission), - missionState.member.memberId.eq(memberId), + .leftJoin(missionArchive) + .on(missionArchive.mission.eq(mission), + missionArchive.member.memberId.eq(memberId), dateInRange ) .where( @@ -288,7 +288,7 @@ public Optional> findRepeatMissionArchivesByMemberId ) .groupBy(mission.id,mission.number) // .having(missionState.count().lt(mission.number)) // HAVING 절을 사용하여 조건 적용 - .orderBy(missionState.count().desc()) + .orderBy(missionArchive.count().desc()) .fetch()); } @@ -401,8 +401,8 @@ private BooleanExpression createRepeatTypeConditionByState() { LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); LocalDate endOfWeek = startOfWeek.plusDays(6); - BooleanExpression dateInRange = missionState.createdDate.goe(startOfWeek.atStartOfDay()) - .and(missionState.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1))); + BooleanExpression dateInRange = missionArchive.createdDate.goe(startOfWeek.atStartOfDay()) + .and(missionArchive.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1))); // 조건이 MissionType.REPEAT 인 경우에만 날짜 범위 조건 적용 return dateInRange.and(dateInRange); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/exception/NoAccessMissionArchiveException.java b/src/main/java/com/moing/backend/domain/missionArchive/exception/NoAccessMissionArchiveException.java index 6ce6ada1..8bb4402e 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/exception/NoAccessMissionArchiveException.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/exception/NoAccessMissionArchiveException.java @@ -1,10 +1,9 @@ package com.moing.backend.domain.missionArchive.exception; -import com.moing.backend.domain.missionState.exception.MissionStateException; import com.moing.backend.global.response.ErrorCode; import org.springframework.http.HttpStatus; -public class NoAccessMissionArchiveException extends MissionStateException { +public class NoAccessMissionArchiveException extends MissionArchiveException { public NoAccessMissionArchiveException() { super(ErrorCode.NO_MORE_ARCHIVE_ERROR, HttpStatus.NOT_FOUND); diff --git a/src/main/java/com/moing/backend/domain/missionState/application/dto/MissionStatusRes.java b/src/main/java/com/moing/backend/domain/missionState/application/dto/MissionStatusRes.java deleted file mode 100644 index 0e12354f..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/application/dto/MissionStatusRes.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.moing.backend.domain.missionState.application.dto; - -public class MissionStatusRes { - - private Long done; - private Long total; - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateScheduleUseCase.java b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateScheduleUseCase.java deleted file mode 100644 index 025f790c..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateScheduleUseCase.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.moing.backend.domain.missionState.application.service; - -import com.moing.backend.domain.member.application.service.UpdateRemindAlarmUseCase; -import com.moing.backend.domain.mission.application.service.MissionRemindAlarmUseCase; -import com.moing.backend.domain.mission.application.service.SendMissionStartAlarmUseCase; -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.service.MissionQueryService; -import com.moing.backend.domain.missionState.domain.service.MissionStateDeleteService; -import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; -import com.moing.backend.domain.teamScore.application.service.TeamScoreUpdateUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Profile; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Slf4j -@Service -@Transactional -@EnableAsync -@EnableScheduling // 스케줄링 활성화 -@RequiredArgsConstructor -@Profile("prod") -public class MissionStateScheduleUseCase { - - private final MissionStateUseCase missionStateUseCase; - private final MissionRemindAlarmUseCase missionRemindAlarmUseCase; - private final MissionQueryService missionQueryService; - private final UpdateRemindAlarmUseCase updateRemindAlarmUseCase; - - private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; - - private final SendMissionStartAlarmUseCase sendMissionStartAlarmUseCase; - - /** - * 단일 미션 마감 - * 해당 시간 미션 마감 - * 한시간 마다 실행 - */ - @Scheduled(cron = "0 1 * * * *") - public void singleMissionEndRoutine() { - - List missionByDueTo = missionQueryService.findMissionByDueTo(); - - for (Mission mission : missionByDueTo) { - mission.updateStatus(MissionStatus.END); - } - - } - - - @Scheduled(cron = "0 0 20 * * *") - public void MissionRemindAlarm() { - missionRemindAlarmUseCase.sendRemindMissionAlarm(); - } - - -// @Scheduled(cron = "0 0 17 * * *") -// public void UpdatePushAlarm() { -// updateRemindAlarmUseCase.sendUpdateAppPushAlarm(); -// } - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java deleted file mode 100644 index 66615bca..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.moing.backend.domain.missionState.application.service; - -import com.moing.backend.domain.member.domain.entity.Member; -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.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionState.domain.service.MissionStateDeleteService; -import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; -import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; -import com.moing.backend.domain.teamScore.application.service.TeamScoreUpdateUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@Service -@Transactional -@RequiredArgsConstructor -public class MissionStateUseCase { - - // 미션 종료 직전인지 확인 - // missionId, missionstate num mission.team.personum - - private final MissionQueryService missionQueryService; - private final MissionStateQueryService missionStateQueryService; - private final MissionStateSaveService missionStateSaveService; - private final MissionStateDeleteService missionStateDeleteService; - - private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; - - - /* - 모든 모임원이 미션을 완료했는지 여부 확인 - */ - - public void updateMissionState(Member member, Mission mission, MissionArchive missionArchive) { - missionStateSaveService.saveMissionState(member,mission, missionArchive.getStatus()); - - } - - - - - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/entity/MissionState.java b/src/main/java/com/moing/backend/domain/missionState/domain/entity/MissionState.java deleted file mode 100644 index 22a550b8..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/entity/MissionState.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.moing.backend.domain.missionState.domain.entity; - -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; -import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; -import com.moing.backend.global.entity.BaseTimeEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import javax.persistence.*; - -@Entity -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -public class MissionState extends BaseTimeEntity { - - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "missionState_id") - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - private Mission mission; - @OneToOne - private Member member; - - @Enumerated(value = EnumType.STRING) - private MissionArchiveStatus status; - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/entity/Status.java b/src/main/java/com/moing/backend/domain/missionState/domain/entity/Status.java deleted file mode 100644 index 56f082a8..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/entity/Status.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.moing.backend.domain.missionState.domain.entity; - -public enum Status { - SUCCESS,FAIL -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java deleted file mode 100644 index 01166d64..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.moing.backend.domain.missionState.domain.repository; - -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -@Repository -public interface MissionStateCustomRepository { - - int getCountsByMissionId(Long missionId) ; - - List findByMissionId(List missionId); - List findByMissionId(Long missionId); - - Optional> findFinishMission(); - - Optional findMissionStateByMemberAndMission(Member member, Mission mission); - - - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java deleted file mode 100644 index 93cde112..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.moing.backend.domain.missionState.domain.repository; - -import com.moing.backend.domain.member.domain.entity.Member; -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.missionArchive.domain.entity.MissionArchiveStatus; -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import javax.persistence.EntityManager; - - -import java.time.DayOfWeek; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.temporal.TemporalAdjusters; -import java.util.List; -import java.util.Optional; - -import static com.moing.backend.domain.missionState.domain.entity.QMissionState.missionState; - -public class MissionStateCustomRepositoryImpl implements MissionStateCustomRepository { - - private final JPAQueryFactory queryFactory; - - public MissionStateCustomRepositoryImpl(EntityManager entityManager) { - this.queryFactory = new JPAQueryFactory(entityManager); - } - - - @Override - public int getCountsByMissionId(Long missionId) { - - LocalDate now = LocalDate.now(); - DayOfWeek firstDayOfWeek = DayOfWeek.MONDAY; // 한 주의 시작일을 월요일로 설정 - LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); - LocalDate endOfWeek = startOfWeek.plusDays(6); // 한 주의 마지막일을 일요일로 설정 - - BooleanExpression repeatTypeCondition = (missionState.mission.type.eq(MissionType.REPEAT) - .and(missionState.createdDate.goe(startOfWeek.atStartOfDay())) - .and(missionState.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1)))).or(missionState.mission.type.eq(MissionType.ONCE)); - - // 기본 조건 - BooleanExpression baseCondition = missionState.mission.id.eq(missionId); - // 조건 적용 - BooleanExpression finalCondition = baseCondition.and(repeatTypeCondition); - - - return queryFactory - .select(missionState) - .from(missionState) - .where(finalCondition) - .fetch().size(); - } - - @Override - public List findByMissionId(List missionId) { - - return queryFactory - .select(missionState) - .from(missionState) - .where( - missionState.mission.id.in(missionId) - ).fetch(); - - } - @Override - public List findByMissionId(Long missionId) { - - return queryFactory - .select(missionState) - .from(missionState) - .where( - missionState.mission.id.in(missionId) - ).fetch(); - - } - - @Override - public Optional> findFinishMission() { - return Optional.ofNullable(queryFactory - .select(missionState) - .from(missionState) - .where( - missionState.mission.dueTo.ne(LocalDateTime.now()), - missionState.mission.status.eq(MissionStatus.ONGOING) - - ).fetch() - ); - } - - public Optional findMissionStateByMemberAndMission(Member member, Mission mission) { - return Optional.ofNullable(queryFactory - .selectFrom(missionState) - .where(missionState.mission.eq(mission), - missionState.member.eq(member)) - .orderBy(missionState.createdDate.desc()) - .fetchFirst()); - } - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateRepository.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateRepository.java deleted file mode 100644 index 32d06a99..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.moing.backend.domain.missionState.domain.repository; - -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface MissionStateRepository extends JpaRepository,MissionStateCustomRepository { -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java b/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java deleted file mode 100644 index b99aa8b0..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.moing.backend.domain.missionState.domain.service; - -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import com.moing.backend.domain.missionState.domain.repository.MissionStateRepository; -import com.moing.backend.global.annotation.DomainService; -import lombok.RequiredArgsConstructor; - -import javax.transaction.Transactional; -import java.util.List; - -@DomainService -@Transactional -@RequiredArgsConstructor -public class MissionStateDeleteService { - - private final MissionStateRepository missionStateRepository; - - public void deleteMissionState(List missionStates) { - - missionStateRepository.deleteAll(missionStates); - } - public void deleteMissionState(MissionState missionStates) { - - missionStateRepository.delete(missionStates); - } - - public void deleteMissionStateByMission(Long missionId) { - - List missionStates = missionStateRepository.findByMissionId(missionId); - missionStateRepository.deleteAll(missionStates); - } -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryService.java b/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryService.java deleted file mode 100644 index 507a9529..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryService.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.moing.backend.domain.missionState.domain.service; - -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import com.moing.backend.domain.missionState.domain.repository.MissionStateRepository; -import com.moing.backend.global.annotation.DomainService; -import lombok.RequiredArgsConstructor; -import com.moing.backend.domain.missionState.exception.NotFoundMissionStateException; -import javax.transaction.Transactional; -import java.util.List; - -@DomainService -@Transactional -@RequiredArgsConstructor -public class MissionStateQueryService { - - private final MissionStateRepository missionStateRepository; - - public int stateCountByMissionId(Long missionId) { - return missionStateRepository.getCountsByMissionId(missionId); - } - - public List findByMissionId(List missionId) { - return missionStateRepository.findByMissionId(missionId); - } - - public List findFinishMission() { - return missionStateRepository.findFinishMission().orElseThrow(NotFoundMissionStateException::new); - } - - public MissionState findMissionState(Member member, Mission mission) { - return missionStateRepository.findMissionStateByMemberAndMission(member, mission).orElseThrow(NotFoundMissionStateException::new); - } - - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateSaveService.java b/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateSaveService.java deleted file mode 100644 index 1a1fc6e9..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateSaveService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.moing.backend.domain.missionState.domain.service; - -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; -import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; -import com.moing.backend.domain.missionState.domain.entity.MissionState; -import com.moing.backend.domain.missionState.domain.entity.Status; -import com.moing.backend.domain.missionState.domain.repository.MissionStateRepository; -import com.moing.backend.global.annotation.DomainService; -import lombok.RequiredArgsConstructor; - -import javax.transaction.Transactional; - -@DomainService -@Transactional -@RequiredArgsConstructor -public class MissionStateSaveService { - - private final MissionStateRepository missionStateRepository; - - public void saveMissionState(Member member, Mission mission, MissionArchiveStatus status) { - missionStateRepository.save(MissionState.builder() - .mission(mission) - .member(member) - .status(status) - .build()); - } - -} diff --git a/src/main/java/com/moing/backend/domain/missionState/exception/MissionStateException.java b/src/main/java/com/moing/backend/domain/missionState/exception/MissionStateException.java deleted file mode 100644 index 54c72e46..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/exception/MissionStateException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.moing.backend.domain.missionState.exception; - -import com.moing.backend.global.exception.ApplicationException; -import com.moing.backend.global.response.ErrorCode; -import org.springframework.http.HttpStatus; - -public abstract class MissionStateException extends ApplicationException { - protected MissionStateException(ErrorCode errorCode, HttpStatus httpStatus) { - super(errorCode, httpStatus); - } -} diff --git a/src/main/java/com/moing/backend/domain/missionState/exception/NotFoundMissionStateException.java b/src/main/java/com/moing/backend/domain/missionState/exception/NotFoundMissionStateException.java deleted file mode 100644 index 2baae393..00000000 --- a/src/main/java/com/moing/backend/domain/missionState/exception/NotFoundMissionStateException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.moing.backend.domain.missionState.exception; - -import com.moing.backend.global.response.ErrorCode; -import org.springframework.http.HttpStatus; - -public class NotFoundMissionStateException extends MissionStateException{ - public NotFoundMissionStateException() { - super(ErrorCode.NOT_FOUND_END_MISSION, HttpStatus.NOT_FOUND); - - } -} diff --git a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java index 999140b9..704cc979 100644 --- a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java @@ -13,7 +13,6 @@ import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; -import com.moing.backend.domain.missionState.domain.entity.MissionState; import com.moing.backend.domain.report.application.mapper.ReportMapper; import com.moing.backend.domain.report.domain.entity.Report; import com.moing.backend.domain.report.domain.entity.constant.ReportType; diff --git a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreGetUseCase.java b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreGetUseCase.java index a51f4026..df25b80c 100644 --- a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreGetUseCase.java +++ b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreGetUseCase.java @@ -1,16 +1,9 @@ package com.moing.backend.domain.teamScore.application.service; -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.mission.domain.service.MissionQueryService; -import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; -import com.moing.backend.domain.team.domain.entity.Team; -import com.moing.backend.domain.team.domain.service.TeamGetService; -import com.moing.backend.domain.team.domain.service.TeamSaveService; import com.moing.backend.domain.teamScore.application.dto.TeamScoreRes; import com.moing.backend.domain.teamScore.domain.entity.TeamScore; import com.moing.backend.domain.teamScore.domain.service.TeamScoreQueryService; -import com.moing.backend.domain.teamScore.domain.service.TeamScoreSaveService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreLogicUseCase.java b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreLogicUseCase.java new file mode 100644 index 00000000..1fc3566d --- /dev/null +++ b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreLogicUseCase.java @@ -0,0 +1,80 @@ +//package com.moing.backend.domain.teamScore.application.service; +// +// +//import com.moing.backend.domain.mission.domain.entity.Mission; +//import com.moing.backend.domain.mission.domain.service.MissionQueryService; +//import com.moing.backend.domain.missionState.domain.service.MissionArchiveStateQueryService; +//import com.moing.backend.domain.team.domain.entity.Team; +//import com.moing.backend.domain.team.domain.service.TeamGetService; +//import com.moing.backend.domain.team.domain.service.TeamSaveService; +//import com.moing.backend.domain.teamScore.application.dto.TeamScoreRes; +//import com.moing.backend.domain.teamScore.domain.entity.TeamScore; +//import com.moing.backend.domain.teamScore.domain.service.TeamScoreQueryService; +//import com.moing.backend.domain.teamScore.domain.service.TeamScoreSaveService; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Service; +//import org.springframework.transaction.annotation.Transactional; +//@Slf4j +//@Service +//@RequiredArgsConstructor +//public class TeamScoreLogicUseCase { +// +// private final MissionQueryService missionQueryService; +// private final TeamScoreQueryService teamScoreQueryService; +// private final MissionArchiveStateQueryService missionArchiveStateQueryService; +// +// public TeamScoreRes getTeamScoreInfo(Long teamId) { +// +// return TeamScoreRes.builder() +// .score(getScore(teamId)) +// .level(getLevel(teamId)) +// .build() +// ; +// } +// +// @Transactional +// public Long updateTeamScore(Long missionId) { +// Mission mission = missionQueryService.findMissionById(missionId); +// Team team = mission.getTeam(); +// TeamScore teamScore = teamScoreQueryService.findTeamScoreByTeam(team.getTeamId()); +// +// teamScore.updateScore(getScoreByMission(mission)); +// teamScore.levelUp(); +// +// return teamScore.getScore(); +// } +// +// public Long getScore(Long teamId) { +// return teamScoreQueryService.findTeamScoreByTeam(teamId).getScore(); +// } +// +// public Long getLevel(Long teamId) { +// return teamScoreQueryService.findTeamScoreByTeam(teamId).getLevel(); +// } +// +// public Long getScoreByMission(Mission mission) { +// float total = totalPeople(mission); +// float done = donePeople(mission); +// +// if (done == 0) { +// return 0L; +// } else { +// return (long) ((done / total * 100) / 5); +// } +// +// } +// +// public float donePeople(Mission mission) { +// return Float.valueOf(missionArchiveStateQueryService.stateCountByMissionId(mission.getId())); +// } +// +// public float totalPeople(Mission mission) { +// return Float.valueOf(mission.getTeam().getNumOfMember()); +// +// } +// +// +// +// +//} diff --git a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java index 04c88904..9b1c548a 100644 --- a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java @@ -73,5 +73,4 @@ public void gainScoreOfBonus(Mission mission) { - } diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java index 14a05e86..19912411 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java @@ -448,7 +448,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { ), responseFields( fieldWithPath("isSuccess").description("true"), - fieldWithPath("message").description(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage()), + fieldWithPath("message").description(MISSION_ARCHIVE_MY_STATUS_SUCCESS.getMessage()), fieldWithPath("data.total").description("전체 미션 참여자"), fieldWithPath("data.done").description("미션 인증 완료한 미션 참여자 ") 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 410eafee..ae0b21c2 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 @@ -1,8 +1,7 @@ package com.moing.backend.domain.missionArchive.representation; import com.moing.backend.config.CommonControllerTest; -import com.moing.backend.domain.mission.application.dto.res.GatherRepeatMissionRes; -import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes; +import com.moing.backend.domain.mission.application.dto.res.*; import com.moing.backend.domain.mission.application.service.MissionGatherBoardUseCase; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes; import com.moing.backend.domain.missionArchive.application.dto.res.MyTeamsRes; @@ -24,8 +23,7 @@ import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; @WebMvcTest(MissionGatherController.class) public class MissionGatherControllerTest extends CommonControllerTest { @@ -44,7 +42,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { .dueTo("2023-09-03T21:32:33.888") .teamName("team name") .missionTitle("mission title") - .status("WAIT/ONGOING/END/FAIL/SUCCESS") + .status("WAIT/ONGOING/SKIP/COMPLETE") + .done(0L) + .total(5L) .build()); given(missionGatherBoardUseCase.getAllActiveSingleMissions(any())).willReturn(output); @@ -74,8 +74,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { fieldWithPath("data[].dueTo").description("미션 마감 시각"), fieldWithPath("data[].teamName").description("팀 이름"), fieldWithPath("data[].missionTitle").description("미션 제목"), - fieldWithPath("data[].status").description("미션 상태") - + fieldWithPath("data[].status").description("WAIT/ONGOING=인증하지 않음 SKIP/COMPLETE=인증 완료"), + fieldWithPath("data[].done").description("미션 인증 한 인원수"), + fieldWithPath("data[].total").description("팀 전체 인원수") ) ) @@ -95,7 +96,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { .missionTitle("mission title") .doneNum("0") .totalNum("0") - .status("WAIT/ONGOING/END/FAIL/SUCCESS") + .status("WAIT/ONGOING/SKIP/COMPLETE") + .donePeople("0") + .totalPeople("0") .build()); given(missionGatherBoardUseCase.getAllActiveRepeatMissions(any())).willReturn(output); @@ -124,9 +127,11 @@ public class MissionGatherControllerTest extends CommonControllerTest { fieldWithPath("data[].teamId").description("팀 아이디"), fieldWithPath("data[].teamName").description("팀 이름"), fieldWithPath("data[].missionTitle").description("미션 제목"), - fieldWithPath("data[].doneNum").description("완료한 횟수"), + fieldWithPath("data[].doneNum").description("내가 완료한 횟수"), fieldWithPath("data[].totalNum").description("전체 횟수"), - fieldWithPath("data[].status").description("미션 상태") + fieldWithPath("data[].status").description("미션 상태"), + fieldWithPath("data[].donePeople").description("미션 완료한 인원수"), + fieldWithPath("data[].totalPeople").description("팀 전체 인원수") ) @@ -146,7 +151,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { .dueTo("2023-09-03T21:32:33.888") .teamName("team name") .missionTitle("mission title") - .status("WAIT/ONGOING/END/FAIL/SUCCESS") + .status("WAIT/ONGOING/SKIP/COMPLETE") + .done(0L) + .total(5L) .build()); given(missionGatherBoardUseCase.getTeamActiveSingleMissions(any(),any())).willReturn(output); @@ -177,8 +184,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { fieldWithPath("data[].dueTo").description("미션 마감 시각"), fieldWithPath("data[].teamName").description("팀 이름"), fieldWithPath("data[].missionTitle").description("미션 제목"), - fieldWithPath("data[].status").description("미션 상태") - + fieldWithPath("data[].status").description("WAIT/ONGOING=인증하지 않음 SKIP/COMPLETE=인증 완료"), + fieldWithPath("data[].done").description("미션 인증 한 인원수"), + fieldWithPath("data[].total").description("팀 전체 인원수") ) ) @@ -198,7 +206,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { .missionTitle("mission title") .doneNum("0") .totalNum("0") - .status("WAIT/ONGOING/END/FAIL/SUCCESS") + .status("WAIT/ONGOING/SKIP/COMPLETE") + .donePeople("0") + .totalPeople("0") .build()); given(missionGatherBoardUseCase.getTeamActiveRepeatMissions(any(),any())).willReturn(output); @@ -230,7 +240,9 @@ public class MissionGatherControllerTest extends CommonControllerTest { fieldWithPath("data[].missionTitle").description("미션 제목"), fieldWithPath("data[].doneNum").description("완료한 횟수"), fieldWithPath("data[].totalNum").description("전체 횟수"), - fieldWithPath("data[].status").description("미션 상태") + fieldWithPath("data[].status").description("미션 상태"), + fieldWithPath("data[].donePeople").description("미션 완료한 인원수"), + fieldWithPath("data[].totalPeople").description("팀 전체 인원수") ) diff --git a/src/test/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryServiceTest.java b/src/test/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryServiceTest.java index 3e8be90c..e69de29b 100644 --- a/src/test/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryServiceTest.java +++ b/src/test/java/com/moing/backend/domain/missionState/domain/service/MissionStateQueryServiceTest.java @@ -1,35 +0,0 @@ -//package com.moing.backend.domain.missionState.domain.service; -// -//import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; -//import com.moing.backend.domain.missionState.domain.repository.MissionStateCustomRepository; -//import com.moing.backend.domain.missionState.domain.repository.MissionStateCustomRepositoryImpl; -//import com.moing.backend.domain.missionState.domain.repository.MissionStateRepository; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -// -//import javax.persistence.EntityManager; -// -//import static org.junit.jupiter.api.Assertions.*; -// -//@SpringBootTest -//class MissionStateQueryServiceTest { -// -// -// @MockBean -// MissionStateQueryService missionStateQueryService ; -// @MockBean -// MissionStateCustomRepositoryImpl missionStateCustomRepository ; -// -// -// @Test -// public void missionDonePeople() { -// System.out.println(missionStateQueryService.stateCountByMissionId(4L)); -// } -// -// -// -// -// -//} \ No newline at end of file