Skip to content

Commit

Permalink
Merge pull request #84 from UMC-CommonPlant/feat/#45_Memo
Browse files Browse the repository at this point in the history
Feat/#45 memo
  • Loading branch information
Bjimin authored Jan 29, 2024
2 parents 9adc785 + 973c3b3 commit 571214f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<JsonResponse> 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<JsonResponse> createMemo(@RequestPart("memoRequest")MemoDto.MemoRequest memoRequest, @RequestPart(value = "image", required = false) MultipartFile multipartFile){
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -34,8 +35,8 @@ public ResponseEntity<JsonResponse> createMemo(@RequestPart("memoRequest")MemoDt
return ResponseEntity.ok(new JsonResponse(true, 200, "createMemo", null));
}

@PatchMapping("/update")
public ResponseEntity<JsonResponse> 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<JsonResponse> updateMemo(@RequestPart("memoRequest")MemoDto.MemoUpdateRequest memoUpdateRequest, @RequestPart(value = "image", required = false) MultipartFile multipartFile) {
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<JsonResponse> 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<JsonResponse> 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<JsonResponse> 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<JsonResponse> 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<JsonResponse> getPlantMemo(@RequestParam("plant_idx") Long plant_idx);

@Hidden
public ResponseEntity<JsonResponse> getRecentMemo(@RequestParam("plant_idx") Long plant_idx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 571214f

Please sign in to comment.