Skip to content

Commit

Permalink
feat : admin blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
ecsimsw committed Aug 17, 2023
1 parent 2896a3c commit 027e080
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 198 deletions.
4 changes: 2 additions & 2 deletions src/main/java/se/ton/t210/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public AdminController(AdminService adminService) {
}

@GetMapping("/api/admin/users/access")
public ResponseEntity<List<AccessDateTimeResponse>> usersMember(Pageable pageable, AccessDateTimeFilter filter) {
final List<AccessDateTimeResponse> responses = adminService.findAll(pageable, filter);
public ResponseEntity<List<AccessDateTimeResponse>> usersMember() {
final List<AccessDateTimeResponse> responses = adminService.findAll();
return ResponseEntity.ok(responses);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/se/ton/t210/controller/PageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PageController {

@GetMapping("/admin")
public String admin() {
return "redirect:/html/admin.html";
return "redirect:/html/admin-access.html";
}

@GetMapping("/html/application-information")
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/se/ton/t210/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ public class Member {
@Id
private Long id;

@Convert(converter = SymmetricEncryptionConverter.class)
@NotNull
private String name;

@Convert(converter = SymmetricEncryptionConverter.class)
@Email
@NotNull
private String email;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/se/ton/t210/dto/AccessDateTimeResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
public class AccessDateTimeResponse {

private final LocalDateTime dateTime;
private final Long memberId;
private final String memberName;
private final String memberEmail;
private final String memberEncryptedPassword;

public AccessDateTimeResponse(LocalDateTime dateTime, String memberName, String memberEmail, String memberEncryptedPassword) {
public AccessDateTimeResponse(LocalDateTime dateTime, Long memberId, String memberName, String memberEmail, String memberEncryptedPassword) {
this.dateTime = dateTime;
this.memberId = memberId;
this.memberName = memberName;
this.memberEmail = memberEmail;
this.memberEncryptedPassword = memberEncryptedPassword;
Expand All @@ -24,6 +26,7 @@ public AccessDateTimeResponse(LocalDateTime dateTime, String memberName, String
public static AccessDateTimeResponse of(AccessDateTime it, Member member) {
return new AccessDateTimeResponse(
it.getAccessTime(),
member.getId(),
member.getName(),
member.getEmail(),
member.getPassword()
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/se/ton/t210/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ public AdminService(MemberRepository memberRepository, AccessDataTimeRepository
}

@Transactional
public List<AccessDateTimeResponse> findAll(Pageable pageable, AccessDateTimeFilter filter) {
final LocalDateTime dateTimeFrom = filter.getDateFrom().orElse(LocalDate.MIN)
.atTime(0, 0, 0);
final LocalDateTime dateTimeTo = filter.getDateTo().orElse(LocalDate.MAX)
.atTime(23, 59, 59);
return accessDataTimeRepository.findAllByAccessTimeBetween(dateTimeTo, dateTimeFrom)
public List<AccessDateTimeResponse> findAll() {
return accessDataTimeRepository.findAll()
.stream()
.map(it -> {
final Member member = memberRepository.findById(it.getMemberId()).orElseThrow();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/static/html/admin-access.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ <h1>Access users</h1>
</br>
</div>
<script src="../js/admin-access.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
Expand Down
40 changes: 21 additions & 19 deletions src/main/resources/static/js/admin-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,16 @@ let currentPage = 1;
let users = []
let hiPage =1

function blockButtonEventHandler(productId) {
const orderUrl = currentDomain + "/api/admin/users"
const data = {
productId: productId,
userId: 1,
quantity: 1
}
axios({
method: "post",
url: currentDomain + orderUrl,
params: data
}).then(() => {
window.location.reload();
}).catch(function () {
if (confirm("Error")) {
window.location.reload();
function blockButtonEventHandler(memberId) {
const orderUrl = currentDomain + "/api/admin/block/users?memberId="+memberId
const response = fetch(orderUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
}
})
});
sAlert("부정사용자 등록")

}

userNameInput.addEventListener("keydown", function(event) {
Expand Down Expand Up @@ -99,10 +91,11 @@ async function displayUsers() {
row.id = `user-${user.id}`;
row.innerHTML = `
<td>${user.dateTime}</td>
<td>${user.memberId}</td>
<td>${user.memberName}</td>
<td>${user.memberEmail}</td>
<td>${user.memberEncryptedPassword}</td>
<td><button onclick="blockButtonEventHandler(${user.id})">Block</button></td>`;
<td><button onclick="blockButtonEventHandler(${user.memberId})">Block</button></td>`;
tableBody.appendChild(row);
}
}
Expand Down Expand Up @@ -172,4 +165,13 @@ async function updatePagination() {

// Initial fetch and display of products
fetchAndDisplayUsers();
updatePagination()
updatePagination()

// sAlert('custom alert example!');
function noError_sAlert(txt, title = 'Success',) {
Swal.fire({
title: title,
text: txt,
confirmButtonText: '닫기'
});
}
Loading

0 comments on commit 027e080

Please sign in to comment.