Skip to content

Commit

Permalink
Merge pull request #357 from TrandPick/development
Browse files Browse the repository at this point in the history
트랜드픽 배포
  • Loading branch information
angelSuho authored Jul 10, 2023
2 parents c81c665 + c46c7f1 commit 80708c0
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package project.trendpick_pro.domain.common.view.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
public class View {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long count = 0L;

public void increment() {
this.count++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package project.trendpick_pro.domain.common.view.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import project.trendpick_pro.domain.common.view.entity.View;

public interface ViewRepository extends JpaRepository<View, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package project.trendpick_pro.domain.common.view.service;

import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import project.trendpick_pro.domain.common.view.entity.View;
import project.trendpick_pro.domain.common.view.repository.ViewRepository;

@Service
@RequiredArgsConstructor
public class ViewService {

private final ViewRepository viewRepository;

private final KafkaTemplate<String, String> kafkaTemplate;

@Transactional
public void registerView() {
viewRepository.save(new View());
}

@Transactional(readOnly = true)
public int findSize() {
return viewRepository.findAll().size();
}

public void requestIncrementViewCount(HttpSession session) {
if (session.getAttribute("visited") == null) {
kafkaTemplate.send("views", "increment", "1");
session.setAttribute("visited", true);
}
}

@Transactional
@KafkaListener(topicPattern = "views", groupId = "group_id")
public void handleIncrementViewCount(@Payload String viewId) {
View totalView = viewRepository.findById(Long.valueOf(viewId)).get();
totalView.increment();
}

@Transactional(readOnly = true)
public Long getCount() {
return viewRepository.findById(1L).get().getCount();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package project.trendpick_pro.domain.product.controller;

import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,6 +21,7 @@
import project.trendpick_pro.domain.category.service.MainCategoryService;
import project.trendpick_pro.domain.category.service.SubCategoryService;
import project.trendpick_pro.domain.common.base.rq.Rq;
import project.trendpick_pro.domain.common.view.service.ViewService;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.service.MemberService;
import project.trendpick_pro.domain.product.entity.dto.ProductRequest;
Expand Down Expand Up @@ -62,6 +64,8 @@ public class ProductController {
private final ReviewService reviewService;
private final AskService askService;

private final ViewService viewService;

private final Rq rq;

@Value("${colors}")
Expand Down Expand Up @@ -133,7 +137,10 @@ public String showProduct(@PathVariable Long productId, Pageable pageable, Model
public String showAllProduct(@RequestParam(value = "page", defaultValue = "0") int offset,
@RequestParam(value = "main-category", defaultValue = "all") String mainCategory,
@RequestParam(value = "sub-category", defaultValue = "전체") String subCategory,
Pageable pageable, Model model) {
Pageable pageable, Model model, HttpSession session) throws InterruptedException {
viewService.requestIncrementViewCount(session);
Thread.sleep(200);
model.addAttribute("totalView", viewService.getCount());
if (mainCategory.equals("recommend")) {
mainCategory = "추천";
} else if (mainCategory.equals("all")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void delete(Long productId) {
}

@Cacheable(value = "product", key = "#productId")
@Transactional(readOnly = true)
public ProductResponse getProduct(Long productId) {

Product product = productRepository.findById(productId).orElseThrow(() -> new ProductNotFoundException("존재하지 않는 상품입니다."));
Expand Down Expand Up @@ -284,6 +285,7 @@ public List<Product> getRecommendProduct(Member member) {
return products;
}

@Transactional(readOnly = true)
public RsData<Page<ProductListResponseBySeller>> findProductsBySeller(Member member, int offset) {
if (member.getBrand() == null)
RsData.of("F-1", "브랜드 관리자의 브랜드를 알 수 없습니다. 브랜드를 설정하세요.");
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/project/trendpick_pro/global/basedata/BaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import project.trendpick_pro.domain.category.service.MainCategoryService;
import project.trendpick_pro.domain.category.service.SubCategoryService;
import project.trendpick_pro.domain.common.file.CommonFile;
import project.trendpick_pro.domain.common.view.service.ViewService;
import project.trendpick_pro.domain.coupon.entity.Coupon;
import project.trendpick_pro.domain.coupon.entity.dto.request.StoreCouponSaveRequest;
import project.trendpick_pro.domain.coupon.repository.CouponRepository;
Expand Down Expand Up @@ -96,6 +97,7 @@ CommandLineRunner initData(
BrandService brandService,
RecommendService recommendService,
ProductService productService,
ViewService viewService,
ProductRepository productRepository,
ReviewRepository reviewRepository,
CouponRepository couponRepository,
Expand All @@ -117,10 +119,10 @@ public void run(String... args) {
accessKeyMap.put("secretKey", secretKey);
accessKeyMap.put("bucket", bucket);

int memberCount = 10;
int productCount = 100;
int reviewCount = 0;
int couponCount = 0;
int memberCount = 100;
int productCount = 1000;
int reviewCount = 100;
int couponCount = 100;
String brandName = "polo";

saveMembers(memberCount, tagNameService, memberService, recommendService);
Expand All @@ -132,6 +134,10 @@ public void run(String... args) {
saveReviews(reviewCount, productCount, accessKeyMap, memberService, productService ,reviewRepository);
saveStoreCoupon(couponCount, storeRepository, couponRepository, brandService);

if (viewService.findSize() == 0) {
viewService.registerView();
}

log.info("BASE_DATA_SUCCESS");
}
};
Expand Down
45 changes: 0 additions & 45 deletions src/main/java/project/trendpick_pro/global/config/RedisConfig.java

This file was deleted.

13 changes: 3 additions & 10 deletions src/main/resources/templates/trendpick/orders/order-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ <h1>결제 정보</h1>
})
})

var couponPopup = null;
function showCouponList(orderItemId) {
document.getElementById('main-content').style.pointerEvents = 'none';
toastr.options = {
Expand All @@ -210,12 +209,11 @@ <h1>결제 정보</h1>
tapToDismiss: false, // 탭하여 닫기 비활성화
closeButton: true // 닫기 버튼 활성화
};
// AJAX 요청을 통해 쿠폰 목록 데이터를 가져옴
$.ajax({
url: '/trendpick/usr/couponCards/apply', // 쿠폰 목록을 제공하는 API 엔드포인트의 URL
url: '/trendpick/usr/couponCards/apply',
method: 'GET',
data: {
orderItem: orderItemId // orderItemId 변수 값을 넘겨줌
orderItem: orderItemId
},
success: function(response) {
couponListHTML = '<div class="coupon-popup">\n' +
Expand All @@ -224,7 +222,6 @@ <h1>결제 정보</h1>
'쿠폰목록\n' +
'</h1>' +
'<div class="grid grid-flow-row-dense grid-cols-1 gap-4 m-2">\n';
// 쿠폰 목록 데이터를 HTML로 변환하여 팝업 창에 삽입
response.forEach(function(coupon) {
couponListHTML += `
<div class="card bg-base-80 shadow-xl">
Expand All @@ -248,10 +245,8 @@ <h3 class="card-title">${coupon.discountPercent}% 쿠폰</h3>
couponListHTML += '</div>\n' +
'<button class="btn btn-sm btn-outline close-button" onclick="closeCouponList()">닫기<button>\n' +
'</div>'
// 팝업 창을 생성하여 쿠폰 목록을 표시
var couponPopup = toastr.info(couponListHTML, '', {
closeButton: false,
// positionClass: 'toast-top-full-width',
timeOut: 0,
extendedTimeOut: 0,
tapToDismiss: false
Expand All @@ -274,11 +269,9 @@ <h3 class="card-title">${coupon.discountPercent}% 쿠폰</h3>
couponCard: couponCardId,
orderItem: orderItemId
},
success: function(response) {
success: function() {
toastr.success('쿠폰이 적용되었습니다.');
location.reload();
// 원하는 동작 수행 (예: 페이지 새로고침, 필요한 데이터 업데이트 등)
// ...
},
error: function() {
toastr.error('쿠폰 적용에 실패했습니다.');
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/templates/trendpick/products/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ <h2 class="text-lg font-bold" th:text="${product.name}" style="white-space: norm
</div>
</div>
</div>
<footer class="bg-gray-800 py-20 mt-20">
<div class="w-4/5 m-auto pt-5">
<p class="text-xl text-gray-400 text-center" style="font-size: 30px">누적 접속자: <span class="font-bold text-gray-100" th:text="${totalView} + ' 명'"></span></p>
</div>
</footer>
</main>
</body>
</html>

0 comments on commit 80708c0

Please sign in to comment.