Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

public interface ApproveMissionUseCase {

// 미션 수신자는 미션 승인 또는 거절을 결정한다.
MissionResult decide(ApproveMissionCommand command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public MissionResult request(CreateMissionCommand command) {
Reward reward = Reward.of(title, command.message());

// Mission 생성시 필요한 값: FamilyRelationId, CategoryId, Period, Reward(nullable)
Mission mission = Mission.create(requesterId, recipientId, relationId, categoryId, period, reward);
Mission mission = Mission.of(requesterId, recipientId, relationId, categoryId, period, reward);

// 3. 저장
missionPort.save(mission);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.oneco.backend.mission.application.service;

import java.time.LocalDate;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -31,9 +33,20 @@ public MissionResult decide(ApproveMissionCommand command) {
MemberId recipientId = MemberId.of(command.recipientId());
validateRecipient(mission, recipientId);
validateStatus(mission);
validateNotExpired(mission);

if (command.accepted()) {
// 미션 승인 상태일 경우
mission.acceptApproval();

// 미션 시작일이 오늘(요청 수락일)과 같거나 이전이라면 즉시 미션 진행 상태로 변경
LocalDate startDate = mission.getPeriod().getStartDate();
LocalDate today = LocalDate.now();

if (startDate.isBefore(today) || startDate.isEqual(today)) {
mission.markInProgress(); // 미션을 즉시 진행 상태로 변경
}

} else {
mission.rejectApproval();
}
Expand All @@ -44,7 +57,8 @@ public MissionResult decide(ApproveMissionCommand command) {

private void validateRecipient(Mission mission, MemberId recipientId) {
if (!mission.getRecipientId().equals(recipientId)) {
throw BaseException.from(MissionErrorCode.MISSION_APPROVAL_FORBIDDEN);
throw BaseException.from(MissionErrorCode.MISSION_APPROVAL_FORBIDDEN,
"미션 수신자가 아닌 사용자는 승인/거절할 수 없습니다.");
}
}

Expand All @@ -54,4 +68,12 @@ private void validateStatus(Mission mission) {
"승인/거절은 APPROVAL_REQUEST 상태에서만 가능합니다.");
}
}

private void validateNotExpired(Mission mission) {
LocalDate today = LocalDate.now();
if (today.isAfter(mission.getPeriod().getEndDate())) {
throw BaseException.from(MissionErrorCode.LATE_MISSION_APPROVAL,
"미션 종료일이 지난 후에는 승인할 수 없습니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void startScheduledMissions() {
long successCount = 0; // 성공 처리 건수
long errorCount = 0; // 실패 처리 중 오류 발생 건수

// 1. 오늘이 시작일인 미션들을 조회한다.
// 1. 오늘이 시작일이면서 미션 상태가 APPROVAL_ACCEPTED인 미션들을 조회한다.
List<Mission> missionsToStart = missionPort.findAllMissionsStartingToday(today);

// =============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public enum MissionErrorCode implements ErrorCode {
HttpStatus.BAD_REQUEST,
"미션 ID가 유효하지 않습니다.",
"MISSION_ERROR_400_INVALID_MISSION_ID"
),
LATE_MISSION_APPROVAL(
HttpStatus.BAD_REQUEST,
"미션 종료일이 지난 후에는 승인할 수 없습니다.",
"MISSION_ERROR_400_LATE_MISSION_APPROVAL"
);

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Mission(
}

// 미션 생성 메서드
public static Mission create(
public static Mission of(
MemberId requesterId,
MemberId recipientId,
FamilyRelationId familyRelationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public ResponseEntity<DataResponse<MissionResult>> createMission(
description = """
- 미션 승인 또는 거절 요청을 처리한다.
- 미션 수신자는 미션을 승인하거나 거절할 수 있다.
- 승인 시 미션 상태는 '진행중'으로 변경된다.
- 승인 시 미션 상태는 '승인 수락'으로 변경된다.
- 거절 시 미션 상태는 '거절됨'으로 변경된다.
- 미션 승인 시점이 미션 시작일이과 같을 경우 미션 상태는 즉시 '진행중'으로 변경된다.
- 미션 승인 시점이 미션 시작일보다 이후 일 경우 미션 상태는 즉시 '진행중'으로 변경된다.
"""
)
@ApiResponses({
Expand Down