Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Master 2024년 8월 30일 #302

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.readyauction.app.auction.dto.ProductRepDto;
import com.readyauction.app.auction.dto.ProductReqDto;
import com.readyauction.app.auction.dto.WinnerReqDto;
import com.readyauction.app.auction.entity.Category;
import com.readyauction.app.auction.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,31 +40,41 @@ public void createAuction(Model model) {
}

@GetMapping("") // 상품 조회
public String searchAuction(@RequestParam(required = false) String prodName,
@RequestParam(defaultValue = "0") int page, Model model) {
// 한 페이지에 9개의 아이템을 표시하고, 경매 마감 시간 적은 순으로 정렬하는 Pageable 객체 생성
Pageable pageable = PageRequest.of(page, 9, Sort.by("endTime").ascending());
public String searchAuction(
@RequestParam(required = false) String prodName,
@RequestParam(defaultValue = "ALL") String category, // Use String for category
@RequestParam(defaultValue = "0") int page,
Model model) {

Pageable pageable = PageRequest.of(page, 9, Sort.by("endTime").ascending());
Page<ProductDto> products;

// Convert category String to Enum
Category categoryEnum;
try {
categoryEnum = "ALL".equalsIgnoreCase(category) ? null : Category.valueOf(category.toUpperCase());
} catch (IllegalArgumentException e) {
// Handle invalid category by redirecting or returning an error page
return "error/404"; // or handle it appropriately
}

if (prodName != null && !prodName.isEmpty()) {
products = productService.searchProductsByName(prodName, pageable);
products = productService.searchProductsByNameAndCategory(prodName, categoryEnum, pageable);
} else {
products = productService.getAllProducts(pageable);
products = productService.getProductsByCategory(categoryEnum, pageable);
}

model.addAttribute("products", products);
model.addAttribute("currentPage", "auction"); // currentPage 값을 "auction"으로 설정
model.addAttribute("currentPage", "auction");
model.addAttribute("currentPageNumber", products.getNumber());
model.addAttribute("totalPages", products.getTotalPages());
model.addAttribute("prodName", prodName);
model.addAttribute("selectedCategory", category); // Pass the selected category

// if (page < 0 || page >= products.getTotalPages()) {
// return "redirect:/auction"; // 유효하지 않은 페이지 번호인 경우 첫 페이지로 리다이렉션
// }
return "auction/auction";

}


@GetMapping("/auctionDetails")// 경매 입찰 하는 상품 상세 페이지
public void auctionDetails() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.readyauction.app.auction.repository;

import com.readyauction.app.auction.entity.AuctionStatus;
import com.readyauction.app.auction.entity.Category;
import com.readyauction.app.auction.entity.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -90,4 +91,13 @@ AND NOT EXISTS (SELECT 1 FROM Bid b WHERE b.product.id = p.id)
// 예진 작업 끝

List<Product> findByAuctionStatus(AuctionStatus auctionStatus); // 필터링을 위한 메서드

// Filter by category and status
@Query("SELECT p FROM Product p WHERE p.category = :category AND p.auctionStatus <> :status")
Page<Product> findByCategoryAndAuctionStatus(@Param("category") Category category, @Param("status") AuctionStatus status, Pageable pageable);

// Search by name, category, and status
@Query("SELECT p FROM Product p WHERE LOWER(p.name) LIKE LOWER(CONCAT('%', :name, '%')) AND p.category = :category AND p.auctionStatus <> :status")
Page<Product> searchByNameCategoryAndStatus(@Param("name") String name, @Param("category") Category category, @Param("status") AuctionStatus status, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,28 @@ public String findByProductImage(String imageUrl) {
public void save(Product product) {
productRepository.save(product);
}

@Transactional
public Page<ProductDto> getProductsByCategory(Category category, Pageable pageable) {
if (category == null) {
return productRepository.findActiveProducts(AuctionStatus.END, pageable)
.map(this::convertToProductDto);
} else {
return productRepository.findByCategoryAndAuctionStatus(category, AuctionStatus.END, pageable)
.map(this::convertToProductDto);
}
}

@Transactional
public Page<ProductDto> searchProductsByNameAndCategory(String name, Category category, Pageable pageable) {
if (category == null) {
return productRepository.searchByNameAndStatus(name, AuctionStatus.END, pageable)
.map(this::convertToProductDto);
} else {
return productRepository.searchByNameCategoryAndStatus(name, category, AuctionStatus.END, pageable)
.map(this::convertToProductDto);
}
}


}
47 changes: 34 additions & 13 deletions src/main/resources/templates/admin/user-management.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
font-weight: bold;
}

.status-suspended {
color: orange;
font-weight: bold;
}

.status-deleted {
color: red;
font-weight: bold;
Expand Down Expand Up @@ -203,6 +208,7 @@ <h1>회원 관리</h1>

<div class="filter-buttons">
<button onclick="loadUsers('active')">활동중인 회원</button>
<button onclick="loadUsers('suspended')" style="background-color: orange">정지된 회원</button>
<button onclick="loadUsers('deleted')" style="background-color: gray">탈퇴한 회원</button>
</div>

Expand All @@ -228,7 +234,7 @@ <h1>회원 관리</h1>
<div class="pagination">
<button id="prevPage" onclick="changePage('prev')">이전</button>
<span id="currentPage">1</span>
<button id="nextPage" onclick="changePage('next')">다음 </button>
<button id="nextPage" onclick="changePage('next')">다음</button>
</div>

<div id="userDetailsModal" class="modal">
Expand All @@ -245,7 +251,7 @@ <h2>회원 상세 정보</h2>
<p><strong>생년월일 : </strong> <span id="modalUserBirth"></span></p>
<p><strong>상태 : </strong> <span id="modalUserStatus"></span></p>
<p><strong id="statusLabel">상태별 일자 : </strong> <span id="modalStatusTimestamp"></span></p>
<p><strong>매너지수 : </strong> <span id="modalMannerScore"></span></p>
<p><strong>매너점수 : </strong> <span id="modalMannerScore"></span></p>

</div>
</div>
Expand Down Expand Up @@ -284,8 +290,12 @@ <h2>회원 상세 정보</h2>
<td>${user.address}</td>
<td>${user.phone}</td>
<td>${user.birth}</td>
<td class="${currentStatus === 'active' ? 'status-active' : 'status-deleted'}">${currentStatus === 'active' ? '활동중' : '탈퇴'}</td>
`;
<td class="${
user.status === 'active' ? 'status-active' :
user.status === 'deleted' ? 'status-deleted' : 'status-suspended'
}">
${user.status === 'active' ? '활동중' : user.status === 'deleted' ? '탈퇴' : '정지됨'}</td>
`;

userTableBody.appendChild(row);
});
Expand Down Expand Up @@ -324,27 +334,37 @@ <h2>회원 상세 정보</h2>
document.getElementById('modalUserBirth').innerText = formatDate(user.birth);

// 상태에 따른 텍스트 설정
const statusText = user.status === 'active' ? '활동중' : '탈퇴';
const statusText = user.status === 'active' ? '활동중' : user.status === 'deleted' ? '탈퇴' : '정지됨';
document.getElementById('modalUserStatus').innerText = statusText;

// 상태에 따른 가입일/탈퇴일 설정
const statusTimestamp = user.status === 'active' ? formatDate(user.createdAt) : formatDate(user.deletedAt);
document.getElementById('modalStatusTimestamp').innerText = statusTimestamp;
let statusTimestamp = '';
let statusLabel = '';

if (user.status === 'active') {
statusTimestamp = formatDate(user.createdAt);
statusLabel = '가입일 : ';
} else if (user.status === 'deleted') {
statusTimestamp = formatDate(user.deletedAt);
statusLabel = '탈퇴일 : ';
} else if (user.status === 'suspended') {
statusTimestamp = ''; // 정지된 회원에 대해서는 별도의 날짜 표시가 없다고 가정
statusLabel = '❌정지된 회원❌';
}

// 상태에 따른 "상태별 일자" 텍스트 변경
const statusLabel = user.status === 'active' ? '가입일 : ' : '탈퇴일 : ';
document.querySelector('p strong#statusLabel').innerText = statusLabel; // 변경된 부분
document.getElementById('modalStatusTimestamp').innerText = statusTimestamp;
document.querySelector('p strong#statusLabel').innerText = statusLabel;

document.getElementById('modalMannerScore').innerText = user.mannerScore;

const modal = document.getElementById('userDetailsModal');
modal.style.display = "block";

document.querySelector('.close').onclick = function() {
document.querySelector('.close').onclick = function () {
modal.style.display = "none";
};

window.onclick = function(event) {
window.onclick = function (event) {
if (event.target === modal) {
modal.style.display = "none";
}
Expand All @@ -356,8 +376,9 @@ <h2>회원 상세 정보</h2>
}



function formatDate(dateString) {
const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
const options = {year: 'numeric', month: '2-digit', day: '2-digit'};
const date = new Date(dateString);
return date.toLocaleDateString('ko-KR', options).replace(/\./g, '').replace(/ /g, ' . ');
}
Expand Down
29 changes: 13 additions & 16 deletions src/main/resources/templates/auction/auction.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
<script th:inline="javascript">

function setCategory(category) {
document.getElementById('categoryInput').value = category;
filterProducts();
const currentUrl = new URL(window.location.href);
currentUrl.searchParams.set('category', category);
currentUrl.searchParams.set('page', '0'); // Reset to first page
window.location.href = currentUrl.href;
}

function filterProducts() {
var category = document.getElementById('categoryInput').value;
var products = document.getElementById('productList').getElementsByClassName('col-lg-4 col-md-6');

for (var i = 0; i < products.length; i++) {
var productCategory = products[i].getAttribute('data-category');
if (category === "ALL" || category === productCategory) {
products[i].style.display = "";
} else {
products[i].style.display = "none";
}
}
const currentUrl = new URL(window.location.href);
const category = document.getElementById('categoryInput').value || 'ALL';
currentUrl.searchParams.set('category', category);
window.location.href = currentUrl.href;
}

function goToProductPage(productId) {
Expand Down Expand Up @@ -148,21 +143,23 @@ <h6>
</div>
</div>
</div>

<!-- Pagination -->
<ul class="pagination pagination-style-one justify-content-center pt-50">
<li th:if="${products.hasPrevious()}" class="page-item page-arrow">
<a class="page-link" th:href="@{/auction(page=${products.number - 1})}"><i class="bi bi-arrow-left"></i></a>
<a class="page-link" th:href="@{/auction(page=${products.number - 1}, category=${selectedCategory})}"><i class="bi bi-arrow-left"></i></a>
</li>

<li th:each="pageNum : ${#numbers.sequence(1, products.totalPages)}"
th:classappend="${pageNum == products.number + 1} ? 'page-item active' : 'page-item'">
<a class="page-link" th:href="@{/auction(page=${pageNum - 1})}">[[${pageNum}]]</a>
<a class="page-link" th:href="@{/auction(page=${pageNum - 1}, category=${selectedCategory})}">[[${pageNum}]]</a>
</li>

<li th:if="${products.hasNext()}" class="page-item page-arrow">
<a class="page-link" th:href="@{/auction/auction(page=${products.number + 1})}"><i class="bi bi-arrow-right"></i></a>
<a class="page-link" th:href="@{/auction(page=${products.number + 1}, category=${selectedCategory})}"><i class="bi bi-arrow-right"></i></a>
</li>
</ul>

</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/cash/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ <h5 class="widget-title">Product Overview</h5>
var paymentData = {
productId: [[${productDetail.id}]], // 상품 ID
amount: [[${productDetail.currentPrice}]], // 즉시 구매가
payTime: new Date().toISOString() // 현재 시간을 ISO 8601 형식으로 설정
payTime: new Date()
};

$.ajax({
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/cash/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h5 class="widget-title">Product Overview</h5>
var paymentData = {
productId: [[${productDetail.id}]], // 상품 ID
amount: [[${productDetail.currentPrice}]], // 현재가
payTime: new Date().toISOString() // 현재 시간을 ISO 8601 형식으로 설정
payTime: new Date()
};

$.ajax({
Expand Down
Loading