-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ClothingStoreService/feature/member-finda…
…ll-paging Feature/member findall paging
- Loading branch information
Showing
12 changed files
with
329 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/store/clothstar/member/repository/MemberJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
package org.store.clothstar.member.repository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.store.clothstar.member.entity.MemberEntity; | ||
|
||
import java.util.Optional; | ||
|
||
public interface MemberJpaRepository extends JpaRepository<MemberEntity, Long>, MemberRepository { | ||
Optional<MemberEntity> findByEmail(String email); | ||
|
||
@Query(value = "select m from member m where m.deletedAt is null order by m.createdAt desc", | ||
countQuery = "select count(m) from member m") | ||
Page<MemberEntity> findAllOffsetPaging(Pageable pageable); | ||
|
||
@Query(value = "select m from member m where m.deletedAt is null order by m.createdAt desc", | ||
countQuery = "select count(m) from member m") | ||
Slice<MemberEntity> findAllSlicePaging(Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
src/main/java/org/store/clothstar/member/service/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Members List</title> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | ||
<style> | ||
.pagination { | ||
justify-content: center; | ||
margin-top: 20px; | ||
} | ||
|
||
.pagination .page-item.active .page-link { | ||
z-index: 3; | ||
color: #fff; | ||
background-color: #007bff; | ||
border-color: #007bff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Members List</h1> | ||
<table class="table"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Created At</th> | ||
</tr> | ||
</thead> | ||
<tbody id="members-table-body"> | ||
<!-- JavaScript로 데이터 로드 --> | ||
</tbody> | ||
</table> | ||
<nav aria-label="Page navigation"> | ||
<ul class="pagination justify-content-center" id="pagination-links"> | ||
<!-- 페이징 버튼이 여기에 추가됩니다. --> | ||
</ul> | ||
</nav> | ||
</div> | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
loadMembers(); | ||
}); | ||
|
||
function loadMembers(page = 0) { | ||
const url = `/v1/members?page=${page}`; | ||
const accessToken = localStorage.getItem("ACCESS_TOKEN"); | ||
let headersObj = new Object(); | ||
headersObj["Content-Type"] = "application/json"; | ||
|
||
if (accessToken) { | ||
headersObj["Authorization"] = accessToken; | ||
} | ||
|
||
fetch(url, { | ||
method: "GET", | ||
headers: headersObj, | ||
}).then(response => response.json()) | ||
.then(data => { | ||
const tableBody = document.getElementById('members-table-body'); | ||
tableBody.innerHTML = ''; // 기존 내용을 지웁니다. | ||
data.content.forEach(member => { | ||
const row = ` | ||
<tr> | ||
<td>${member.memberId}</td> | ||
<td>${member.name}</td> | ||
<td>${member.createdAt}</td> | ||
</tr> | ||
`; | ||
tableBody.innerHTML += row; | ||
}); | ||
|
||
// 페이징 링크 업데이트 | ||
updatePagination(data); | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching member data:', error); | ||
}); | ||
} | ||
|
||
function updatePagination(data) { | ||
const paginationElement = document.getElementById('pagination-links'); | ||
paginationElement.innerHTML = ''; | ||
|
||
const totalPages = data.totalPages; | ||
const currentPage = data.number; | ||
|
||
const pagesToShow = 10; // 한 번에 보일 페이지 수 | ||
|
||
// 시작 페이지와 끝 페이지 계산 | ||
let startPage = Math.max(0, currentPage - Math.floor(pagesToShow / 2)); | ||
let endPage = Math.min(totalPages - 1, startPage + pagesToShow - 1); | ||
|
||
if (endPage - startPage + 1 < pagesToShow) { | ||
startPage = Math.max(0, endPage - pagesToShow + 1); | ||
} | ||
|
||
if (startPage > 0) { | ||
addPaginationLink('Previous', currentPage - 1); | ||
} | ||
|
||
for (let i = startPage; i <= endPage; i++) { | ||
addPaginationLink(i + 1, i, currentPage); | ||
} | ||
|
||
if (endPage < totalPages - 1) { | ||
addPaginationLink('Next', currentPage + 1); | ||
} | ||
} | ||
|
||
function addPaginationLink(text, page, currentPage) { | ||
const paginationElement = document.getElementById('pagination-links'); | ||
const li = document.createElement('li'); | ||
li.classList.add('page-item'); | ||
if (page === currentPage) { | ||
li.classList.add('active'); | ||
} | ||
const pageLink = document.createElement('a'); | ||
pageLink.classList.add('page-link'); | ||
pageLink.href = '#'; | ||
pageLink.textContent = text; | ||
pageLink.addEventListener('click', function (event) { | ||
event.preventDefault(); | ||
loadMembers(page); | ||
}); | ||
li.appendChild(pageLink); | ||
paginationElement.appendChild(li); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.