AttachmentController.java

역할


1. 첨부파일 업로드 (/tasks/{taskId}/attachments)

@PostMapping(value = "/tasks/{taskId}/attachments", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> upload(@PathVariable("taskId") Long taskId,
                                @RequestParam("files") List<MultipartFile> files,
                                Authentication auth) {

    // 현재 로그인한 사용자의 ID 추출
    Long uploaderId = Long.valueOf(auth.getName());

    // AttachmentService에서 실제 파일 저장 처리 후 결과 반환
    return ResponseEntity.ok(attachmentService.uploadToTask(taskId, uploaderId, files));
}

설명:


2. 첨부파일 삭제 (Soft Delete) (/attachments/{attachmentId})

@DeleteMapping("/attachments/{attachmentId}")
public ResponseEntity<?> delete(@PathVariable("attachmentId") Long attachmentId,
                                Authentication auth) {

    Long requesterId = Long.valueOf(auth.getName());

    // 실제 삭제 로직은 softDelete 메서드에서 처리 (DB flag 변경)
    attachmentService.softDelete(attachmentId, requesterId);

    return ResponseEntity.ok().build();
}

설명: