Notice
Recent Posts
Recent Comments
Link
반응형
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 리액트세팅
- 구글 oauth
- 자바스크립트
- java
- springboot
- HTML
- 자바스크립트기초
- 자바스크립트 기초
- 자바
- 마이바티스
- react
- Javascript
- 구글캘린더api
- mybatis
- 기초 코딩
- 웹
- 기초코딩
- 스프링부트
- 코딩
- 처음만나는자바스크립트
- spring
- 웹앱
- js
- Spring Boot
- 자바스크립트기초문법
- javaspring
- 전자정부 서버세팅
- 리액트프로젝트세팅
- CSS
- 리액트초기세팅
Archives
- Today
- Total
인생 디벨로퍼
[2단계] Admin Court 삭제 본문
728x90
반응형
삭제 기능은, db delete 가 아닌, status 관리로 비활성화 시키기로 함!
Controller
@PostMapping("/admin/court/delete")
public ResponseEntity<Object> courtDelete(@RequestParam("courtId") Long courtId) {
boolean delete = stadiumCourtService.courtDelete(courtId);
if (delete) {
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@GetMapping("/admin/court/inactive")
public String court_inactive(String keyword,
@PageableDefault(page = 0, size = 5, sort = "id", direction = Sort.Direction.ASC) Pageable pageable,
Model model) {
Page<StadiumCourt> courts;
if (keyword != null && !keyword.isEmpty()) {
courts = stadiumCourtService.getCourtListByTitleContaining(keyword, pageable);
} else {
courts = stadiumCourtService.getStadiumCourtDeleteList(pageable);
}
int nowPage = courts.getPageable().getPageNumber() + 1;
int startPage = ((nowPage - 1) / 5) * 5 + 1; // 버튼에서 첫 숫자
int endPage = Math.min(nowPage + 5, courts.getTotalPages()); // 버튼에서 마지막 숫자
model.addAttribute("courtList", courts.getContent());
model.addAttribute("nowPage", nowPage);
model.addAttribute("startPage", startPage);
model.addAttribute("endPage", endPage);
model.addAttribute("totalPage", courts.getTotalPages());
model.addAttribute("keyword", keyword);
return "/admin_court/inactive";
}
status 변경과, 비활성화 페이지를 위한 GetMapping controller 도 만들어 줬다.
앞의 포스팅과 동일.
Service
@Transactional
public boolean courtDelete(Long courtId) {
Optional<StadiumCourt> StadiumCourt = stadiumCourtRepository.findById(courtId);
if (StadiumCourt.isPresent()) {
StadiumCourt stadiumCourt = StadiumCourt.get();
stadiumCourt.setStatus(StadiumCourtStatus.비활성);
stadiumCourtRepository.save(stadiumCourt);
return true;
} else {
return false;
}
}
public Page<StadiumCourt> getStadiumCourtDeleteList(Pageable pageable) {
StadiumCourt stadiumCourt = new StadiumCourt();
stadiumCourt.setStatus(StadiumCourtStatus.비활성);
Example<StadiumCourt> example = Example.of(stadiumCourt);
return stadiumCourtRepository.findAll(example, pageable);
}
삭제 된 코트는 status 가 '비활성' 을 save (update) 한다.
Repository
public Page<StadiumCourt> getCourtListByTitleContaining(String title, Pageable pageable) {
return stadiumCourtRepository.findByTitleContaining(title, pageable);
}
public Page<StadiumCourt> getStadiumCourtDeleteList(Pageable pageable) {
StadiumCourt stadiumCourt = new StadiumCourt();
stadiumCourt.setStatus(StadiumCourtStatus.비활성);
Example<StadiumCourt> example = Example.of(stadiumCourt);
return stadiumCourtRepository.findAll(example, pageable);
}
View
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../layout/header.jsp" %>
<div style="position :relative; height: 700px;">
<div class="d-flex" style="position: absolute; left: 2px">
<div class="container my-3">
<div class="list-group">
<a href="/admin/court" class="list-group-item list-group-item-action">
코트
</a>
<a href="/admin/court/wait" class="list-group-item list-group-item-action">승인대기</a>
<a href="/admin/court/inactive" class="list-group-item list-group-item-action active" aria-current="true">비활성화</a>
</div>
</div>
<div class="vl">
</div>
</div>
<div class="d-flex justify-content-center">
<div style="position: relative; top: 50px">
<table class="table">
<tr class="my-text-align">
<th scope="col" class="text-center">번호</th>
<th scope="col" class="text-center">코트이름</th>
<th scope="col" class="text-center">코트가격</th>
<th scope="col" class="text-center">수용 인원</th>
<th scope="col" class="text-center">등록 일자</th>
<th scope="col" class="text-center"></th>
</tr>
<c:forEach items="${courtList}" var="courtList">
<tr class="my-text-align">
<td class="text-center">${courtList.id}</td>
<td>${courtList.title}</td>
<td>${courtList.courtPrice}</td>
<td>${courtList.capacity}</td>
<td class="text-center">${MyDateUtils.toStringFormat(courtList.createdAt)}</td>
</tr>
</c:forEach>
</table>
<div class="d-flex justify-content-center mb-3">
<ul class="pagination">
<li class='page-item ${nowPage == 1 ? "disabled" : ""}'><a class="page-link"
href="javascript:void(0);" onclick="callPrev();">Prev</a></li>
<c:forEach var="num" begin="${startPage}" end="${endPage}">
<li class="page-item ${num == nowPage ? 'active' : ''}">
<a class="page-link" href="/admin/court?page=${num-1}&keyword=${keyword}">${num}</a>
</li>
</c:forEach>
<li class='page-item ${nowPage == totalPage ? "disabled" : ""}'><a class="page-link"
href="javascript:void(0);" onclick="callNext();">Next</a></li>
</ul>
</div>
<div class="input-group justify-content-center" style="position: absolute; bottom: 30;">
<div class="col-6">
<input id="keyword" name="query" type="text" class="form-control" placeholder="검색어 입력"
aria-label="search" value="" aria-describedby="button-addon2">
</div>
<div class="col-auto">
<button id="button-addon2" class="btn btn-primary" type="submit"
onclick="searchGet()">검색</button>
</div>
</div>
</div>
</div>
</div>
</div>
<%@ include file="../layout/footer.jsp" %>
결과
여기서 삭제 버튼을 누르면,
비활성화 되서 여기 넘어온다!
728x90
반응형
'Project > Final Project - Sporting (매칭)' 카테고리의 다른 글
Sporting App 정리 (0) | 2023.07.02 |
---|---|
[2단계] Compony Info Update (S3) (0) | 2023.05.01 |
[2단계] Admin court 등록 승인 (0) | 2023.05.01 |
[2단계] Admin page Court view (0) | 2023.05.01 |
[1단계] Stadium Detail (0) | 2023.05.01 |