diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java index 3cff40f6..0caa23dc 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java @@ -6,7 +6,7 @@ @Getter @Setter -//@Builder +@Builder public class RepeatMissionBoardRes { private Long missionId; private String title; @@ -16,18 +16,19 @@ public class RepeatMissionBoardRes { private Long done; private int number; private String way; + private String status; - public RepeatMissionBoardRes(Long missionId, String title, Long done,int number,String way) { + public RepeatMissionBoardRes(Long missionId, String title, Long done,int number,String way,String status) { this.missionId = missionId; this.title = title; this.dueTo="False"; this.number = number; this.done = done; this.way = way; + this.status = status; } - @Builder public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long done, int number,String way) { this.missionId = missionId; this.title = title; @@ -36,4 +37,15 @@ public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long do this.number = number; this.way = way; } + + @Builder + public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long done, int number, String way, String status) { + this.missionId = missionId; + this.title = title; + this.dueTo = dueTo; + this.done = done; + this.number = number; + this.way = way; + this.status = status; + } } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java new file mode 100644 index 00000000..114a2e95 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java @@ -0,0 +1,94 @@ +//package com.moing.backend.domain.mission.application.service; +// +//import com.moing.backend.domain.mission.domain.entity.Mission; +//import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; +//import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.batch.core.Job; +//import org.springframework.batch.core.Step; +//import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +//import org.springframework.batch.core.configuration.annotation.JobScope; +//import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +//import org.springframework.batch.core.configuration.annotation.StepScope; +//import org.springframework.batch.item.ItemProcessor; +//import org.springframework.batch.item.database.JpaItemWriter; +//import org.springframework.batch.item.database.JpaPagingItemReader; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//import javax.persistence.EntityManagerFactory; +// +//@Slf4j +//@RequiredArgsConstructor +//@Configuration +//public class RepeatMissionEnd { +// +// public static final String JOB_NAME = "makeMissionEnd"; +// +// private final EntityManagerFactory entityManagerFactory; +// private final StepBuilderFactory stepBuilderFactory; +// private final JobBuilderFactory jobBuilderFactory; +// +// private final MissionStateUseCase missionStateUseCase; +// private final TeamScoreLogicUseCase teamScoreLogicUseCase; +// +// private final int chunkSize = 10; +// +// @Bean +// public Job payPagingJob() { +// return jobBuilderFactory.get(JOB_NAME) +// .start(payPagingStep()) +// .build(); +// } +// +// @Bean +// @JobScope +// public Step payPagingStep() { +// return stepBuilderFactory.get("makeMissionEndStep") +// .chunk(chunkSize) +// .reader(payPagingReader()) +// .processor(payPagingProcessor()) +// .writer(writer()) +// .build(); +// } +// +// @Bean +// @StepScope +// public JpaPagingItemReader payPagingReader() { +// +// JpaPagingItemReader reader = new JpaPagingItemReader() { +// @Override +// public int getPage() { +// return 0; +// } +// }; +// +// reader.setQueryString("SELECT m FROM Mission m WHERE m.status = 'ONGOING' AND m.type = 'REPEAT'"); +// reader.setPageSize(chunkSize); +// reader.setEntityManagerFactory(entityManagerFactory); +// reader.setName("payPagingReader"); +// +// return reader; +// } +// +// // sundayRepeatMissionRoutine() +// @Bean +// @StepScope +// public ItemProcessor payPagingProcessor() { +// return mission -> { +// teamScoreLogicUseCase.updateTeamScore(mission.getId()); +// missionStateUseCase.deleteAllMissionState(mission.getId()); +// mission.makeEnd(); +// return mission; +// }; +// } +// +// @Bean +// @StepScope +// public JpaItemWriter writer() { +// JpaItemWriter writer = new JpaItemWriter<>(); +// writer.setEntityManagerFactory(entityManagerFactory); +// return writer; +// } +//} \ No newline at end of file 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 66177310..df199e4a 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 @@ -84,4 +84,8 @@ public void setTeam(Team team) { public void updateStatus(MissionStatus missionStatus) { this.status = missionStatus; } + + public void makeEnd() { + this.status = MissionStatus.END; + } } 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 1ac31cec..d4df05e9 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 @@ -58,10 +58,8 @@ public Long deleteArchive(String userSocialId, Long missionId) { Mission mission = missionQueryService.findMissionById(missionId); Team team = mission.getTeam(); - // 사진 제출 했다면, + // 사진 제출 했다면, s3 삭제 로직 if (mission.getWay() == MissionWay.PHOTO && missionArchiveQueryService.isDone(memberId, missionId)) { - //s3삭제 - } @@ -70,6 +68,7 @@ public Long deleteArchive(String userSocialId, Long missionId) { MissionState missionState = missionStateQueryService.findMissionState(member, mission); missionStateDeleteService.deleteMissionState(missionState); + return deleteArchive.getId(); } 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 efa04b7f..f9781c43 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 @@ -43,13 +43,12 @@ public MissionArchiveCustomRepositoryImpl(EntityManager em) { public Optional> findSingleMissionInComplete(Long memberId, Long teamId, MissionStatus status, OrderCondition orderCondition) { OrderSpecifier[] orderSpecifiers = createOrderSpecifier(orderCondition); - String missionArchiveStatus = "INCOMPLETE"; return Optional.ofNullable(queryFactory .select(Projections.constructor(SingleMissionBoardRes.class, mission.id, mission.dueTo.stringValue(), mission.title, - Expressions.constant(missionArchiveStatus), + mission.status.stringValue(), mission.type.stringValue() )) .from(mission) @@ -64,10 +63,12 @@ public Optional> findSingleMissionInComplete(Long me .or(missionState.mission.status.eq(MissionStatus.ONGOING)) )), mission.type.eq(MissionType.ONCE), + mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)), mission.team.teamId.eq(teamId)) .orderBy(orderSpecifiers).fetch()); + } @Override public Optional> findSingleMissionComplete(Long memberId, Long teamId, MissionStatus status, @@ -176,7 +177,8 @@ public Optional> findRepeatMissionArchivesByMemberId mission.title, missionArchive.count.max().coalesce(0L).as("done"), mission.number, - mission.way.stringValue() + mission.way.stringValue(), + mission.status.stringValue() )) .from(mission) .leftJoin(mission.missionArchiveList,missionArchive) @@ -184,7 +186,7 @@ public Optional> findRepeatMissionArchivesByMemberId .where( mission.team.teamId.eq(teamId), mission.type.eq(MissionType.REPEAT), - mission.status.eq(MissionStatus.ONGOING) + mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)) ) .groupBy(mission) .fetch()); 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 index 41849b62..f3405ce6 100644 --- 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 @@ -6,6 +6,8 @@ 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.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; @@ -14,6 +16,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + @Slf4j @Service @Transactional @@ -26,6 +31,7 @@ public class MissionStateUseCase { private final MissionQueryService missionQueryService; private final MissionStateQueryService missionStateQueryService; private final MissionStateSaveService missionStateSaveService; + private final MissionStateDeleteService missionStateDeleteService; private final TeamScoreLogicUseCase teamScoreLogicUseCase; @@ -80,7 +86,18 @@ public void updateMissionState(Member member, Mission mission, MissionArchive mi public void deleteMissionState(Member member, Mission mission, MissionArchive missionArchive) { + MissionState missionState = missionStateQueryService.findMissionState(member, mission); + missionStateDeleteService.deleteMissionState(missionState); + + } + + public void missionStateReset(List missionIds) { + List missionStates = missionStateQueryService.findByMissionId(missionIds); + missionStateDeleteService.deleteMissionState(missionStates); + } + public void deleteAllMissionState(Long missionId) { + missionStateDeleteService.deleteMissionStateByMission(missionId); } 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 index 6a9e996d..01166d64 100644 --- 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 @@ -14,6 +14,7 @@ public interface MissionStateCustomRepository { int getCountsByMissionId(Long missionId) ; List findByMissionId(List missionId); + List findByMissionId(Long missionId); Optional> findFinishMission(); 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 index d6ef72e7..a8aebddd 100644 --- 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 @@ -45,6 +45,17 @@ public List findByMissionId(List missionId) { 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 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 index eb679fb6..b99aa8b0 100644 --- 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 @@ -23,4 +23,10 @@ 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/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java index 91fae242..5065dcac 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java @@ -42,7 +42,7 @@ public class MissionBoardControllerTest extends CommonControllerTest { .missionId(1L) .dueTo("2023-09-03T21:32:33.888") .title("Mission title") - .status("SKIP/COMPLETE") + .status("WAIT/ONGOING/SKIP/COMPLETE") .missionType("ONCE/REPEAT") .build()); @@ -94,7 +94,8 @@ public class MissionBoardControllerTest extends CommonControllerTest { .dueTo("True/False") .done(1L) .number(3) - .way("TEXT/PHOTO/LINK") + .way("TEXT/PHOTO/LINK") + .status("WAIT/ONGOING/SKIP/COMPLETE") .build()); given(missionArchiveBoardUseCase.getActiveRepeatMissions(any(),any())).willReturn(output); @@ -127,7 +128,8 @@ public class MissionBoardControllerTest extends CommonControllerTest { fieldWithPath("data[].dueTo").description("내일 리셋 상태 리턴, 일요일이면 true[True/False]"), fieldWithPath("data[].number").description("전체 횟수"), fieldWithPath("data[].done").description("인증한 횟수"), - fieldWithPath("data[].way").description("인증 방법") + fieldWithPath("data[].way").description("인증 방법"), + fieldWithPath("data[].status").description("인증 상태") ) )