From 4d8d1cfff6358f66f53421fb04f4d1413ceb7511 Mon Sep 17 00:00:00 2001 From: "sungjin.choi" Date: Fri, 27 Nov 2026 18:02:10 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=9E=90=EB=A3=8C=EC=8B=A4=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=B0=9B=EA=B8=B0=C2=B7=EA=B8=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GET /api/media-posts/files/..?dl=1 : attachment로 응답 (원래 파일명 유지, 이어받기 지원) - 상세 응답 파일에 size(바이트) 추가 - PUT /api/media-posts/{id} : 제목·분류 수정 (본인 글만, 제목 필수, 분류 비우면 미분류) Co-Authored-By: Claude Opus 5.5 --- .../controller/MediaPostController.java | 49 ++++++++++++++++--- .../specialsource/entity/MediaPost.java | 1 + .../controller/MediaPostControllerTest.java | 37 ++++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/main/java/company/specialsource/controller/MediaPostController.java b/src/main/java/company/specialsource/controller/MediaPostController.java index 039ca2c..b06a4e4 100644 --- a/src/main/java/company/specialsource/controller/MediaPostController.java +++ b/src/main/java/company/specialsource/controller/MediaPostController.java @@ -72,10 +72,12 @@ public class MediaPostController { public record CreateRequest(String url, String title, String category) {} + public record UpdateRequest(String title, String category) {} + // result: VIDEO / IMAGE / FAIL = 끝남, PROGRESS = 받는 중 (progress %, speed) public record CallbackRequest(String folder, String result, Integer progress, String speed) {} - public record FileItem(String name, String type, String url) {} + public record FileItem(String name, String type, long size, String url) {} // size: 바이트 public record MediaPostResponse(Long id, String title, String sourceUrl, String category, MediaPost.Status status, Integer progress, String speed, String author, LocalDateTime createdAt, @@ -92,8 +94,7 @@ public class MediaPostController { } String title = request.title() == null || request.title().isBlank() ? url : request.title().trim(); if (title.length() > 500) title = title.substring(0, 500); - String category = request.category() == null || request.category().isBlank() ? null : request.category().trim(); - if (category != null && category.length() > 50) category = category.substring(0, 50); + String category = normalizeCategory(request.category()); LocalDateTime now = LocalDateTime.now(); MediaPost post = repository.save(MediaPost.builder() @@ -173,6 +174,31 @@ public class MediaPostController { .orElse(ResponseEntity.notFound().build()); } + // 수정: 제목·분류만 (링크를 바꾸려면 다시 받아야 하므로 삭제 후 새로 등록). 본인 글만, 이유는 delete와 같이 400 + @PutMapping("/{id}") + public ResponseEntity update(@PathVariable Long id, @RequestBody UpdateRequest request, Principal principal) { + MediaPost post = repository.findById(id).orElse(null); + if (post == null) return ResponseEntity.notFound().build(); + if (!post.getAuthor().equals(principal.getName())) { + return ResponseEntity.badRequest().body(Map.of("error", "본인이 등록한 글만 수정할 수 있습니다")); + } + if (request.title() == null || request.title().isBlank()) { + return ResponseEntity.badRequest().body(Map.of("error", "제목을 입력하세요")); + } + String title = request.title().trim(); + post.setTitle(title.length() > 500 ? title.substring(0, 500) : title); + post.setCategory(normalizeCategory(request.category())); + repository.save(post); + return ResponseEntity.ok(toResponse(post, true)); + } + + // 분류: 앞뒤 공백 제거, 비우면 미분류(null), 최대 50자 + private static String normalizeCategory(String category) { + if (category == null || category.isBlank()) return null; + String c = category.trim(); + return c.length() > 50 ? c.substring(0, 50) : c; + } + // 삭제: 글 + 폴더(파일) 함께. 본인 글만 // (403은 프론트가 "로그인 만료"로 처리해 로그아웃되므로 400 + 이유로 응답) // ponytail: 받는 중에 지우면 봇이 폴더를 다시 만들어 파일이 남을 수 있음. 문제 되면 DOWNLOADING 중 삭제 막기 @@ -193,9 +219,11 @@ public class MediaPostController { return ResponseEntity.noContent().build(); } - // 파일 전송 (