diff --git a/.github/workflows/dev_api_ci_cd.yml b/.github/workflows/dev_api_ci_cd.yml index 0bbde3dc..b85b4131 100644 --- a/.github/workflows/dev_api_ci_cd.yml +++ b/.github/workflows/dev_api_ci_cd.yml @@ -41,6 +41,7 @@ jobs: aws.s3.access-key: ${{ secrets.AWS_S3_ACCESS_KEY }} aws.s3.secret-key: ${{ secrets.AWS_S3_SECRET_KEY }} spring.redis.host: ${{ secrets.REDIS_HOST }} + spring.redis.port: ${{ secrets.REDIS_DEV_PORT }} oauth.apple.iss: ${{ secrets.APPLE_ISS }} oauth.apple.client-id: ${{ secrets.APPLE_CLIENT_ID }} slack.webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/prod_api_ci_cd.yml b/.github/workflows/prod_api_ci_cd.yml index 8a570630..ac8c8e22 100644 --- a/.github/workflows/prod_api_ci_cd.yml +++ b/.github/workflows/prod_api_ci_cd.yml @@ -45,6 +45,7 @@ jobs: aws.s3.access-key: ${{ secrets.AWS_S3_ACCESS_KEY }} aws.s3.secret-key: ${{ secrets.AWS_S3_SECRET_KEY }} spring.redis.host: ${{ secrets.REDIS_HOST }} + spring.redis.port: ${{ secrets.REDIS_PROD_HOST }} oauth.apple.iss: ${{ secrets.APPLE_ISS }} oauth.apple.client-id: ${{ secrets.APPLE_CLIENT_ID }} slack.webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} @@ -89,7 +90,7 @@ jobs: cp Procfile deploy/Procfile cp -r .ebextensions-prod deploy/.ebextensions cp -r .platform deploy/.platform - cd deploy && zip -r winey-server-api-${{steps.current-time.outputs.formattedTime}}-${{github.sha}} . + cd deploy && zip -r winey-prod-api-${{steps.current-time.outputs.formattedTime}}-${{github.sha}} . - name: Deploy Consumer to EB uses: einaregilsson/beanstalk-deploy@v19 diff --git a/Winey-API/src/main/java/com/example/wineyapi/WineyApiApplication.java b/Winey-API/src/main/java/com/example/wineyapi/WineyApiApplication.java index 5c24a7e5..0c11896b 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/WineyApiApplication.java +++ b/Winey-API/src/main/java/com/example/wineyapi/WineyApiApplication.java @@ -1,9 +1,13 @@ package com.example.wineyapi; +import static com.example.wineycommon.constants.WineyStatic.*; + import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.servers.Server; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; @@ -30,7 +34,7 @@ public class WineyApiApplication implements ApplicationListener createWine(@RequestBody WineRe @GetMapping("/wines/recommend") @ApiErrorCodeExample(UserAuthErrorCode.class) @Operation(summary= "02-01 Wine🍷 ν™ˆν™”λ©΄ 와인 쑰회 API #FRAME 001_01_ν™ˆ/λ©”μΈνŽ˜μ΄μ§€ Made By Austin",description = "ν™ˆν™”λ©΄ 와인 μΆ”μ²œ μ‘°νšŒμž…λ‹ˆλ‹€.") - public CommonResponse> recommendWine(@Parameter(hidden = true) @AuthenticationPrincipal User user) { + public CommonResponse> recommendWine(@Parameter(hidden = true) @AuthenticationPrincipal User user) { return CommonResponse.onSuccess(wineService.recommendWine(user)); } diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java b/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java index 554bef49..d2ce36cf 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/convertor/WineConvertor.java @@ -1,9 +1,10 @@ package com.example.wineyapi.wine.convertor; -import com.example.wineyapi.common.redis.RecommendWine; +import com.example.wineydomain.redis.entity.RecommendWine; import com.example.wineyapi.wine.dto.WineResponse; import com.example.wineyapi.wine.service.WineHelper; import com.example.wineycommon.reponse.PageResponse; +import com.example.wineydomain.redis.model.RecommendWineDTO; import com.example.wineydomain.tastingNote.repository.TastingNoteRepository; import com.example.wineydomain.user.entity.User; import com.example.wineydomain.wine.entity.Wine; @@ -25,12 +26,12 @@ @RequiredArgsConstructor public class WineConvertor { private final WineHelper wineHelper; - public List RecommendWineCountByWine(List wineLists) { - List recommendWineDTOS = new ArrayList<>(); + public List RecommendWineCountByWine(List wineLists) { + List recommendWineDTOS = new ArrayList<>(); wineLists.forEach( result -> recommendWineDTOS.add( - WineResponse.RecommendWineDTO.builder() + RecommendWineDTO.builder() .name(result.getName()) .wineId(result.getWineId()) .country(result.getCountry()) @@ -49,12 +50,12 @@ public List RecommendWineCountByWine(List toRecommendWineDto(List wineLists) { - List recommendWineDTOS = new ArrayList<>(); + public List toRecommendWineDto(List wineLists) { + List recommendWineDTOS = new ArrayList<>(); wineLists.forEach( result -> recommendWineDTOS.add( - WineResponse.RecommendWineDTO.builder() + RecommendWineDTO.builder() .wineId(result.getId()) .name(result.getName()) .country(result.getCountry()) @@ -111,7 +112,7 @@ public WineResponse.WineDTO toWineDTO(Wine wine, WineSummary wineSummary) { .build(); } - public RecommendWine toRecommendWine(User user, List recommendWineLists) { + public RecommendWine toRecommendWine(User user, List recommendWineLists) { LocalDateTime now = LocalDateTime.now(); LocalDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay(); diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/dto/WineResponse.java b/Winey-API/src/main/java/com/example/wineyapi/wine/dto/WineResponse.java index 18bd2749..e907dc9a 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/dto/WineResponse.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/dto/WineResponse.java @@ -49,24 +49,6 @@ public static class CreateWineDTO { private String field; } - @NoArgsConstructor - @Getter - @AllArgsConstructor - @Builder - public static class RecommendWineDTO { - private Long wineId; - - private String name; - - private String country; - - private String type; - - private List varietal; - - private int price; - } - @NoArgsConstructor @Getter @Setter diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineService.java b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineService.java index 0b36eb43..483ded4b 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineService.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineService.java @@ -3,12 +3,13 @@ import com.example.wineyapi.wine.dto.WineResponse; import com.example.wineycommon.reponse.PageResponse; +import com.example.wineydomain.redis.model.RecommendWineDTO; import com.example.wineydomain.user.entity.User; import java.util.List; public interface WineService { - List recommendWine(User user); + List recommendWine(User user); PageResponse> searchWineList(Integer page, Integer size, String content); diff --git a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java index 5bee8bbe..5cb61bf9 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wine/service/WineServiceImpl.java @@ -1,7 +1,8 @@ package com.example.wineyapi.wine.service; -import com.example.wineyapi.common.redis.RecommendWine; -import com.example.wineyapi.common.redis.RecommendWineRepository; +import com.example.wineydomain.redis.entity.RecommendWine; +import com.example.wineydomain.redis.model.RecommendWineDTO; +import com.example.wineydomain.redis.repository.RecommendWineRepository; import com.example.wineyapi.wine.convertor.WineConvertor; import com.example.wineyapi.wine.dto.WineResponse; import com.example.wineycommon.exception.NotFoundException; @@ -16,6 +17,7 @@ import com.example.wineydomain.wine.repository.WineRepository; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -23,6 +25,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -31,18 +34,14 @@ public class WineServiceImpl implements WineService { private final WineConvertor wineConvertor; private final WineRepository wineRepository; private final RecommendWineRepository recommendWineRepository; - @Override - public List recommendWine(User user) { - if(recommendWineRepository.existsById(String.valueOf(user.getId()))){ - RecommendWine recommendWine = recommendWineRepository.findById(String.valueOf(user.getId())).get(); - return recommendWine.getRecommendWineList(); - } + @Override + public List recommendWine(User user) { + Optional recommendWine = recommendWineRepository.findById(String.valueOf(user.getId())); + if (recommendWine.isPresent()) return recommendWine.get().getRecommendWineList(); List tastingNotes = tastingNoteRepository.findTop3ByUserAndBuyAgainOrderByStarRatingDescCreatedAtDesc(user, true); - - List recommendWineDTOS = wineConvertor.toRecommendWineDto(findRecommend(user, tastingNotes)); + List recommendWineDTOS = wineConvertor.toRecommendWineDto(findRecommend(user, tastingNotes)); recommendWineRepository.save(wineConvertor.toRecommendWine(user, recommendWineDTOS)); - return recommendWineDTOS; } diff --git a/Winey-API/src/main/java/com/example/wineyapi/wineTip/controller/WineTipController.java b/Winey-API/src/main/java/com/example/wineyapi/wineTip/controller/WineTipController.java index 17c78996..fc74e037 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/wineTip/controller/WineTipController.java +++ b/Winey-API/src/main/java/com/example/wineyapi/wineTip/controller/WineTipController.java @@ -29,9 +29,7 @@ public CommonResponse>> getWineTip @Parameter(description = "νŽ˜μ΄μ§€", example = "0") @RequestParam(required = false, defaultValue = "0") Integer page, @Parameter(description = "νŽ˜μ΄μ§€ μ‚¬μ΄μ¦ˆ", example = "10") @RequestParam(required = false, defaultValue = "10") Integer size ){ - PageResponse> wineTip = wineTipService.getWineTip(page, size); - return CommonResponse.onSuccess(wineTip); + return CommonResponse.onSuccess(wineTipService.getWineTip(page, size)); } - } diff --git a/Winey-Common/src/main/resources/application-common.yml b/Winey-Common/src/main/resources/application-common.yml index 512a48ea..6a22078b 100644 --- a/Winey-Common/src/main/resources/application-common.yml +++ b/Winey-Common/src/main/resources/application-common.yml @@ -31,7 +31,7 @@ aws: spring: redis: host: ${REDIS_HOST} - port: 6379 + port: ${REDIS_PORT} slack: webhook-url: ${SLACK_WEBHOOK_URL} diff --git a/Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWine.java b/Winey-Domain/src/main/java/com/example/wineydomain/redis/entity/RecommendWine.java similarity index 79% rename from Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWine.java rename to Winey-Domain/src/main/java/com/example/wineydomain/redis/entity/RecommendWine.java index 9c1498e7..603009e3 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWine.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/redis/entity/RecommendWine.java @@ -1,4 +1,4 @@ -package com.example.wineyapi.common.redis; +package com.example.wineydomain.redis.entity; import java.util.List; @@ -6,7 +6,7 @@ import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.TimeToLive; -import com.example.wineyapi.wine.dto.WineResponse; +import com.example.wineydomain.redis.model.RecommendWineDTO; import com.example.wineydomain.wine.repository.WineRepository; import lombok.AccessLevel; @@ -24,7 +24,7 @@ public class RecommendWine { @Id private String id; - private List recommendWineList; + private List recommendWineList; @TimeToLive private long ttl; } diff --git a/Winey-Domain/src/main/java/com/example/wineydomain/redis/model/RecommendWineDTO.java b/Winey-Domain/src/main/java/com/example/wineydomain/redis/model/RecommendWineDTO.java new file mode 100644 index 00000000..c8206d90 --- /dev/null +++ b/Winey-Domain/src/main/java/com/example/wineydomain/redis/model/RecommendWineDTO.java @@ -0,0 +1,26 @@ +package com.example.wineydomain.redis.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +@AllArgsConstructor +@Builder +public class RecommendWineDTO { + private Long wineId; + + private String name; + + private String country; + + private String type; + + private List varietal; + + private int price; +} \ No newline at end of file diff --git a/Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWineRepository.java b/Winey-Domain/src/main/java/com/example/wineydomain/redis/repository/RecommendWineRepository.java similarity index 66% rename from Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWineRepository.java rename to Winey-Domain/src/main/java/com/example/wineydomain/redis/repository/RecommendWineRepository.java index 2e4aedf3..99c2c5e2 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/common/redis/RecommendWineRepository.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/redis/repository/RecommendWineRepository.java @@ -1,8 +1,10 @@ -package com.example.wineyapi.common.redis; +package com.example.wineydomain.redis.repository; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import com.example.wineydomain.redis.entity.RecommendWine; + @Repository public interface RecommendWineRepository extends CrudRepository { }