Skip to content

Commit

Permalink
Merge pull request #347 from IceButler/refactor/#334-fridge-service
Browse files Browse the repository at this point in the history
#334 ๋ƒ‰์žฅ๊ณ  ๊ด€๋ จ API ํด๋ฆฐ์ฝ”๋“œ ๋ฐ ๋™์ ์ฟผ๋ฆฌ ์ ์šฉ
  • Loading branch information
psyeon1120 authored Aug 13, 2024
2 parents 223e014 + 19449c9 commit 8f1d29e
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 460 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -49,7 +51,7 @@ public ResponseCustom<Long> addFridge(@Valid @RequestBody AddFridgeReq addFridge
return ResponseCustom.success(fridgeService.addFridge(addFridgeReq, userId));
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์ •๋ณด ์ˆ˜์ •", description = "๋ƒ‰์žฅ๊ณ  ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.")
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์ •๋ณด ์ˆ˜์ •", description = "์ฃผ์ธ์ด ๋ƒ‰์žฅ๊ณ  ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = ResponseCustom.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "(G0000)์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ์ž…๋‹ˆ๋‹ค.",
Expand All @@ -70,83 +72,64 @@ public ResponseCustom<Void> modifyFridge(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID"
return ResponseCustom.success();
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‚ญ์ œ", description = "๋ƒ‰์žฅ๊ณ ๋ฅผ ์‚ญ์ œํ•œ๋‹ค.")
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‚ญ์ œ", description = "์ฃผ์ธ์ด ๋ƒ‰์žฅ๊ณ ๋ฅผ ์‚ญ์ œํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = ResponseCustom.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "(G0000)์ž˜๋ชป๋œ ํŒŒ๋ผ๋ฏธํ„ฐ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "403", description = "(G0001)๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.\t\n",
@ApiResponse(responseCode = "404", description = "(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "409", description = "(R0001)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์‚ฌ์šฉ์ž๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@PatchMapping("/{fridgeId}/remove")
public ResponseCustom<Long> removeFridge(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@DeleteMapping("/{fridgeId}")
public ResponseCustom<Void> removeFridge(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.removeFridge(fridgeId, userId));
fridgeService.removeFridge(fridgeId, userId);
return ResponseCustom.success();
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‚ฌ์šฉ์ž ์‚ญ์ œ", description = "๋ƒ‰์žฅ๊ณ  ์‚ฌ์šฉ์ž๋ฅผ ์‚ญ์ œํ•œ๋‹ค.")
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ํƒˆํ‡ด", description = "๋ƒ‰์žฅ๊ณ ์—์„œ ์Šค์Šค๋กœ ํƒˆํ‡ดํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = ResponseCustom.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "403", description = "(G0001)๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0003)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.",
@ApiResponse(responseCode = "404", description = "(R0003)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@PatchMapping("/{fridgeId}/remove/each")
@PatchMapping("/{fridgeId}/withdraw")
public ResponseCustom<Long> removeFridgeUser(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.removeFridgeUser(fridgeId, userId));
fridgeService.removeFridgeUser(fridgeId, userId);
return ResponseCustom.success();
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ „์ฒด ์กฐํšŒ(์นดํ…Œ๊ณ ๋ฆฌ๋ณ„)", description = "๋ƒ‰์žฅ๊ณ  ๋‚ด ์‹ํ’ˆ์„ ์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„๋กœ ์ „์ฒด์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeMainRes.class)
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ๊ฒ€์ƒ‰ ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ๋‚ด ์‹ํ’ˆ์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeFoodsRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "(F0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์นดํ…Œ๊ณ ๋ฆฌ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.",
@ApiResponse(responseCode = "404", description = "(R0003)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@GetMapping("/{fridgeId}/foods")
public ResponseCustom<FridgeMainRes> getFoods(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(description = "์‹ํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.getFoods(fridgeId, userId, category));
}


@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ๊ฒ€์ƒ‰ ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ๋‚ด ์‹ํ’ˆ์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeFoodsRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@GetMapping("/{fridgeId}/search")
public ResponseCustom<List<FridgeFoodsRes>> searchFridgeFood(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(description = "์‹ํ’ˆ๋ช…") @RequestParam String keyword,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.searchFridgeFood(fridgeId, userId, keyword));
public ResponseCustom<Page<FridgeFoodsRes>> searchFridgeFood(@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(description = "์‹ํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(description = "์‹ํ’ˆ๋ช…") @RequestParam(required = false) String word,
Pageable pageable,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.searchFridgeFoods(fridgeId, userId, word, category, pageable));
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ƒ์„ธ ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ๋‚ด ์‹ํ’ˆ์„ ์ƒ์„ธ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeFoodsRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "403", description = "(G0001)๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0002)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‹ํ’ˆ์ž…๋‹ˆ๋‹ค.",
@ApiResponse(responseCode = "404", description = "(R0002)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‹ํ’ˆ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
Expand Down Expand Up @@ -224,51 +207,54 @@ public ResponseCustom<?> deleteFridgeFood(@RequestBody DeleteFridgeFoodsReq dele
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ๋ฉค๋ฒ„ ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ ์˜ ๋ฉค๋ฒ„๋ฅผ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeUserMainRes.class)
@SwaggerApiSuccess(implementation = FridgeUserRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "403", description = "(G0001)๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@Auth
@GetMapping("{fridgeId}/members")
public ResponseCustom<FridgeUserMainRes> getMembers(
@GetMapping("/{fridgeId}/members")
public ResponseCustom<List<FridgeUserRes>> getFridgeMembers(
@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.searchMembers(fridgeId, userId));
return ResponseCustom.success(fridgeService.getFridgeMembers(fridgeId, userId));
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์„ ํƒ๋ชฉ๋ก ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ์„ ํƒ๋ชฉ๋ก์„ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = SelectFridgesMainRes.class)
@Operation(summary = "๋‚ด ๋ƒ‰์žฅ๊ณ  ์กฐํšŒ", description = "์‚ฌ์šฉ์ž์˜ ๋ƒ‰์žฅ๊ณ ๋ฅผ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = MyFridgeRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@GetMapping("/select")
public ResponseCustom<SelectFridgesMainRes> selectFridges(
@GetMapping
public ResponseCustom<MyFridgeRes> getMyFridge(
@Parameter(hidden = true) @IsLogin Long userId
) {
return ResponseCustom.success(fridgeService.selectFridges(userId));
return ResponseCustom.success(fridgeService.getMyFridge(userId));
}

@Operation(summary = "๋ƒ‰์žฅ๊ณ  ๋ชฉ๋ก ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ๋ชฉ๋ก์„ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = GetFridgesMainRes.class)
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์ •๋ณด ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ์ •๋ณด๋ฅผ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = FridgeInfoRes.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "(U0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.",
@ApiResponse(responseCode = "404", description = "(R0000)์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ƒ‰์žฅ๊ณ ์ž…๋‹ˆ๋‹ค.\t\n" +
"(R0003)ํ•ด๋‹น ๋ƒ‰์žฅ๊ณ ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@Auth
@GetMapping("")
public ResponseCustom<GetFridgesMainRes> myFridge(@Parameter(hidden = true) @IsLogin Long userId) {
return ResponseCustom.success(fridgeService.myFridge(userId));
@GetMapping("/{fridgeId}")
public ResponseCustom<FridgeInfoRes> getFridgeInfo(
@Parameter(description = "๋ƒ‰์žฅ๊ณ  ID") @PathVariable Long fridgeId,
@Parameter(hidden = true) @IsLogin Long userId
) {
return ResponseCustom.success(fridgeService.getFridgeInfo(userId, fridgeId));
}

/**
* [Get] ๋ƒ‰์žฅ๊ณ  ํ†ต๊ณ„ (๋‚ญ๋น„/์†Œ๋น„)
*/
@Operation(summary = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์‚ญ์ œ ํ†ต๊ณ„ ์กฐํšŒ", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ์˜ ์‚ญ์ œ ํƒ€์ž…๋ณ„ ํ†ต๊ณ„๋ฅผ ์กฐํšŒํ•œ๋‹ค.")
@SwaggerApiSuccess(implementation = GetFridgesMainRes.class)
@SwaggerApiSuccess(implementation = FridgeFoodsStatistics.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "(F0003)์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‹ํ’ˆ์‚ญ์ œ ํƒ€์ž…์ž…๋‹ˆ๋‹ค.",
content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class FridgeFoodReq {
private String foodDetailName;
@Schema(name = "foodCategory", description = "์‹ํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ")
private String foodCategory;
@Schema(name = "shelfLife", description = "์‹ํ’ˆ ์†Œ๋น„๊ธฐํ•œ")
private String shelfLife;
@Schema(name = "expirationDate", description = "์‹ํ’ˆ ์†Œ๋น„๊ธฐํ•œ")
private String expirationDate;
@Schema(name = "ownerId", description = "์‹ํ’ˆ ์†Œ์œ ์ž ID")
private Long ownerId;
@Schema(name = "memo", description = "์‹ํ’ˆ ๋ฉ”๋ชจ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.icebutler_server.fridge.dto.response;

import com.example.icebutler_server.global.util.FridgeUtils;
import com.example.icebutler_server.fridge.entity.FridgeFood;
import com.example.icebutler_server.global.util.AwsS3ImageUrlUtil;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -9,33 +8,33 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.format.DateTimeFormatter;
import java.time.LocalDate;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(name = "FridgeFoodRes", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ƒ์„ธ ์ •๋ณด")
@Schema(name = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ƒ์„ธ ์ •๋ณด", description = "FridgeFoodRes")
public class FridgeFoodRes {
@Schema(name = "fridgeFoodId", description = "๋ƒ‰์žฅ๊ณ  ID")
@Schema(description = "๋ƒ‰์žฅ๊ณ  ID", example = "1")
private Long fridgeFoodId;
@Schema(name = "foodId", description = "์‹ํ’ˆ ID")
@Schema(description = "์‹ํ’ˆ ID", example = "1")
private Long foodId;
@Schema(name = "foodName", description = "์‹ํ’ˆ๋ช…")
@Schema(description = "์‹ํ’ˆ๋ช…", example = "์‚ฌ๊ณผ")
private String foodName;
@Schema(name = "foodDetailName", description = "์‹ํ’ˆ ์ƒ์„ธ๋ช…")
@Schema(description = "์‹ํ’ˆ ์ƒ์„ธ๋ช…", example = "๋ฌด๋†์•ฝ ์‚ฌ๊ณผ")
private String foodDetailName;
@Schema(name = "foodCategory", description = "์‹ํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ")
@Schema(description = "์‹ํ’ˆ ์นดํ…Œ๊ณ ๋ฆฌ", example = "์ฑ„์†Œ")
private String foodCategory;
@Schema(name = "shelfLife", description = "์‹ํ’ˆ ์†Œ๋น„๊ธฐํ•œ")
private String shelfLife;
@Schema(name = "day", description = "์‹ํ’ˆ ์†Œ๋น„๊ธฐํ•œ ๋””๋ฐ์ด")
private int day;
@Schema(name = "owner", description = "์‹ํ’ˆ ์†Œ์œ ์ž")
@Schema(description = "์‹ํ’ˆ ์†Œ๋น„๊ธฐํ•œ", example = "2024-01-01")
private LocalDate expirationDate;
@Schema(description = "๋‚จ์€ ์†Œ๋น„๊ธฐ๊ฐ„", example = "3")
private int shelfLife;
@Schema(description = "์‹ํ’ˆ ์†Œ์œ ์ž", example = "๋‚˜์•ผ๋‚˜")
private String owner;
@Schema(name = "memo", description = "์‹ํ’ˆ ๋ฉ”๋ชจ")
@Schema(description = "์‹ํ’ˆ ๋ฉ”๋ชจ", example = "๋จน์ง€๋งˆ์„ธ์š”.")
private String memo;
@Schema(name = "imgUrl", description = "์‹ํ’ˆ ์ด๋ฏธ์ง€ URL")
@Schema(description = "์‹ํ’ˆ ์ด๋ฏธ์ง€ URL", example = "https://~~/apple.jpg")
private String imgUrl;

public static FridgeFoodRes toDto(FridgeFood fridgeFood) {
Expand All @@ -45,8 +44,8 @@ public static FridgeFoodRes toDto(FridgeFood fridgeFood) {
.foodName(fridgeFood.getFood().getFoodName())
.foodDetailName(fridgeFood.getFoodDetailName())
.foodCategory(fridgeFood.getFood().getFoodCategory().getName())
.shelfLife(fridgeFood.getShelfLife().format(DateTimeFormatter.ISO_DATE))
.day(FridgeUtils.calShelfLife(fridgeFood.getShelfLife()))
.expirationDate(fridgeFood.getExpirationDate())
.shelfLife(fridgeFood.getShelfLife())
.owner(fridgeFood.getOwner() == null ? null : fridgeFood.getOwner().getNickname())
.memo(fridgeFood.getMemo())
.imgUrl(fridgeFood.getFridgeFoodImgKey() == null ? null : AwsS3ImageUrlUtil.toUrl(fridgeFood.getFridgeFoodImgKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@
import com.example.icebutler_server.global.util.FridgeUtils;
import com.example.icebutler_server.fridge.entity.FridgeFood;
import com.example.icebutler_server.global.util.AwsS3ImageUrlUtil;
import com.querydsl.core.annotations.QueryProjection;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(name = "FridgeFoodsRes", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ •๋ณด")
public class FridgeFoodsRes {
@Schema(name = "fridgeFoodId", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ID")
private Long fridgeFoodId;
@Schema(name = "foodName", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ด๋ฆ„")
private String foodName;
@Schema(name = "foodImgUrl", description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ด๋ฏธ์ง€ URL")
private String foodImgUrl;
@Schema(name = "shelfLife", description = "์‹ํ’ˆ ์œ ํšจ๊ธฐํ•œ")
private int shelfLife;
@Schema(description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ID", example = "1")
private Long fridgeFoodId;
@Schema(description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ด๋ฆ„", example = "์‚ฌ๊ณผ")
private String foodName;
@Schema(description = "๋ƒ‰์žฅ๊ณ  ์‹ํ’ˆ ์ด๋ฏธ์ง€ URL", example = "https://~~/apple.jpg")
private String foodImgUrl;
@Schema(description = "๋‚จ์€ ์†Œ๋น„๊ธฐ๊ฐ„", example = "4")
private int shelfLife;

public static FridgeFoodsRes toDto(FridgeFood fridgeFood) {
return FridgeFoodsRes.builder()
.fridgeFoodId(fridgeFood.getId())
.foodName(fridgeFood.getFood().getFoodName())
.foodImgUrl(AwsS3ImageUrlUtil.toUrl(fridgeFood.getFood().getFoodImgKey()))
.shelfLife(FridgeUtils.calShelfLife(fridgeFood.getShelfLife()))
.build();
}
@QueryProjection
public FridgeFoodsRes(Long fridgeFoodId, String foodName, String foodImgUrl, int shelfLife) {
this.fridgeFoodId = fridgeFoodId;
this.foodName = foodName;
this.foodImgUrl = AwsS3ImageUrlUtil.toUrl(foodImgUrl);
this.shelfLife = shelfLife;
}

public static FridgeFoodsRes toDto(FridgeFood fridgeFood) {
return FridgeFoodsRes.builder()
.fridgeFoodId(fridgeFood.getId())
.foodName(fridgeFood.getFood().getFoodName())
.foodImgUrl(AwsS3ImageUrlUtil.toUrl(fridgeFood.getFood().getFoodImgKey()))
.shelfLife(FridgeUtils.calShelfLife(fridgeFood.getExpirationDate()))
.build();
}
}
Loading

0 comments on commit 8f1d29e

Please sign in to comment.