Skip to content

Commit

Permalink
Merge pull request #208 from TrandPick/refactor/207_EnableRedis
Browse files Browse the repository at this point in the history
Refactor/207 enable redis
  • Loading branch information
angelSuho authored Jun 14, 2023
2 parents ed70879 + 758d4cf commit 4be72ce
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,6 +180,18 @@ public Optional<Member> CheckLogin() {
throw new MemberNotFoundException("존재하지 않는 회원입니다.");
}
}

public RsData<Member> RsCheckLogin() {

String username = SecurityContextHolder.getContext().getAuthentication().getName(); // 둘다 테스트 해보기
Optional<Member> 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> member = memberService.findByEmail(username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4be72ce

Please sign in to comment.