Skip to content

Commit

Permalink
Merge pull request #210 from TrandPick/development
Browse files Browse the repository at this point in the history
트렌드픽 배포 v.1.0.1
  • Loading branch information
angelSuho authored Jun 14, 2023
2 parents 37039d8 + 988d9a4 commit 6b461c9
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/work-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'Dockerfile'
- 'readme.md'
branches:
- 'development'
- 'main'
jobs:
build:
name: 빌드
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ out/

### secret yml ###
src/main/resources/application-secret.yml
src/main/resources/application-db.yml

### generated ###
src/main/generated
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// db
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'

// test
Expand Down
11 changes: 0 additions & 11 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 @@ -181,17 +181,6 @@ public Optional<Member> CheckLogin() {
}
}

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 @@ -7,6 +7,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
Expand All @@ -21,8 +22,10 @@
import project.trendpick_pro.domain.common.base.rq.Rq;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.exception.MemberNotFoundException;
import project.trendpick_pro.domain.member.service.MemberService;
import project.trendpick_pro.domain.product.entity.Product;
import project.trendpick_pro.domain.product.entity.dto.request.ProductSaveRequest;
import project.trendpick_pro.domain.product.entity.dto.response.ProductListResponse;
import project.trendpick_pro.domain.product.entity.dto.response.ProductListResponseBySeller;
import project.trendpick_pro.domain.product.entity.form.ProductOptionForm;
import project.trendpick_pro.domain.product.service.ProductService;
Expand All @@ -45,6 +48,7 @@ public class ProductController {

private final ProductService productService;
private final RecommendService recommendService;
private final MemberService memberService;

private final TagNameService tagNameService;
private final BrandService brandService;
Expand Down Expand Up @@ -147,19 +151,17 @@ public String showAllProduct(@RequestParam(value = "page", defaultValue = "0") i
mainCategory = "상의";
}
if (mainCategory.equals("추천")) {
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.getData(), offset));
String username = SecurityContextHolder.getContext().getAuthentication().getName();
Optional<Member> member = memberService.findByEmail(username);
if (member.isEmpty()) {
model.addAttribute("subCategoryName", "전체");
model.addAttribute("mainCategoryName", "전체");
model.addAttribute("productResponses", productService.showAll(offset, mainCategory, subCategory));
model.addAttribute("subCategories", subCategoryService.findAll(mainCategory));
} else {
model.addAttribute("subCategoryName", subCategory);
model.addAttribute("subCategoryName", "전체");
model.addAttribute("mainCategoryName", mainCategory);
model.addAttribute("productResponses", productService.showAll(offset, mainCategory, subCategory));
model.addAttribute("productResponses", recommendService.getFindAll(member.get(), offset));
model.addAttribute("subCategories", subCategoryService.findAll(mainCategory));
}
} else if(mainCategory.equals("전체")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
public class ProductRepositoryImpl implements ProductRepositoryCustom {

private final JPAQueryFactory queryFactory;
private final JPAQuery<Long> subQuery;

public ProductRepositoryImpl(EntityManager em) {
this.queryFactory = new JPAQueryFactory(em);
this.subQuery = new JPAQuery<>(em);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
package project.trendpick_pro.domain.recommend.controller;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import project.trendpick_pro.domain.common.base.rq.Rq;
import project.trendpick_pro.domain.recommend.entity.Recommend;
import project.trendpick_pro.domain.recommend.service.RecommendService;

@Controller
@RequiredArgsConstructor
public class RecommendController {

private final RecommendService recommendService;
private final Rq rq;

@PreAuthorize("isAuthenticated()")
@GetMapping("/admin/caculate")
public String caculate(){
// recommendService.select();
recommendService.select();
return "redirect:/trendpick/products/list";
}

@PreAuthorize("isAuthenticated()")
@GetMapping("/admin/getrecommendset")
public String getRecommend(Model model, @RequestParam("page") int offset){
model.addAttribute("recommend", recommendService.getFindAll(rq.CheckMember().get(), offset));
return "main";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import project.trendpick_pro.domain.brand.entity.Brand;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.product.entity.Product;

Expand Down
32 changes: 17 additions & 15 deletions src/main/java/project/trendpick_pro/global/basedata/BaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ public void run(String... args) {
}
CreateSubCategories(mainCategoryService, subCategoryService);

em.flush();
em.clear();

JoinForm admin = JoinForm.builder()
.email("[email protected]")
.password("12345")
Expand Down Expand Up @@ -198,19 +195,7 @@ public void run(String... args) {
Rsmember1.connectAddress("서울특별시 어디구 어디로 123");
recommendService.select(Rsmember1.getEmail());
}
JoinForm member = JoinForm.builder()
.email("[email protected]")
.password("12345")
.username("sooho")
.phoneNumber("010-1234-1234")
.state("MEMBER")
.tags(tags)
.build();
Member Rsmember1 = memberService.register(member).getData();
Rsmember1.connectAddress("서울특별시 진짜 주인공 123");
memberRepository.save(Rsmember1);

recommendService.select(Rsmember1.getEmail());
JoinForm member2 = JoinForm.builder()
.email("[email protected]")
.password("12345")
Expand Down Expand Up @@ -281,6 +266,20 @@ public void run(String... args) {
productRepository.save(product);
}
}

JoinForm member = JoinForm.builder()
.email("[email protected]")
.password("12345")
.username("sooho")
.phoneNumber("010-1234-1234")
.state("MEMBER")
.tags(tags)
.build();
Member Rsmember1 = memberService.register(member).getData();
Rsmember1.connectAddress("서울특별시 진짜 주인공 123");
memberRepository.save(Rsmember1);
recommendService.select(Rsmember1.getEmail());

//==장바구니 데이터==//
cartService.addItemToCart(memberService.findByEmail("[email protected]").get(), new CartItemRequest(1L,5));
cartService.addItemToCart(memberService.findByEmail("[email protected]").get(), new CartItemRequest(2L,3));
Expand Down Expand Up @@ -333,6 +332,9 @@ public void run(String... args) {
reviewRepository.save(review3);
Review review4 = Review.of (rr, memberService.findByEmail("[email protected]").get(), product2, mainFile);
reviewRepository.save(review4);

em.flush();
em.clear();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package project.trendpick_pro.global.jmeter;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.entity.dto.MemberInfoDto;
import project.trendpick_pro.domain.member.repository.MemberRepository;

@RestController
@RequiredArgsConstructor
@RequestMapping("/jmeter")
public class JmeterController {

private final MemberRepository memberRepository;

@GetMapping("/member/info")
public MemberInfoDto getMemberInfo(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("memberId") == null) {
throw new RuntimeException("세션이 없거나 로그인되어 있지 않습니다.");
}

Long memberId = (Long) session.getAttribute("memberId");
// memberId를 사용하여 회원 정보를 조회하고 MemberInfoDto 객체를 생성하여 반환합니다.
Member member = memberRepository.findById(memberId).get();
return MemberInfoDto.of(member);
}
}
7 changes: 7 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ spring:
hibernate:
format_sql: true
use_sql_comments: true
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
data:
redis:
host: 172.17.0.1
logging.level:
org:
hibernate.SQL: debug
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ spring:
exclude:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://db-gv7so.pub-cdb.ntruss.com:3306/trendpick
url: jdbc:mysql://db-gv7so.cdb.ntruss.com:3306/trendpick
username: trendpick
password: trendpick@111
jpa:
hibernate:
ddl-auto: create
data:
redis:
host: 10.96.10.86
host: redis-1-service
9 changes: 2 additions & 7 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
spring:
profiles:
active: prod
include: secret, data
active: dev
include: secret, db, data
mvc:
pathmatch:
matching-strategy: ant_path_matcher
hiddenmethod:
filter:
enabled: true
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration

management:
endpoint:
health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ <h1 class="text-4xl font-bold ml-4">TrendPick</h1>
</a>
<div class="flex justify-between">
<ul class="menu menu-horizontal px-1">
<div th:if="${@rq.CheckLoginHtml()}">
<li th:if="!${@rq.CheckAdminHtml()}"><a href="/trendpick/products/list?main-category=recommend">추천</a></li>
</div>
<li th:if="${@rq.CheckLoginHtml()} and !${@rq.CheckAdminHtml()}"><a href="/trendpick/products/list?main-category=recommend">추천</a></li>
<li><a href="/trendpick/products/list?main-category=전체">전체</a></li>
<li><a href="/trendpick/products/list?main-category=상의">상의</a></li>
<li><a href="/trendpick/products/list?main-category=아우터">아우터</a></li>
Expand Down

0 comments on commit 6b461c9

Please sign in to comment.