Skip to content

Commit

Permalink
feat: #100 회원 등급 정책 뷰 구현 중
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrationn committed May 14, 2024
1 parent 55cf3c6 commit e9e65cb
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.t3t.frontserver.member.adaptor;

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.model.response.BaseResponse;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

@Component
@RequiredArgsConstructor
public class MemberGradePolicyAdaptor {
private final MemberGradePolicyApiClient memberGradePolicyApiClient;

public List<MemberGradePolicyDto> getMemberGradePolicyList() {
try {
return Optional.ofNullable(memberGradePolicyApiClient.getMemberGradePolicyList().getBody())
.map(BaseResponse::getData)
.orElseThrow(MemberGradePolicyApiClientException::new);
} catch (FeignException e) {
throw new MemberGradePolicyApiClientException(FeignClientUtils.getMessageFromFeignException(e));
}
}

public MemberGradePolicyDto getMemberGradePolicy(Long policyId) {
try {
return Optional.ofNullable(memberGradePolicyApiClient.getMemberGradePolicy(policyId).getBody())
.map(BaseResponse::getData)
.orElseThrow(MemberGradePolicyApiClientException::new);
} catch (FeignException e) {
throw new MemberGradePolicyApiClientException(FeignClientUtils.getMessageFromFeignException(e));
}
}

public MemberGradePolicyDto createMemberGradePolicy(MemberGradePolicyCreationRequest request) {
try {
return Optional.ofNullable(memberGradePolicyApiClient.createMemberGradePolicy(request).getBody())
.map(BaseResponse::getData)
.orElseThrow(MemberGradePolicyApiClientException::new);
} catch (FeignException e) {
throw new MemberGradePolicyApiClientException(FeignClientUtils.getMessageFromFeignException(e));
}
}

public void updateMemberGradePolicy(Long policyId, BigDecimal startAmount, BigDecimal endAmount, int rate) {
try {
memberGradePolicyApiClient.updateMemberGradePolicy(policyId, startAmount, endAmount, rate);
} catch (FeignException e) {
throw new MemberGradePolicyApiClientException(FeignClientUtils.getMessageFromFeignException(e));
}
}

public void deleteMemberGradePolicy(Long policyId) {
try {
memberGradePolicyApiClient.deleteMemberGradePolicy(policyId);
} catch (FeignException e) {
throw new MemberGradePolicyApiClientException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.t3t.frontserver.member.client;

import com.t3t.frontserver.member.model.dto.MemberGradePolicyDto;
import com.t3t.frontserver.member.model.request.MemberGradePolicyCreationRequest;
import com.t3t.frontserver.model.response.BaseResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@FeignClient(name = "MemberGradePolicyApiClient", url = "${t3t.feignClient.url}")
public interface MemberGradePolicyApiClient {

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

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

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

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

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

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.service.MemberGradePolicyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

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

@GetMapping("/admin/member-grade-policies")
public String getMemberGradePolicView(Model model) {
List<MemberGradePolicyDto> 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);

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

@PostMapping("/admin/member-grade-policy")
public String createMemberGradePolicy(@Valid @ModelAttribute MemberGradePolicyCreationRequest request) {
memberGradePolicyService.createMemberGradePolicy(request);

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

@PutMapping("/admin/member-grade-policy/{policyId}/default")
public String updateMemberGradePolicy(@PathVariable("policyId") Long policyId,
@RequestParam("startAmount") BigDecimal startAmount,
@RequestParam("endAmount") BigDecimal endAmount,
@RequestParam("rate") int rate) {
MemberGradePolicyUpdateRequest request
= MemberGradePolicyUpdateRequest.builder()
.startAmount(startAmount)
.endAmount(endAmount)
.rate(rate)
.build();

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

@DeleteMapping("/admin/member-grade-policy/{policyId}")
public String deleteMemberGradePolicy(@PathVariable("policyId") Long policyId) {
memberGradePolicyService.deleteMemberGradePolicy(policyId);

return "redirect:/main/page/memberGradePolicy";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.t3t.frontserver.member.exception;

public class MemberGradePolicyApiClientException extends RuntimeException {
private static final String DEFAULT_MESSAGE = "회원 등급 정책 API 호출에 실패하였습니다.";
public MemberGradePolicyApiClientException(){
super(DEFAULT_MESSAGE);
}
public MemberGradePolicyApiClientException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.t3t.frontserver.member.model.request;

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

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class MemberGradePolicyCreationRequest {

private BigDecimal startAmount;
private BigDecimal endAmount;
private int rate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.t3t.frontserver.member.model.request;

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

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class MemberGradePolicyUpdateRequest {
private BigDecimal startAmount;
private BigDecimal endAmount;
private int rate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
@RequiredArgsConstructor
public class MemberGradePolicyService {
private final MemberGradePolicyAdaptor memberGradePolicyAdaptor;

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

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

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

public void updateMemberGradePolicy(Long policyId, BigDecimal startAmount, BigDecimal endAmount, int rate) {
memberGradePolicyAdaptor.updateMemberGradePolicy(policyId, startAmount, endAmount, rate);
}

public void deleteMemberGradePolicy(Long policyId) {
memberGradePolicyAdaptor.deleteMemberGradePolicy(policyId);
}
}
44 changes: 44 additions & 0 deletions src/main/resources/templates/main/page/memberGradePolicy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout(categoryList)"
layout:decorate="main/layout/layout">

<th:block layout:fragment="content">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<h2 class="text-center mb-5">회원 등급 정책</h2>
<div class="d-flex justify-content-end mb-3">
<a class="btn btn-primary mx-1">등록</a>
</div>
<div class="text-center mb-5">
<table id="pointDetailTable" class="table table-bordered table-striped centered-table">
<thread>
<tr>
<td>No</td>
<td>기준 시작 금액</td>
<td>기준 종료 금액</td>
<td>적립 비율</td>
<td>편집</td>
</tr>
</thread>
<tbody>
<!-- Thymeleaf를 사용하여 반복문 처리 -->
<tr th:each="memberGradePolicy, no : ${memberGradePolicyList}">
<td th:text="${no.index + 1}"></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>
</tr>
</tbody>

</table>
<a href="/" class="btn btn-secondary">메인 화면 바로가기</a>
<p></p>
</div>
</div>
</div>
</div>
</th:block>
</html>

0 comments on commit e9e65cb

Please sign in to comment.