Skip to content

Commit

Permalink
docs: #100 회원 등급 정책 view 초안
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrationn committed May 17, 2024
1 parent 5a90f66 commit dca6a5c
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.t3t.frontserver.member.client.MemberGradePolicyApiClient;
import com.t3t.frontserver.member.exception.MemberGradePolicyApiClientException;
import com.t3t.frontserver.member.model.dto.MemberGradePolicyDto;
import com.t3t.frontserver.member.model.request.MemberGradePolicyCreationRequest;
import com.t3t.frontserver.member.model.response.MemberGradePolicyResponse;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
Expand All @@ -19,7 +19,7 @@
public class MemberGradePolicyAdaptor {
private final MemberGradePolicyApiClient memberGradePolicyApiClient;

public List<MemberGradePolicyDto> getMemberGradePolicyList() {
public List<MemberGradePolicyResponse> getMemberGradePolicyList() {
try {
return Optional.ofNullable(memberGradePolicyApiClient.getMemberGradePolicyList().getBody())
.map(BaseResponse::getData)
Expand All @@ -29,7 +29,7 @@ public List<MemberGradePolicyDto> getMemberGradePolicyList() {
}
}

public MemberGradePolicyDto getMemberGradePolicy(Long policyId) {
public MemberGradePolicyResponse getMemberGradePolicy(Long policyId) {
try {
return Optional.ofNullable(memberGradePolicyApiClient.getMemberGradePolicy(policyId).getBody())
.map(BaseResponse::getData)
Expand All @@ -39,7 +39,7 @@ public MemberGradePolicyDto getMemberGradePolicy(Long policyId) {
}
}

public MemberGradePolicyDto createMemberGradePolicy(MemberGradePolicyCreationRequest request) {
public MemberGradePolicyResponse createMemberGradePolicy(MemberGradePolicyCreationRequest request) {
try {
return Optional.ofNullable(memberGradePolicyApiClient.createMemberGradePolicy(request).getBody())
.map(BaseResponse::getData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.t3t.frontserver.member.model.dto.MemberGradePolicyDto;
import com.t3t.frontserver.member.model.request.MemberGradePolicyCreationRequest;
import com.t3t.frontserver.member.model.response.MemberGradePolicyResponse;
import com.t3t.frontserver.model.response.BaseResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,20 +15,20 @@
public interface MemberGradePolicyApiClient {

@GetMapping("/at/bookstore/admin/member-grade-policies")
ResponseEntity<BaseResponse<List<MemberGradePolicyDto>>> getMemberGradePolicyList();
ResponseEntity<BaseResponse<List<MemberGradePolicyResponse>>> getMemberGradePolicyList();

@GetMapping("/admin/bookstore/member-grade-policies/{policyId}")
ResponseEntity<BaseResponse<MemberGradePolicyDto>> getMemberGradePolicy(@PathVariable("policyId") Long policyId);
@GetMapping("/at/bookstore/admin/member-grade-policies/{policyId}")
ResponseEntity<BaseResponse<MemberGradePolicyResponse>> getMemberGradePolicy(@PathVariable("policyId") Long policyId);

@PostMapping("/admin/bookstore/member-grade-policy")
ResponseEntity<BaseResponse<MemberGradePolicyDto>> createMemberGradePolicy(@RequestBody MemberGradePolicyCreationRequest request);
@PostMapping("/at/bookstore/admin/member-grade-policy")
ResponseEntity<BaseResponse<MemberGradePolicyResponse>> createMemberGradePolicy(@RequestBody MemberGradePolicyCreationRequest request);

@PutMapping("/admin/bookstore/member-grade-policy/{policyId}/default")
ResponseEntity<BaseResponse<MemberGradePolicyDto>> updateMemberGradePolicy(@PathVariable("policyId") Long policyId,
@PutMapping("/at/bookstore/admin/member-grade-policy/{policyId}/default")
ResponseEntity<BaseResponse<Void>> updateMemberGradePolicy(@PathVariable("policyId") Long policyId,
@RequestParam("startAmount") BigDecimal startAmount,
@RequestParam("endAmount") BigDecimal endAmount,
@RequestParam("rate") int rate);

@DeleteMapping("/admin/bookstore/member-grade-policy/{policyId}")
@DeleteMapping("/at/bookstore/admin/member-grade-policy/{policyId}")
ResponseEntity<BaseResponse<Void>> deleteMemberGradePolicy(@PathVariable("policyId") Long policyId);
}
Original file line number Diff line number Diff line change
@@ -1,68 +1,40 @@
package com.t3t.frontserver.member.controller;

import com.t3t.frontserver.member.client.MemberGradePolicyApiClient;
import com.t3t.frontserver.member.model.dto.MemberGradePolicyDto;
import com.t3t.frontserver.member.model.request.MemberGradePolicyCreationRequest;
import com.t3t.frontserver.member.model.request.MemberGradePolicyUpdateRequest;
import com.t3t.frontserver.member.model.response.MemberGradePolicyResponse;
import com.t3t.frontserver.member.service.MemberGradePolicyService;
import com.t3t.frontserver.model.response.BaseResponse;
import feign.FeignException;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

@Slf4j
@Controller
@RequiredArgsConstructor
public class MemberGradePolicyController {
private final MemberGradePolicyService memberGradePolicyService;
private final MemberGradePolicyApiClient memberGradePolicyApiClient;

@GetMapping("/admin/member-grade-policies")
public String getMemberGradePolicyList(Model model) {
/*ResponseEntity<BaseResponse<List<MemberGradePolicyDto>>> memberGradePolicyList
= memberGradePolicyApiClient.getMemberGradePolicyList();
// List<MemberGradePolicyDto> memberGradePolicyList = memberGradePolicyService.getMemberGradePolicyList();
model.addAttribute("memberGradePolicyList", memberGradePolicyList);
*/



try {
ResponseEntity<BaseResponse<List<MemberGradePolicyDto>>> response = memberGradePolicyApiClient.getMemberGradePolicyList();
if (response.getStatusCode() == HttpStatus.OK) {
List<MemberGradePolicyDto> memberGradePolicyDtoList = Objects.requireNonNull(response.getBody()).getData();

if (memberGradePolicyDtoList != null) {
model.addAttribute("memberGradePolicyDtoList", memberGradePolicyDtoList);
}
} else {
log.info(response.getStatusCode().toString());
}
} catch (FeignException exception) {
log.error(exception.getMessage());
model.addAttribute("errorMessage", "데이터를 가져오는데 실패했습니다.");
}


// Long memberId = SecurityContextUtils.getMemberId(). .equals(MemberRole.valueOf("ADMIN"));

List<MemberGradePolicyResponse> memberGradePolicyList = memberGradePolicyService.getMemberGradePolicyList();
model.addAttribute("memberGradePolicyList", memberGradePolicyList);

return "redirect:/main/page/memberGradePolicy";
}

@GetMapping("/admin/member-grade-policies/{policyId}")
public String getMemberGradePolicy(Model model, @PathVariable("policyId") Long policyId) {
MemberGradePolicyDto memberGradePolicyDto = memberGradePolicyService.getMemberGradePolicy(policyId);
model.addAttribute("memberGradePolicyDto", memberGradePolicyDto);
MemberGradePolicyResponse memberGradePolicy = memberGradePolicyService.getMemberGradePolicy(policyId);
model.addAttribute("memberGradePolicy", memberGradePolicy);

return "redirect:/main/page/memberGradePolicy";
}
Expand All @@ -71,7 +43,7 @@ public String getMemberGradePolicy(Model model, @PathVariable("policyId") Long p
public String createMemberGradePolicy(@Valid @ModelAttribute MemberGradePolicyCreationRequest request) {
memberGradePolicyService.createMemberGradePolicy(request);

return "redirect:/main/page/memberGradePolicy";
return "redirect:/main/page/memberGradePolicyRegister";
}

@PutMapping("/admin/member-grade-policy/{policyId}/default")
Expand All @@ -87,7 +59,8 @@ public String updateMemberGradePolicy(@PathVariable("policyId") Long policyId,
.build();

memberGradePolicyService.updateMemberGradePolicy(policyId, request.getStartAmount(), request.getEndAmount(), request.getRate());
return "redirect:/main/page/memberGradePolicy";

return "redirect:/main/page/memberGradePolicyUpdate";
}

@DeleteMapping("/admin/member-grade-policy/{policyId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.t3t.frontserver.member.model.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MemberGradePolicyResponse {
private BigDecimal startAmount;
private BigDecimal endAmount;
private int rate;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.t3t.frontserver.member.service;

import com.t3t.frontserver.member.adaptor.MemberGradePolicyAdaptor;
import com.t3t.frontserver.member.model.dto.MemberGradePolicyDto;
import com.t3t.frontserver.member.model.request.MemberGradePolicyCreationRequest;
import com.t3t.frontserver.member.model.response.MemberGradePolicyResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -14,15 +14,15 @@
public class MemberGradePolicyService {
private final MemberGradePolicyAdaptor memberGradePolicyAdaptor;

public List<MemberGradePolicyDto> getMemberGradePolicyList() {
public List<MemberGradePolicyResponse> getMemberGradePolicyList() {
return memberGradePolicyAdaptor.getMemberGradePolicyList();
}

public MemberGradePolicyDto getMemberGradePolicy(Long policyId) {
public MemberGradePolicyResponse getMemberGradePolicy(Long policyId) {
return memberGradePolicyAdaptor.getMemberGradePolicy(policyId);
}

public MemberGradePolicyDto createMemberGradePolicy(MemberGradePolicyCreationRequest request) {
public MemberGradePolicyResponse createMemberGradePolicy(MemberGradePolicyCreationRequest request) {
return memberGradePolicyAdaptor.createMemberGradePolicy(request);
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/templates/admin/fragment/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@
</li>
</ul>
</li>
<!-- 회원 등급 정책 관리 -->
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#policy-nav" data-bs-toggle="collapse" href="#">
<i class="bi bi-menu-button-wide"></i><span>회원 등급 규정 관리</span><i class="bi bi-chevron-down ms-auto"></i>
</a>
<ul id="policy-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
<li>
<a href="/admin/member-grade-policies"> <!-- TODO : URL 수정 -->
<i class="bi bi-circle"></i><span>회원 등급 조회 및 삭제</span>
</a>
</li>
<li>
<a href="/admin/member-grade-policy"> <!-- TODO : URL 수정 -->
<i class="bi bi-circle"></i><span>회원 등급 등록</span>
</a>
</li>
<li>
<a href="/admin/member-grade-policy/{policyId}/default"> <!-- TODO : URL 수정 -->
<i class="bi bi-circle"></i><span>회원 등급 수정</span>
</a>
</li>
</ul>
</li>
<!-- ex -->
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#example-nav" data-bs-toggle="collapse" href="#">
<i class="bi bi-menu-button-wide"></i><span>Example</span><i class="bi bi-chevron-down ms-auto"></i>
Expand Down
44 changes: 37 additions & 7 deletions src/main/resources/templates/main/page/memberGradePolicy.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout(categoryList)"
layout:decorate="main/layout/layout">
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="admin/layout/layout">

<th:block layout:fragment="content">
<script th:inline="javascript">
Expand All @@ -17,7 +17,7 @@
}
</script>
<div class="ml-3 mb-3">
<button type="button" class="btn btn-danger" onclick="deleteMemberGradePolicy()">삭제</button>
<button type="button" class="btn btn-danger" onclick="deleteSelectedPolicies()">삭제</button>
</div>
<div class="container">
<div class="row justify-content-center">
Expand All @@ -40,12 +40,12 @@ <h2 class="text-center mb-5">회원 등급 정책</h2>
<tbody>
<!-- Thymeleaf를 사용하여 반복문 처리 -->
<tr th:each="memberGradePolicy, no : ${memberGradePolicyList}">
<td><input type="checkbox" th:value="${memberGradePolicy.policyId}" th:id="'policyCheckbox_' + ${memberGradePolicy}" name="policyCheckbox" class="policyCheckbox"></td>
<td th:text="${memberGradePolicy}"></td>
<td><input type="checkbox" th:value="${no}" th:id="'policyCheckbox_' + ${memberGradePolicy}" name="policyCheckbox" class="policyCheckbox"></td>
<td th:text="${memberGradePolicy.grade}"></td>
<td th:text="${memberGradePolicy.startAmount}"></td>
<td th:text="${memberGradePolicy.endAmount}"></td>
<td th:switch="${memberGradePolicy.rate}"></td>
<td><button>수정</button><button>삭제</button></td>
<td><button>삭제</button></td>
</tr>
</tbody>
</table>
Expand All @@ -55,5 +55,35 @@ <h2 class="text-center mb-5">회원 등급 정책</h2>
</div>
</div>
</div>

<script th:inline="javascript">
function selectOnlyOneCheckbox() {
var checkboxes = document.getElementsByClassName('policyCheckbox');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].onclick = function() {
for (var j = 0; j < checkboxes.length; j++) {
if (checkboxes[j] != this) {
checkboxes[j].checked = false;
}
}
};
}
}

function deleteSelectedPolicies() {
var selectedCheckbox = document.querySelector('input[name="policyCheckbox"]:checked');
if (selectedCheckbox) {
alert("회원 등급을 삭제하시겠습니까?");
var selectedPolicyId = selectedCheckbox.value;
window.location.href = '/admin/member-grade-policies/' + selectedPolicyId + '/delete';
} else {
alert("회원 등급을 선택하세요.");
}
}

window.onload = function() {
selectOnlyOneCheckbox();
};
</script>
</th:block>
</html>

0 comments on commit dca6a5c

Please sign in to comment.