Skip to content

Commit

Permalink
Merge pull request #50 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 2, 2023
2 parents cc81752 + cbe7473 commit 9dc3a07
Show file tree
Hide file tree
Showing 52 changed files with 921 additions and 194 deletions.
6 changes: 0 additions & 6 deletions src/docs/asciidoc/MissionBoard-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ operation::mission-board-controller-test/반복_미션_인증_조회[snipipets='

---

[[MissionBoard-나의미션인증조회]]
== 나의 미션 인증 조회
operation::mission-archive-controller-test/나의_미션_인증_조회[snippets='http-request,path-parameters,http-response,response-fields']

---

[[MissionBoard-종료된인증조회]]
== 종료된 인증 조회
operation::mission-board-controller-test/종료된_인증_조회[snippets='http-request,path-parameters,http-response,response-fields']
Expand Down
10 changes: 10 additions & 0 deletions src/docs/asciidoc/TeamScore-API.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


[[TeamScore-API]]
= TeamScore API

[[TeamScore-팀별-불-레벨-경험치-조회]]
=== 팀별_불_레벨_경험치_조회
operation::team-score-controller-test/팀별_불_레벨_경험치_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

---
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.moing.backend.domain.fire.domain.repository;

import com.moing.backend.domain.fire.domain.entity.Fire;
import com.moing.backend.domain.fire.domain.entity.QFire;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive;
import com.querydsl.jpa.JPAExpressions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.moing.backend.domain.mission.application.dto.req;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;


@AllArgsConstructor
@Builder
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.moing.backend.domain.mission.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.units.qual.A;

@Getter
@Setter
@Builder
@AllArgsConstructor
public class SingleMissionBoardRes {
private Long missionId;
private String dueTo; // 날짜
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.moing.backend.domain.mission.application.service;

public class MissionCheckScheduler {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.moing.backend.domain.mission.application.service;

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.service.MissionQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class MissionTerminationUseCase {

private final MemberGetService memberGetService;
private final MissionQueryService missionQueryService;

// 스케쥴러에서 호출
public void terminateMission() {

List<Mission> missionByDueTo = missionQueryService.findMissionByDueTo();

missionByDueTo.stream().forEach(
// 미션 종료 처리
mission -> mission.updateStatus(MissionStatus.END)

);
}

// 미션 점수 반영 -> MissionState


// MissionState 조회 해서 미션 점수 현황조회

public void getMissionScoreStatus() {

}

// 팀별 점수 반영
public void updateMissionScore() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void setTeam(Team team) {
this.team = team;
}

public void setStatus(MissionStatus missionStatus) {
public void updateStatus(MissionStatus missionStatus) {
this.status = missionStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface MissionCustomRepository {
Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long memberId, List<Long>teams);


Optional<List<Mission>> findMissionByDueTo();


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.persistence.EntityManager;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -59,6 +60,18 @@ public Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long m
.fetch());
}


@Override
public Optional<List<Mission>> findMissionByDueTo() {

LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1);

return Optional.ofNullable(queryFactory
.selectFrom(mission)
.where(
mission.dueTo.after(oneHourAgo)
).fetch());
}
@Override
public Optional<List<GatherSingleMissionRes>> findSingleMissionByMemberId(Long memberId, List<Long> teams) {
return Optional.ofNullable(queryFactory
Expand All @@ -75,8 +88,7 @@ public Optional<List<GatherSingleMissionRes>> findSingleMissionByMemberId(Long m
mission.type.eq(MissionType.ONCE)

)
.fetch()

);
.fetch());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes;
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.exception.NotFoundEndMissionException;
import com.moing.backend.domain.mission.exception.NotFoundMissionException;
import com.moing.backend.domain.mission.domain.repository.MissionRepository;
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
Expand Down Expand Up @@ -41,4 +42,12 @@ public List<GatherSingleMissionRes> findAllSingleMission(Long memberId) {
List<Long> teams = teamGetService.getTeamIdByMemberId(memberId);
return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new);
}

/**
* 스케쥴러에서 한시간 단위로 실행
* 현재 시간으로부터 1시간 이내 종료 되는 미션 리턴
*/
public List<Mission> findMissionByDueTo() {
return missionRepository.findMissionByDueTo().orElseThrow(NotFoundEndMissionException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moing.backend.domain.mission.exception;

import com.moing.backend.global.response.ErrorCode;
import org.springframework.http.HttpStatus;

public class NotFoundEndMissionException extends MissionException {

public NotFoundEndMissionException() {
super(ErrorCode.NOT_FOUND_MISSION,
HttpStatus.NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import lombok.*;

@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class MissionArchiveReq {

private String status;
private String archive; //사진일 경우 파일명, 이외에는 text,link

@Builder
public MissionArchiveReq(String status, String archive) {
this.status = status;
this.archive = archive;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moing.backend.domain.mission.application.service;
package com.moing.backend.domain.missionArchive.application.service;

import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
Expand Down Expand Up @@ -45,8 +45,7 @@ public List<SingleMissionBoardRes> getActiveSingleMissions(Long teamId, String m

Member member = memberGetService.getMemberBySocialId(memberId);

List<MissionArchive> mySingleMissionArchives = missionArchiveQueryService.findMySingleMissionArchives(member.getMemberId(), teamId, MissionStatus.ONGOING);
return MissionArchiveMapper.mapToSingleMissionBoardResList(mySingleMissionArchives);
return missionArchiveQueryService.findMySingleMissionArchives(member.getMemberId(), teamId, MissionStatus.ONGOING);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
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;
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.TeamScoreLogicUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,37 +32,38 @@ public class MissionArchiveCreateUseCase {
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 MissionArchiveScoreService missionArchiveScoreService;
private final MissionStateSaveService missionStateSaveService;
private final MissionStateUseCase missionStateUseCase;

private final TeamScoreLogicUseCase teamScoreLogicUseCase;

// 미션 인증
public MissionArchiveRes createArchive(String userSocialId, Long missionId, MissionArchiveReq missionReq) {

Member member = memberGetService.getMemberBySocialId(userSocialId);
Long memberId = member.getMemberId();

Mission mission = missionQueryService.findMissionById(missionId);
Team team = mission.getTeam();

MissionArchive newArchive = MissionArchiveMapper.mapToMissionArchive(missionReq, member, mission);

// 인증 완료한 미션인지 확인
if (isDoneMission(memberId,mission)) {
throw new NoMoreMissionArchiveException();
}

// archive 회차
if (mission.getType().equals(MissionType.ONCE)) {
newArchive.updateCount(1L);
}
else {
// 반복 미션일 경우
if (mission.getType() == MissionType.REPEAT) {
newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId)+1);
}else {
newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId));
}

missionStateUseCase.updateMissionState(member, mission, newArchive);
return MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive),memberId);

}
Expand All @@ -68,18 +73,7 @@ public Boolean isDoneMission(Long memberId,Mission mission) {
return missionArchiveQueryService.findMyDoneArchives(memberId, mission.getId()) >= mission.getNumber();
}

// 이 미션을 완료 했는지
public Boolean isEndMission(Member member,Mission mission) {
Team team = mission.getTeam();

Long missionsCountByTeam = missionQueryService.findMissionsCountByTeam(team.getTeamId());

if (missionsCountByTeam == team.getNumOfMember()-1) {
mission.setStatus(MissionStatus.END);
return true;
}
return false;
}



Expand Down

This file was deleted.

Loading

0 comments on commit 9dc3a07

Please sign in to comment.