Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#45 memo #84

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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