Skip to content

Commit

Permalink
Merge pull request #76 from Modagbul/feat/mission-closing
Browse files Browse the repository at this point in the history
Feat/mission closing
  • Loading branch information
seungueonn authored Nov 16, 2023
2 parents 1e31d17 + f126420 commit 88e3a4a
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Getter
@Setter
//@Builder
@Builder
public class RepeatMissionBoardRes {
private Long missionId;
private String title;
Expand All @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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")
// .<Mission, Mission>chunk(chunkSize)
// .reader(payPagingReader())
// .processor(payPagingProcessor())
// .writer(writer())
// .build();
// }
//
// @Bean
// @StepScope
// public JpaPagingItemReader<Mission> payPagingReader() {
//
// JpaPagingItemReader<Mission> reader = new JpaPagingItemReader<Mission>() {
// @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<Mission, Mission> payPagingProcessor() {
// return mission -> {
// teamScoreLogicUseCase.updateTeamScore(mission.getId());
// missionStateUseCase.deleteAllMissionState(mission.getId());
// mission.makeEnd();
// return mission;
// };
// }
//
// @Bean
// @StepScope
// public JpaItemWriter<Mission> writer() {
// JpaItemWriter<Mission> writer = new JpaItemWriter<>();
// writer.setEntityManagerFactory(entityManagerFactory);
// return writer;
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ public void setTeam(Team team) {
public void updateStatus(MissionStatus missionStatus) {
this.status = missionStatus;
}

public void makeEnd() {
this.status = MissionStatus.END;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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삭제


}

Expand All @@ -70,6 +68,7 @@ public Long deleteArchive(String userSocialId, Long missionId) {

MissionState missionState = missionStateQueryService.findMissionState(member, mission);
missionStateDeleteService.deleteMissionState(missionState);

return deleteArchive.getId();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public MissionArchiveCustomRepositoryImpl(EntityManager em) {
public Optional<List<SingleMissionBoardRes>> 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)
Expand All @@ -64,10 +63,12 @@ public Optional<List<SingleMissionBoardRes>> 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<List<SingleMissionBoardRes>> findSingleMissionComplete(Long memberId, Long teamId, MissionStatus status,
Expand Down Expand Up @@ -176,15 +177,16 @@ public Optional<List<RepeatMissionBoardRes>> 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)
.on( missionArchive.member.memberId.eq(memberId))
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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<Long> missionIds) {
List<MissionState> missionStates = missionStateQueryService.findByMissionId(missionIds);
missionStateDeleteService.deleteMissionState(missionStates);
}

public void deleteAllMissionState(Long missionId) {
missionStateDeleteService.deleteMissionStateByMission(missionId);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface MissionStateCustomRepository {
int getCountsByMissionId(Long missionId) ;

List<MissionState> findByMissionId(List<Long> missionId);
List<MissionState> findByMissionId(Long missionId);

Optional<List<MissionState>> findFinishMission();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public List<MissionState> findByMissionId(List<Long> missionId) {
missionState.mission.id.in(missionId)
).fetch();

}
@Override
public List<MissionState> findByMissionId(Long missionId) {

return queryFactory
.select(missionState)
.from(missionState)
.where(
missionState.mission.id.in(missionId)
).fetch();

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ public void deleteMissionState(MissionState missionStates) {

missionStateRepository.delete(missionStates);
}

public void deleteMissionStateByMission(Long missionId) {

List<MissionState> missionStates = missionStateRepository.findByMissionId(missionId);
missionStateRepository.deleteAll(missionStates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("인증 상태")

)
)
Expand Down

0 comments on commit 88e3a4a

Please sign in to comment.