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

Feat/63 merge #69

Merged
merged 5 commits into from
Sep 26, 2023
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
@@ -0,0 +1,42 @@
package picasso.server.api.auction.controller;

import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import picasso.server.api.auction.service.PictureBidHistoryService;
import picasso.server.common.exception.NotLoginUserRestException;
import picasso.server.domain.domains.picture.items.PictureStatus;
import picasso.server.domain.domains.user.entity.User;

@Slf4j
@Controller
@RequestMapping("/bid-history")
@RequiredArgsConstructor
public class PictureBidHistoryController {

private final PictureBidHistoryService pictureBidHistoryService;

@GetMapping("/myBidList")
public String retrieveBidHistoryList(Model model, HttpSession session) {
User user = (User) session.getAttribute("loginUser");
if (user == null) {
throw NotLoginUserRestException.EXCEPTION;
}
model.addAttribute("bidList", pictureBidHistoryService.retrieveMyBidHistoryList(user));
return "bidhistory/mybid";
}

@GetMapping("/myPictureList")
public String retrieveMyPictureHistoryList(Model model, HttpSession session) {
User user = (User) session.getAttribute("loginUser");
if (user == null) {
throw NotLoginUserRestException.EXCEPTION;
}
model.addAttribute("pictureList", pictureBidHistoryService.retrieveMyPictureList(user, PictureStatus.BIDDING));
return "bidhistory/myPictureList";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import picasso.server.api.auction.dto.request.PictureBiddingValidRequestDto;
import picasso.server.api.auction.service.PictureBidHistoryService;
import picasso.server.common.exception.NotLoginUserRestException;
import picasso.server.domain.domains.picture.items.PictureBidHistory;
import picasso.server.domain.domains.user.entity.User;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import picasso.server.common.exception.NotLoginUserRestException;
import picasso.server.domain.domains.picture.items.Picture;
import picasso.server.domain.domains.picture.items.PictureBidHistory;
import picasso.server.domain.domains.picture.items.PictureStatus;
import picasso.server.domain.domains.picture.repository.PictureBidHistoryRepository;
import picasso.server.domain.domains.picture.repository.PictureRepository;
import picasso.server.domain.domains.user.entity.User;
Expand Down Expand Up @@ -71,4 +72,12 @@ private boolean isAbleBiddingPictureByUser(User user, Picture picture, PictureBi
// 사용자가 최종 입찰자가 아니거나 또는
return !topHistory.getUser().equals(user) && amount <= topHistory.getBidAmount() + picture.getIncrementAmount();
}

public List<PictureBidHistory> retrieveMyBidHistoryList(User user) {
return pictureBidHistoryRepository.findAllByUserOrderByCreatedAt(user);
}

public List<Picture> retrieveMyPictureList(User user, PictureStatus pictureStatus) {
return pictureRepository.findAllByPictureStatusAndUser(pictureStatus, user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.NotFound;
import org.springframework.stereotype.Controller;
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.ResponseBody;
import picasso.server.api.user.service.UserService;
import picasso.server.api.user.vo.request.LoginRequestDto;
import picasso.server.api.user.vo.request.SignUpRequestDto;
import picasso.server.common.exception.NotFoundException;
import picasso.server.common.exception.UserNotFoundException;
import picasso.server.domain.domains.user.entity.User;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Slf4j
Expand Down Expand Up @@ -77,4 +83,16 @@ public String signUp(SignUpRequestDto requestDto, HttpSession session) {
private void setSessionLoginUser(HttpSession session, User user) {
session.setAttribute("loginUser", user);
}

@ResponseBody
@PostMapping("/session-info")
public Map<String, Long> paymentSessionInfoRtn(HttpSession session) {
User temp = (User)session.getAttribute("loginUser");
Long userId = userService.findUserById(temp.getId()).orElseThrow(
() -> UserNotFoundException.EXCEPTION
).getId();
return new HashMap<String, Long>(){{
put("userId", userId);
}};
}
}
2 changes: 1 addition & 1 deletion Api/src/main/resources/static/css/fail.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
height: 700px;
flex-direction: column;
justify-content: space-evenly;
background: #0d6efd;
background: #ff0000;
}

#popup-header {
Expand Down
Empty file.
1 change: 0 additions & 1 deletion Api/src/main/resources/static/js/bidModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function inputPrice(e){
priceAmount.textContent = "입찰 금액 : " + bidNum + "원";
}


var amount = document.getElementById('inputPrice');
var userId;
var bidResult = obj => {
Expand Down
41 changes: 41 additions & 0 deletions Api/src/main/resources/templates/bidhistory/myPictureList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html
lang="ko"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}"
>
<main layout:fragment="content">
<link rel="stylesheet" type="text/css" href="/static/css/mybid.css" />
<div class="container">
<h2>내 경매 목록</h2>
<p>내가 올린 경매 내역을 확인할 수 있습니다.</p>
<table class="table">
<thead>
<tr>
<th>입찰번호</th>
<th>그림 이름</th>
<th>입찰가</th>
<th>입찰 일시</th>
</tr>
</thead>
<tbody>
<tr th:each="picture : ${pictureList}">
<td th:text="${picture.getId()}"></td>
<td th:text="${picture.getPicture().getPictureName()}">
<a th:href="'/pictures/' + ${picture.getPicture().getPictureId()}"></a>
</td>
<td th:text="${picture.getBidAmount()}"></td>
<td th:text="${picture.getCreatedAt()}"></td>
</tr>
</tbody>
</table>
</div>
</main>

<th:block layout:fragment="script">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</th:block>
</html>
41 changes: 41 additions & 0 deletions Api/src/main/resources/templates/bidhistory/mybid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html
lang="ko"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}"
>
<main layout:fragment="content">
<link rel="stylesheet" type="text/css" href="/static/css/mybid.css" />
<div class="container">
<h2>내 입찰 목록</h2>
<p>나의 입찰 내역을 확인할 수 있습니다.</p>
<table class="table">
<thead>
<tr>
<th>입찰번호</th>
<th>그림 이름</th>
<th>입찰가</th>
<th>입찰 일시</th>
</tr>
</thead>
<tbody>
<tr th:each="bid : ${bidList}">
<td th:text="${bid.getId()}"></td>
<td th:text="${bid.getPicture().getPictureName()}">
<a th:href="'/pictures/' + ${bid.getPicture().getPictureId()}"></a>
</td>
<td th:text="${bid.getBidAmount()}"></td>
<td th:text="${bid.getCreatedAt()}"></td>
</tr>
</tbody>
</table>
</div>
</main>

<th:block layout:fragment="script">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</th:block>
</html>
4 changes: 2 additions & 2 deletions Api/src/main/resources/templates/fragment/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<a class="link-info link-offset-1 link-underline-opacity-0 " href="/user/mypage" th:text="${session.loginUser.nickName}"></a>
</b> 님
</div>
<small><a href="#" class="link-primary link-offset-2 link-underline-opacity-0 link-underline-opacity-100-hover" th:text="${session.loginUser.point}"></a> P</small>
<small><a onclick="requestPayment(event)" class="link-primary link-offset-2 link-underline-opacity-0 link-underline-opacity-100-hover" th:text="${session.loginUser.point}"></a> P</small>
</div>
<!--로그인 사용자가 존재하고, Profile이 없는 경우-->
<div class="col">
Expand All @@ -49,14 +49,14 @@
th:if="${session.loginUser.profile == null}">
<path d="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"/>
</svg>
<img th:if="${session.loginUser.profile != null}"
<img th:if="${session.loginUser.profile != null}"
th:src="'http://xgrnsxldyejc19608959.cdn.ntruss.com' + ${session.loginUser.profile} + '?type=f&w=80&h=80&quality=90&align=4&faceopt=false'"
alt="User Profile"/>
</div>
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/user/mypage">마이 페이지</a></li>
<li><a class="dropdown-item" href="/bid-history/myPictureList">내가 등록한 경매</a></li>
<li><a class="dropdown-item" onclick="requestPayment(event)">포인트 환전</a></li>
<th:block th:if="${session.loginUser.userRole.name() == 'ADMIN'}">
<li><hr class="dropdown-divider"></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>
<main layout:fragment="content">
<link rel="stylesheet" type="text/css" href="/static/css/detail.css"/>

<div class="container body" style="margin-top: 100px;">
<div th:if="${picture}" class="picture-details">
<input type="hidden" name="pictureId" id="pictureId" th:value="${picture.pictureId}" />
Expand Down
10 changes: 3 additions & 7 deletions Api/src/main/resources/templates/user/mypage.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ <h1>마이페이지</h1>
<hr>
<div class="row">
<div class="col">
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">Point 충전</button>
</div>
<div class="col">
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">낙찰횟수</button>
</div>
<div class="col">
<button type="button" class="btn btn-primary btn-lg" style="width:100%;">내 경매</button>
<button onclick="location.href='/bid-history/myBidList'" type="button" class="btn btn-primary btn-lg" style="width:100%;">내 입찰 내역</button>
<br/>
<button onclick="location.href='/bid-history/myPictureList'" type="button" class="btn btn-primary btn-lg" style="width:100%;">내가 등록한 경매 내역</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import picasso.server.common.dto.ErrorDetail;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
Expand All @@ -28,6 +29,7 @@ public enum GlobalException implements BaseErrorCode {
PICTURE_STATUS_AFTER_APPROVE(INTERNAL_SERVER_ERROR.value(), "이미 관리자가 승인한 게시물 입니다."),
NOT_LOGIN_EXCEPTION(UNAUTHORIZED.value(), "로그인이 필요합니다."),
NEED_LOGIN_ERROR(UNAUTHORIZED.value(), "로그인이 필요한 기능입니다."),
USER_NOT_FOUND_ERROR(NOT_FOUND.value(), "유저를 찾을 수 없습니다.")
;

private final Integer statusCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package picasso.server.common.exception;

import static picasso.server.common.exception.GlobalException.NOT_FOUND_ERROR;

public class UserNotFoundException extends BaseException {
public static final BaseException EXCEPTION = new UserNotFoundException();

private UserNotFoundException() {
super(NOT_FOUND_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public interface PictureBidHistoryRepository extends JpaRepository<PictureBidHis
List<PictureBidHistory> findByUserOrderByCreatedAtDesc(User user);

List<PictureBidHistory> findByPictureOrderByBidAmountDesc(Picture picture);

List<PictureBidHistory> findAllByUserOrderByCreatedAt(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Repository;
import picasso.server.domain.domains.picture.items.Picture;
import picasso.server.domain.domains.picture.items.PictureStatus;
import picasso.server.domain.domains.user.entity.User;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -25,5 +26,6 @@ public interface PictureRepository extends JpaRepository<Picture, Long>{
Page<Picture> findAllByPictureStatusOrderByBidStartDateAsc(PictureStatus status, Pageable pageable);

Optional<Picture> findByPictureIdAndPictureStatus(Long id, PictureStatus status);


List<Picture> findAllByPictureStatusAndUser(PictureStatus status, User user);
}
Loading