화면






Mustache
<!-- 구매자 신고하기 -->
<button type="button" class="btn btn-custom btn-sm"
onclick="reportBuyer({{id}})"
data-bs-toggle="modal"
data-bs-target="#myModal">
구매자신고
</button>
<!-- 신고하기 모달창 -->
<div class="modal" id="myModal">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content" style="padding: 20px">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">신고하기</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<!-- Modal body -->
<input type="text" class="modal-body" id="reportContent" name="reportContent"
placeholder="신고내용을 작성해주세요." style="resize: none;" required>
<!-- 숨겨진 필드에 buyerId 설정 -->
<input type="hidden" id="reportBuyerId" name="buyerId">
<!-- Modal footer -->
<div class="modal-footer" style="margin-top: 30px">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">취소</button>
<button type="submit" class="btn btn-danger" data-bs-dismiss="modal" onclick="report_buyer()">신고하기</button>
</div>
</div>
</div>
</div>
<!-- 판매자 신고하기 -->
<button type="button" class="btn btn-custom btn-sm"
onclick="reportSeller({{id}})"
data-bs-toggle="modal"
data-bs-target="#myModal">
판매자 신고
</button>
<!-- 신고하기 모달창 -->
<div class="modal" id="myModal">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content" style="padding: 20px">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">신고하기</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<!-- Modal body -->
<input type="text" class="modal-body" id="reportContent" name="reportContent"
placeholder="신고내용을 작성해주세요." style="resize: none;" required>
<!-- 숨겨진 필드에 sellerId 설정 -->
<input type="hidden" id="reportSellerId" name="sellerId">
<!-- Modal footer -->
<div class="modal-footer" style="margin-top: 30px">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">취소</button>
<button type="submit" class="btn btn-danger" data-bs-dismiss="modal" onclick="report_seller()">신고하기</button>
</div>
</div>
</div>
</div>
JavaScript
let transaction_id=""
// 구매자 신고를 위한 모달창에 해당 물품 구매자의 buyerId값 넣기
function reportBuyer(transactionId){
transaction_id = transactionId;
}
// 신고하기
async function report_buyer() {
let reportContent = document.getElementById('reportContent').value;
console.log(transaction_id);
console.log(reportContent);
let url = `/api/v1/report`;
let response = await fetch(url, {
method: 'Post',
headers: {
'Content-Type': 'application/json',
},
body : JSON.stringify({
transactionId: transaction_id,
reason : reportContent
})
})
let responseData = await response.json();
if (!responseData.success) {
alert(responseData.msg);
}else{
window.location.href =`/s/mypage-complete-auction`;
}
}
let transaction_id=""
// 판매자 신고를 위한 모달창에 해당 물품 구매자의 buyerId값 넣기
function reportSeller(transactionId){
transaction_id = transactionId;
}
// 신고하기
async function report_seller() {
let reportContent = document.getElementById('reportContent').value;
console.log(transaction_id);
console.log(reportContent);
let url = `/api/v1/report`;
let response = await fetch(url, {
method: 'Post',
headers: {
'Content-Type': 'application/json',
},
body : JSON.stringify({
transactionId: transaction_id,
reason : reportContent
})
})
let responseData = await response.json();
if (!responseData.success) {
alert(responseData.msg);
}else {
window.location.href =`/s/mypage-participated-auction`;
}
}
function changePage(pageNumber) {
window.location.href = `/s/mypage-participated-auction?page=${pageNumber}`;
}
Controller
// 판매자, 구매자 신고하기
@PostMapping("/api/v1/report")
@ResponseBody
public ResponseEntity<?> reportBuyer(@AuthenticationPrincipal User user, @RequestBody ReportRequest.ReportSaveDTO reportSaveDTO) {
reportService.save(user.getId(),reportSaveDTO);
CommonResp resp = new CommonResp(true, "신고 성공", null);
return new ResponseEntity<>(resp, HttpStatus.OK);
}
Service
// 신고하기
@Transactional
public void save(Integer userId, ReportRequest.ReportSaveDTO reportSaveDTO) {
Optional<Transaction> transaction = transactionRepository.findById(reportSaveDTO.getTransactionId());
if(transaction.isPresent()) {
if(transaction.get().getBuyer().getId().equals(userId)){
Report report = Report.builder().
reporter(transaction.get().getBuyer()).
reported(transaction.get().getSeller()).
reason(reportSaveDTO.getReason()).
transaction(transaction.get()).
status(0).
build();
reportRepository.save(report);
}else if(transaction.get().getSeller().getId().equals(userId)){
Report report = Report.builder().
reporter(transaction.get().getSeller()).
reported(transaction.get().getBuyer()).
reason(reportSaveDTO.getReason()).
transaction(transaction.get()).
status(0).
build();
reportRepository.save(report);
}else{
throw new Exception400("자신이 등록한 물품 혹은 낙찰된 물품이 아닙니다.");
}
}
transaction.get().statusReport(3);
}
Repository
// 낙찰 물품 조회
public Optional<Transaction> findById(Integer id) {
return Optional.ofNullable(em.find(Transaction.class, id));
}
// 신고 하기(등록)
public void save(Report report) {
em.persist(report);
}
해설
신고자의 유저정보와 낙찰 물품 정보, 신고사유를 받아
낙찰된 물품을 조회
낙찰된 물품의 판매자 id와 구매자id를 확인하여 유저 정보를 비교
판매자 id와 구매자 id 가 유저 id와 같지 않다면 throw
판매자 id와 같다면 판매자 id를 신고자로 간주, 구매자를 피신고자로하여 report 테이블에 등록
구매자 id와 같다면 구매자 id를 신고자로 간주, 판매자를 피신고자로하여 report 테이블에 등록
낙찰 테이블의 상태정보를 신고된 상태로 변경
Share article