-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
679 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
api-module/src/main/java/com/foodgo/apimodule/cuisine/application/QuisineFindUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.foodgo.apimodule.cuisine.application; | ||
|
||
import com.foodgo.apimodule.cuisine.dto.IngredientInfo; | ||
import com.foodgo.apimodule.cuisine.mapper.IngredientMapper; | ||
import com.foodgo.coremodule.quisine.domain.Ingredient; | ||
import com.foodgo.coremodule.quisine.service.QuisineQueryService; | ||
import com.foodgo.coremodule.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class QuisineFindUseCase { | ||
|
||
private final QuisineQueryService quisineQueryService; | ||
|
||
public List<IngredientInfo> findIngredientInfo(User user) { | ||
|
||
List<IngredientInfo> infoList = new ArrayList<>(); | ||
|
||
List<Ingredient> ingredients = quisineQueryService.findIngredientsByUserId(user.getId()); | ||
for (Ingredient ingredient : ingredients) { | ||
final IngredientInfo infoDTO = IngredientMapper.toInfoDTO(ingredient); | ||
infoList.add(infoDTO); | ||
} | ||
|
||
return infoList; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
api-module/src/main/java/com/foodgo/apimodule/cuisine/application/QuisineSaveUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.foodgo.apimodule.cuisine.application; | ||
|
||
import com.foodgo.apimodule.cuisine.dto.IngredientAddReq; | ||
import com.foodgo.apimodule.cuisine.mapper.IngredientMapper; | ||
import com.foodgo.commonmodule.image.service.AwsS3Service; | ||
import com.foodgo.coremodule.quisine.domain.Ingredient; | ||
import com.foodgo.coremodule.quisine.service.QuisineQueryService; | ||
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 QuisineSaveUseCase { | ||
|
||
private final QuisineQueryService quisineQueryService; | ||
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); | ||
|
||
quisineQueryService.saveIngredient(ingredient); | ||
} | ||
|
||
public void deleteIngredient(Long ingredientId) { | ||
|
||
quisineQueryService.deleteIngredient(ingredientId); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api-module/src/main/java/com/foodgo/apimodule/cuisine/dto/IngredientAddReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.foodgo.apimodule.cuisine.dto; | ||
|
||
public record IngredientAddReq( | ||
String name, | ||
String quantity | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
api-module/src/main/java/com/foodgo/apimodule/cuisine/dto/IngredientInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.foodgo.apimodule.cuisine.dto; | ||
|
||
public record IngredientInfo( | ||
Long ingredientId, | ||
String name, | ||
String quantity, | ||
String imageUrl | ||
) { | ||
} |
30 changes: 30 additions & 0 deletions
30
api-module/src/main/java/com/foodgo/apimodule/cuisine/mapper/IngredientMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.foodgo.apimodule.cuisine.mapper; | ||
|
||
import com.foodgo.apimodule.cuisine.dto.IngredientAddReq; | ||
import com.foodgo.apimodule.cuisine.dto.IngredientInfo; | ||
import com.foodgo.coremodule.quisine.domain.Ingredient; | ||
import com.foodgo.coremodule.user.domain.User; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class IngredientMapper { | ||
|
||
public static IngredientInfo toInfoDTO(Ingredient ingredient) { | ||
return new IngredientInfo( | ||
ingredient.getId(), | ||
ingredient.getName(), | ||
ingredient.getQuantity(), | ||
ingredient.getImageUrl() | ||
); | ||
} | ||
|
||
public static Ingredient toIngredientEntity(IngredientAddReq addReq, User user, String imageUrl) { | ||
return Ingredient.builder() | ||
.name(addReq.name()) | ||
.quantity(addReq.quantity()) | ||
.imageUrl(imageUrl) | ||
.user(user) | ||
.build(); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
api-module/src/main/java/com/foodgo/apimodule/cuisine/presentation/QuisineController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.foodgo.apimodule.cuisine.presentation; | ||
|
||
import com.foodgo.apimodule.cuisine.application.QuisineFindUseCase; | ||
import com.foodgo.apimodule.cuisine.application.QuisineSaveUseCase; | ||
import com.foodgo.apimodule.cuisine.dto.IngredientAddReq; | ||
import com.foodgo.apimodule.cuisine.dto.IngredientInfo; | ||
import com.foodgo.apimodule.user.annotation.UserResolver; | ||
import com.foodgo.commonmodule.common.ApplicationResponse; | ||
import com.foodgo.coremodule.user.domain.User; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/quisine") | ||
@Validated | ||
@Tag(name = "Quisine", description = "음식 추천 관련 API") | ||
public class QuisineController { | ||
|
||
private final QuisineFindUseCase quisineFindUseCase; | ||
private final QuisineSaveUseCase quisineSaveUseCase; | ||
|
||
// 전체 조회 | ||
@GetMapping | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "식재료 리스트 확인 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "식재료 리스트 확인 API", description = "식재료 리스트 확인 API 입니다.") | ||
public ApplicationResponse<List<IngredientInfo>> findIngredientList(@UserResolver User user) { | ||
|
||
final List<IngredientInfo> ingredientInfo = quisineFindUseCase.findIngredientInfo(user); | ||
return ApplicationResponse.ok(ingredientInfo); | ||
} | ||
|
||
// 식재료 추가하기 | ||
@PostMapping | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "식재료 리스트 추가 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "식재료 리스트 추가 API", description = "식재료 리스트 추가 API 입니다.") | ||
public ApplicationResponse<String> addIngredientList(@UserResolver User user, | ||
@RequestPart(value = "dto") IngredientAddReq addReq, | ||
@RequestPart(value = "file") MultipartFile multipartFile) { | ||
|
||
quisineSaveUseCase.saveIngredient(addReq, multipartFile, user); | ||
return ApplicationResponse.ok("식재료 리스트 추가되었습니다."); | ||
} | ||
|
||
// 식재료 삭제하기 | ||
@DeleteMapping("{ingredientId}") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "식재료 리스트 삭제 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "식재료 리스트 삭제 API", description = "식재료 리스트 삭제 API 입니다.") | ||
public ApplicationResponse<String> deleteIngredient(@PathVariable Long ingredientId) { | ||
|
||
quisineSaveUseCase.deleteIngredient(ingredientId); | ||
return ApplicationResponse.ok("식재료 리스트가 삭제되었습니다."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +0,0 @@ | ||
spring: | ||
|
||
config: | ||
activate: | ||
on-profile: prod | ||
|
||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://foodgo-database.cfe8w8i089jb.ap-northeast-2.rds.amazonaws.com:3306/foodgo_database | ||
username: foodgodatabase | ||
password: foodgodatabase | ||
|
||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.MySQL8Dialect | ||
show_sql: false # hibernate 로그 남길지 | ||
|
||
data: | ||
redis: | ||
host: redis | ||
port: 6379 | ||
|
||
jwt: | ||
secret: aGFuZXVtLWZvb2Rnby1qd3Qtc2VjcmV0LWtleQo= | ||
token: | ||
access-expiration-time: 86400000 # 24 * 60 * 60 * 1000 = 1일 | ||
refresh-expiration-time: 604800000 # 7 * 24 * 60 * 60 * 1000 = 7일 | ||
|
||
logging: | ||
level: | ||
org: | ||
hibernate.sql: debug | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.