diff --git a/src/main/java/com/umc/commonplant/domain/memo/controller/MemoController.java b/src/main/java/com/umc/commonplant/domain/memo/controller/MemoController.java index ce19155..604101b 100644 --- a/src/main/java/com/umc/commonplant/domain/memo/controller/MemoController.java +++ b/src/main/java/com/umc/commonplant/domain/memo/controller/MemoController.java @@ -8,6 +8,7 @@ import com.umc.commonplant.global.dto.JsonResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -18,14 +19,14 @@ @RequestMapping("/memo") @RequiredArgsConstructor @RestController -public class MemoController { +public class MemoController implements MemoSwagger{ private final MemoService memoService; private final JwtService jwtService; private final UserService userService; - @PostMapping("/add") - public ResponseEntity createMemo(@RequestPart("memoRequest")MemoDto.MemoRequest memoRequest, @RequestPart("image") MultipartFile multipartFile){ + @PostMapping(value = "/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity createMemo(@RequestPart("memoRequest")MemoDto.MemoRequest memoRequest, @RequestPart(value = "image", required = false) MultipartFile multipartFile){ String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -34,8 +35,8 @@ public ResponseEntity createMemo(@RequestPart("memoRequest")MemoDt return ResponseEntity.ok(new JsonResponse(true, 200, "createMemo", null)); } - @PatchMapping("/update") - public ResponseEntity updateMemo(@RequestPart("memoRequest")MemoDto.MemoUpdateRequest memoUpdateRequest, @RequestPart("image") MultipartFile multipartFile) { + @PatchMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity updateMemo(@RequestPart("memoRequest")MemoDto.MemoUpdateRequest memoUpdateRequest, @RequestPart(value = "image", required = false) MultipartFile multipartFile) { String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); diff --git a/src/main/java/com/umc/commonplant/domain/memo/controller/MemoSwagger.java b/src/main/java/com/umc/commonplant/domain/memo/controller/MemoSwagger.java new file mode 100644 index 0000000..c9ff57d --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/memo/controller/MemoSwagger.java @@ -0,0 +1,59 @@ +package com.umc.commonplant.domain.memo.controller; + +import com.umc.commonplant.domain.memo.dto.MemoDto; +import com.umc.commonplant.domain.user.entity.User; +import com.umc.commonplant.domain2.info.dto.InfoDto; +import com.umc.commonplant.global.dto.JsonResponse; +import io.swagger.v3.oas.annotations.Hidden; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +@Tag(name = "Memo Controller", description = "메모 관련 API") +public interface MemoSwagger { + @Operation(summary = "메모 작성", description = "메모 작성을 위해 내용을 입력한 뒤 호출하는 API") + public ResponseEntity createMemo( + @Parameter( + name = "memoRequest", + description = "memoRequest 객체", + required = true + ) @RequestPart("memoRequest") MemoDto.MemoRequest memoRequest, + @Parameter( + name = "image", + description = "메모의 이미지" + ) @RequestPart(value = "image", required = false) MultipartFile multipartFile + ); + + @Operation(summary = "메모 수정", description = "기존의 메모 내용을 수정하는 API로, 이미지 수정의 경우 이미지 파일을 전달하면 업데이트, multipart 파일이 null이고 imgUrl 전달받으면(이때 전꺼랑 같으면) 유지, 아니라면 삭제") + public ResponseEntity updateMemo( + @Parameter( + name = "memoRequest", + description = "memoRequest 객체", + required = true + ) @RequestPart("memoRequest")MemoDto.MemoUpdateRequest memoUpdateRequest, + @Parameter( + name = "image", + description = "메모의 이미지" + ) @RequestPart(value = "image", required = false) MultipartFile multipartFile + ); + + @Operation(summary = "메모 삭제", description = "하나의 특정 메모를 삭제하는 API로, 작성자만 삭제 가능") + @Parameter(name = "memo_idx", description = "메모의 memo index", example = "4", required = true) + public ResponseEntity deleteMemo(@RequestParam("memo_idx") Long memo_idx); + + @Operation(summary = "하나의 메모 조회", description = "memo_idx에 해당하는 하나의 메모 조회") + @Parameter(name = "memo_idx", description = "메모의 memo index", example = "4", required = true) + public ResponseEntity getOneMemo(@RequestParam("memo_idx") Long memo_idx); + + @Operation(summary = "메모 리스트 조회", description = "plant_idx에 해당하는 모든 메모를 최신 날짜 순서로 조회") + @Parameter(name = "plant_idx", description = "식물의 plant index", example = "1", required = true) + public ResponseEntity getPlantMemo(@RequestParam("plant_idx") Long plant_idx); + + @Hidden + public ResponseEntity getRecentMemo(@RequestParam("plant_idx") Long plant_idx); +} diff --git a/src/main/java/com/umc/commonplant/domain/memo/dto/MemoDto.java b/src/main/java/com/umc/commonplant/domain/memo/dto/MemoDto.java index 3373373..fafbb14 100644 --- a/src/main/java/com/umc/commonplant/domain/memo/dto/MemoDto.java +++ b/src/main/java/com/umc/commonplant/domain/memo/dto/MemoDto.java @@ -3,6 +3,7 @@ import com.umc.commonplant.domain.memo.entity.Memo; import com.umc.commonplant.domain.plant.entity.Plant; import com.umc.commonplant.domain2.info.entity.Info; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,7 +15,10 @@ public class MemoDto { @NoArgsConstructor @Data public static class MemoRequest { + + @Schema(description = "메모를 작성할 식물 index", example = "1") private Long plant_idx; + @Schema(description = "메모 내용", example = "test") private String content; @Builder @@ -28,9 +32,14 @@ public MemoRequest(Long plant_idx, String content) { @NoArgsConstructor @Data public static class MemoUpdateRequest { + + @Schema(description = "수정할 메모의 index", example = "1") private Long memo_idx; + @Schema(description = "수정할 메모가 포함된 식물 index", example = "1") private Long plant_idx; + @Schema(description = "메모 내용", example = "test") private String content; + @Schema(description = "메모 이미지", example = "메모의 이미지를 수정하지 않고 유지하기 위해 전송하는 이전 메모 이미지 url") private String imgUrl; @Builder