Skip to content

Commit

Permalink
fix: cuisine change to presigned url
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 26, 2024
1 parent 8314966 commit f0ce644
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.foodgo.apimodule.cuisine.dto.TestResultType;
import com.foodgo.apimodule.ingredient.dto.IngredientInfo;
import com.foodgo.apimodule.ingredient.mapper.IngredientMapper;
import com.foodgo.commonmodule.image.service.FileService;
import com.foodgo.coremodule.cuisine.domain.Ingredient;
import com.foodgo.coremodule.cuisine.domain.TestType;
import com.foodgo.coremodule.cuisine.exception.CuisineErrorCode;
Expand All @@ -25,6 +26,7 @@
public class CuisineFindUseCase {

private final CuisineQueryService cuisineQueryService;
private final FileService fileService;

@Value("${spring.openapi.key.recipe}")
private String apiKey;
Expand All @@ -35,7 +37,8 @@ public List<IngredientInfo> findIngredientInfo(User user) {

List<Ingredient> ingredients = cuisineQueryService.findIngredientsByUserId(user.getId());
for (Ingredient ingredient : ingredients) {
final IngredientInfo infoDTO = IngredientMapper.toInfoDTO(ingredient);
String imageUrl = ingredient.getImageUrl().isEmpty() ? null : fileService.getDownloadPresignedUrl(ingredient.getImageUrl());
final IngredientInfo infoDTO = IngredientMapper.toInfoDTO(ingredient, imageUrl);
infoList.add(infoDTO);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package com.foodgo.apimodule.cuisine.application;

import com.foodgo.apimodule.ingredient.dto.IngredientAddReq;
import com.foodgo.apimodule.cuisine.dto.TestResultType;
import com.foodgo.apimodule.ingredient.dto.IngredientAddReq;
import com.foodgo.apimodule.ingredient.mapper.IngredientMapper;
import com.foodgo.commonmodule.image.service.AwsS3Service;
import com.foodgo.coremodule.cuisine.domain.CuisineTest;
import com.foodgo.coremodule.cuisine.domain.Ingredient;
import com.foodgo.coremodule.cuisine.service.CuisineQueryService;
import com.foodgo.coremodule.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@RequiredArgsConstructor
@Transactional
public class CuisineSaveUseCase {

private final CuisineQueryService cuisineQueryService;
private final AwsS3Service awsS3Service;

public void saveIngredient(IngredientAddReq addReq, MultipartFile multipartFile, User user) {

String imageUrl = awsS3Service.uploadFile(multipartFile);
Ingredient ingredient = IngredientMapper.toIngredientEntity(addReq, user, imageUrl);
public void saveIngredient(IngredientAddReq addReq, User user) {

Ingredient ingredient = IngredientMapper.toIngredientEntity(addReq, user);
cuisineQueryService.saveIngredient(ingredient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.URISyntaxException;
import java.util.List;
Expand Down Expand Up @@ -62,10 +61,9 @@ public ApplicationResponse<List<IngredientInfo>> findIngredientList(@UserResolve
)
@Operation(summary = "식재료 리스트 추가 API", description = "식재료 리스트 추가 API 입니다.")
public ApplicationResponse<String> addIngredientList(@UserResolver User user,
@RequestPart(value = "dto") IngredientAddReq addReq,
@RequestPart(value = "file") MultipartFile multipartFile) {
@RequestBody IngredientAddReq addReq) {

cuisineSaveUseCase.saveIngredient(addReq, multipartFile, user);
cuisineSaveUseCase.saveIngredient(addReq, user);
return ApplicationResponse.ok("식재료 리스트 추가되었습니다.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public record IngredientAddReq(
String name,
String quantity
String quantity,
String imageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class IngredientMapper {

public static IngredientInfo toInfoDTO(Ingredient ingredient) {
public static IngredientInfo toInfoDTO(Ingredient ingredient, String imageUrl) {
return new IngredientInfo(
ingredient.getId(),
ingredient.getName(),
ingredient.getQuantity(),
ingredient.getImageUrl()
imageUrl
);
}

public static Ingredient toIngredientEntity(IngredientAddReq addReq, User user, String imageUrl) {
public static Ingredient toIngredientEntity(IngredientAddReq addReq, User user) {
return Ingredient.builder()
.name(addReq.name())
.quantity(addReq.quantity())
.imageUrl(imageUrl)
.imageUrl(addReq.imageUrl())
.user(user)
.build();
}
Expand Down

0 comments on commit f0ce644

Please sign in to comment.