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
@@ -1,5 +1,6 @@
package clap.server.adapter.inbound.web.task;

import clap.server.adapter.inbound.security.service.SecurityUserDetails;
import clap.server.application.port.inbound.task.CancelTaskUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -18,9 +19,9 @@ public class CancelTaskController {
private final CancelTaskUsecase cancelTaskUsecase;

@Operation(summary = "작업 취소")
@Secured("ROLE_USER")
@Secured({"ROLE_USER","ROLE_MANAGER"})
@PatchMapping("/{taskId}/cancel")
public void cancelTask(@PathVariable Long taskId) {
cancelTaskUsecase.cancleTask(taskId);
public void cancelTask(@PathVariable Long taskId, SecurityUserDetails userDetails) {
cancelTaskUsecase.cancleTask(taskId, userDetails.getUserId());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package clap.server.application.port.inbound.task;

public interface CancelTaskUsecase {
void cancleTask(Long taskId);
void cancleTask(Long taskId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.task.Task;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;


@ApplicationService
@RequiredArgsConstructor
@Transactional
public class CancelTaskService implements CancelTaskUsecase {
private final TaskService taskService;

@Override
public void cancleTask(Long taskId) {
public void cancleTask(Long taskId, Long memberId) {
Task task = taskService.findById(taskId);
task.cancelTask();
task.cancelTask(memberId);
taskService.upsert(task);
}
}
9 changes: 7 additions & 2 deletions src/main/java/clap/server/domain/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import clap.server.domain.model.common.BaseTime;
import clap.server.domain.model.member.Member;
import clap.server.exception.ApplicationException;
import clap.server.exception.DomainException;
import clap.server.exception.code.TaskErrorCode;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -15,6 +16,7 @@
import java.util.Objects;

import static clap.server.domain.policy.task.TaskPolicyConstants.DEFAULT_PROCESSOR_ORDER_GAP;
import static clap.server.exception.code.TaskErrorCode.NOT_A_REQUESTER;

@Getter
@SuperBuilder
Expand Down Expand Up @@ -48,7 +50,7 @@ public static Task createTask(Member member, Category category, String title, St

public void updateTask(Long requesterId, Category category, String title, String description) {
if (!Objects.equals(requesterId, this.requester.getMemberId())) {
throw new ApplicationException(TaskErrorCode.NOT_A_REQUESTER);
throw new ApplicationException(NOT_A_REQUESTER);
}
this.category = category;
this.title = title;
Expand Down Expand Up @@ -103,7 +105,10 @@ public void updateProcessorOrder(long newProcessorOrder) {
this.processorOrder = newProcessorOrder;
}

public void cancelTask() {
public void cancelTask(Long requesterId) {
if (!Objects.equals(this.requester.getMemberId(), requesterId)) {
throw new DomainException(NOT_A_REQUESTER);
}
this.taskStatus = TaskStatus.TERMINATED;
this.finishedAt = LocalDateTime.now();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/clap/server/exception/code/TaskErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public enum TaskErrorCode implements BaseErrorCode {
INVALID_TASK_ORDER(HttpStatus.INTERNAL_SERVER_ERROR, "TASK_007", "유효하지 않은 task order입니다."),
INVALID_TASK_STATUS_TRANSITION(HttpStatus.BAD_REQUEST, "TASK_008", "유효하지 않은 작업 상태 전환입니다."),
NOT_A_REVIEWER(HttpStatus.FORBIDDEN, "TASK_009", "작업 승인 및 수정 권한이 없습니다."),
NOT_A_REQUESTER(HttpStatus.FORBIDDEN, "TASK_009", "작업 수정 권한이 없습니다."),
TASK_STATUS_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "TASK_010", "변경할 수 없는 작업 상태입니다. 다른 API를 사용해주세요")
NOT_A_REQUESTER(HttpStatus.FORBIDDEN, "TASK_010", "작업 수정 및 취소 권한이 없습니다."),
TASK_STATUS_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "TASK_011", "변경할 수 없는 작업 상태입니다. 다른 API를 사용해주세요")
;

private final HttpStatus httpStatus;
Expand Down