Skip to content

Commit

Permalink
�Api-Release-v0.0.1-1
Browse files Browse the repository at this point in the history
Port 수정 및 코드 구조 변경
  • Loading branch information
imenuuu authored May 31, 2024
2 parents 53974fb + fbed3b4 commit 880de64
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dev_api_ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/prod_api_ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,7 +34,7 @@ public class WineyApiApplication implements ApplicationListener<ApplicationReady
public static void main(String[] args) {
SpringApplication.run(WineyApiApplication.class, args);
long heapSize = Runtime.getRuntime().totalMemory();
log.info("MATCH API Server - HEAP Size(M) : "+ heapSize / (1024*1024) + " MB");
log.info("WINEY API Server - HEAP Size(M) : "+ heapSize / (1024*1024) + " MB");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private HttpServletRequest unwrapHttpServletRequest(HttpServletRequest request)
return request;
} else if (request instanceof ResourceUrlEncodingFilter) {
return new ContentCachingRequestWrapper(request);
} else if (request instanceof HttpServletRequest){
} else if (request != null){
return new ContentCachingRequestWrapper(request);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.wineycommon.annotation.ApiErrorCodeExample;
import com.example.wineycommon.reponse.CommonResponse;
import com.example.wineycommon.reponse.PageResponse;
import com.example.wineydomain.redis.model.RecommendWineDTO;
import com.example.wineydomain.user.entity.User;
import com.example.wineydomain.user.exception.UserAuthErrorCode;
import com.example.wineydomain.wine.exception.ReadWineErrorCode;
Expand Down Expand Up @@ -42,7 +43,7 @@ public CommonResponse<WineResponse.CreateWineDTO> createWine(@RequestBody WineRe
@GetMapping("/wines/recommend")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary= "02-01 Wine🍷 홈화면 와인 조회 API #FRAME 001_01_홈/메인페이지 Made By Austin",description = "홈화면 와인 추천 조회입니다.")
public CommonResponse<List<WineResponse.RecommendWineDTO>> recommendWine(@Parameter(hidden = true) @AuthenticationPrincipal User user) {
public CommonResponse<List<RecommendWineDTO>> recommendWine(@Parameter(hidden = true) @AuthenticationPrincipal User user) {
return CommonResponse.onSuccess(wineService.recommendWine(user));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,12 +26,12 @@
@RequiredArgsConstructor
public class WineConvertor {
private final WineHelper wineHelper;
public List<WineResponse.RecommendWineDTO> RecommendWineCountByWine(List<TastingNoteRepository.WineList> wineLists) {
List<WineResponse.RecommendWineDTO> recommendWineDTOS = new ArrayList<>();
public List<RecommendWineDTO> RecommendWineCountByWine(List<TastingNoteRepository.WineList> wineLists) {
List<RecommendWineDTO> recommendWineDTOS = new ArrayList<>();

wineLists.forEach(
result -> recommendWineDTOS.add(
WineResponse.RecommendWineDTO.builder()
RecommendWineDTO.builder()
.name(result.getName())
.wineId(result.getWineId())
.country(result.getCountry())
Expand All @@ -49,12 +50,12 @@ public List<WineResponse.RecommendWineDTO> RecommendWineCountByWine(List<Tasting
return recommendWineDTOS;
}

public List<WineResponse.RecommendWineDTO> toRecommendWineDto(List<WineRepository.WineList> wineLists) {
List<WineResponse.RecommendWineDTO> recommendWineDTOS = new ArrayList<>();
public List<RecommendWineDTO> toRecommendWineDto(List<WineRepository.WineList> wineLists) {
List<RecommendWineDTO> recommendWineDTOS = new ArrayList<>();

wineLists.forEach(
result -> recommendWineDTOS.add(
WineResponse.RecommendWineDTO.builder()
RecommendWineDTO.builder()
.wineId(result.getId())
.name(result.getName())
.country(result.getCountry())
Expand Down Expand Up @@ -111,7 +112,7 @@ public WineResponse.WineDTO toWineDTO(Wine wine, WineSummary wineSummary) {
.build();
}

public RecommendWine toRecommendWine(User user, List<WineResponse.RecommendWineDTO> recommendWineLists) {
public RecommendWine toRecommendWine(User user, List<RecommendWineDTO> recommendWineLists) {
LocalDateTime now = LocalDateTime.now();

LocalDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> varietal;

private int price;
}

@NoArgsConstructor
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WineResponse.RecommendWineDTO> recommendWine(User user);
List<RecommendWineDTO> recommendWine(User user);

PageResponse<List<WineResponse.SearchWineDto>> searchWineList(Integer page, Integer size, String content);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,13 +17,15 @@
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;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -31,18 +34,14 @@ public class WineServiceImpl implements WineService {
private final WineConvertor wineConvertor;
private final WineRepository wineRepository;
private final RecommendWineRepository recommendWineRepository;
@Override
public List<WineResponse.RecommendWineDTO> 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<RecommendWineDTO> recommendWine(User user) {
Optional<RecommendWine> recommendWine = recommendWineRepository.findById(String.valueOf(user.getId()));
if (recommendWine.isPresent()) return recommendWine.get().getRecommendWineList();
List<TastingNote> tastingNotes = tastingNoteRepository.findTop3ByUserAndBuyAgainOrderByStarRatingDescCreatedAtDesc(user, true);

List<WineResponse.RecommendWineDTO> recommendWineDTOS = wineConvertor.toRecommendWineDto(findRecommend(user, tastingNotes));
List<RecommendWineDTO> recommendWineDTOS = wineConvertor.toRecommendWineDto(findRecommend(user, tastingNotes));
recommendWineRepository.save(wineConvertor.toRecommendWine(user, recommendWineDTOS));

return recommendWineDTOS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public CommonResponse<PageResponse<List<WineTipResponse.WineTipDto>>> getWineTip
@Parameter(description = "페이지", example = "0") @RequestParam(required = false, defaultValue = "0") Integer page,
@Parameter(description = "페이지 사이즈", example = "10") @RequestParam(required = false, defaultValue = "10") Integer size
){
PageResponse<List<WineTipResponse.WineTipDto>> wineTip = wineTipService.getWineTip(page, size);
return CommonResponse.onSuccess(wineTip);
return CommonResponse.onSuccess(wineTipService.getWineTip(page, size));
}


}
2 changes: 1 addition & 1 deletion Winey-Common/src/main/resources/application-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ aws:
spring:
redis:
host: ${REDIS_HOST}
port: 6379
port: ${REDIS_PORT}

slack:
webhook-url: ${SLACK_WEBHOOK_URL}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.wineyapi.common.redis;
package com.example.wineydomain.redis.entity;

import java.util.List;

import org.springframework.data.annotation.Id;
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;
Expand All @@ -24,7 +24,7 @@ public class RecommendWine {
@Id
private String id;

private List<WineResponse.RecommendWineDTO> recommendWineList;
private List<RecommendWineDTO> recommendWineList;
@TimeToLive
private long ttl;
}
Original file line number Diff line number Diff line change
@@ -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<String> varietal;

private int price;
}
Original file line number Diff line number Diff line change
@@ -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<RecommendWine, String> {
}

0 comments on commit 880de64

Please sign in to comment.