diff --git a/build.gradle b/build.gradle index 8772f39c..9a292acc 100644 --- a/build.gradle +++ b/build.gradle @@ -67,6 +67,11 @@ dependencies { // https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.282' + //cache & redis + implementation 'org.springframework.boot:spring-boot-starter-cache' + implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'org.springframework.session:spring-session-core' + implementation 'org.springframework.session:spring-session-data-redis' } tasks.named('test') { diff --git a/src/main/java/project/trendpick_pro/TrendPickProApplication.java b/src/main/java/project/trendpick_pro/TrendPickProApplication.java index 99cccbe0..3f5dba73 100644 --- a/src/main/java/project/trendpick_pro/TrendPickProApplication.java +++ b/src/main/java/project/trendpick_pro/TrendPickProApplication.java @@ -2,9 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableScheduling; +@EnableCaching @EnableScheduling @EnableJpaAuditing @SpringBootApplication diff --git a/src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java b/src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java index f9e3c31e..5fbd150c 100644 --- a/src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java +++ b/src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java @@ -14,6 +14,7 @@ import org.springframework.web.servlet.LocaleResolver; import project.trendpick_pro.domain.member.entity.Member; import project.trendpick_pro.domain.member.entity.RoleType; +import project.trendpick_pro.domain.member.entity.form.JoinForm; import project.trendpick_pro.domain.member.exception.MemberNotFoundException; import project.trendpick_pro.domain.member.exception.MemberNotMatchException; import project.trendpick_pro.domain.member.service.MemberService; @@ -179,6 +180,18 @@ public Optional CheckLogin() { throw new MemberNotFoundException("존재하지 않는 회원입니다."); } } + + public RsData RsCheckLogin() { + + String username = SecurityContextHolder.getContext().getAuthentication().getName(); // 둘다 테스트 해보기 + Optional member = memberService.findByEmail(username); + + if (memberService.findByEmail(member.get().getEmail()).isPresent()) { + return RsData.of("F-1", "로그인된 상태가 아닙니다.", member.get()); + } + return RsData.of("S-1", "추천 카테고리입니다.", member.get()); + } + public boolean checkLogin(){ String username = SecurityContextHolder.getContext().getAuthentication().getName(); // 둘다 테스트 해보기 Optional member = memberService.findByEmail(username); diff --git a/src/main/java/project/trendpick_pro/domain/product/controller/ProductController.java b/src/main/java/project/trendpick_pro/domain/product/controller/ProductController.java index 8d3bbdb0..d8122857 100644 --- a/src/main/java/project/trendpick_pro/domain/product/controller/ProductController.java +++ b/src/main/java/project/trendpick_pro/domain/product/controller/ProductController.java @@ -147,11 +147,14 @@ public String showAllProduct(@RequestParam(value = "page", defaultValue = "0") i mainCategory = "상의"; } if (mainCategory.equals("추천")) { - Member member = rq.CheckLogin().orElseThrow(() -> new MemberNotFoundException("존재하지 않는 회원입니다.")); - if (member.getRole().getValue().equals("MEMBER")) { + RsData member = rq.RsCheckLogin(); + if (member.isFail()) { + return rq.historyBack(member); + } + if (member.getData().getRole().getValue().equals("MEMBER")) { model.addAttribute("subCategoryName", subCategory); model.addAttribute("mainCategoryName", mainCategory); - model.addAttribute("productResponses", recommendService.getFindAll(member, offset)); + model.addAttribute("productResponses", recommendService.getFindAll(member.getData(), offset)); model.addAttribute("subCategories", subCategoryService.findAll(mainCategory)); } else { model.addAttribute("subCategoryName", subCategory); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index dd8c1ef7..731498dc 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -11,6 +11,10 @@ spring: hibernate: format_sql: true use_sql_comments: true + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration + - org.springframework.boot.autoconfigure.session.SessionAutoConfiguration logging.level: org: hibernate.SQL: debug diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 5c588062..667da36a 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -17,9 +17,12 @@ spring: exclude: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://db-gv7so.cdb.ntruss.com:3306/trendpick + url: jdbc:mysql://db-gv7so.pub-cdb.ntruss.com:3306/trendpick username: trendpick password: trendpick@111 jpa: hibernate: ddl-auto: create + data: + redis: + host: 172.17.0.1