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(); } - // 파일 전송 (