-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55cf3c6
commit e9e65cb
Showing
8 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/com/t3t/frontserver/member/adaptor/MemberGradePolicyAdaptor.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 |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/t3t/frontserver/member/client/MemberGradePolicyApiClient.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 |
---|---|---|
@@ -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); | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/t3t/frontserver/member/controller/MemberGradePolicyController.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 |
---|---|---|
@@ -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"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/t3t/frontserver/member/exception/MemberGradePolicyApiClientException.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 |
---|---|---|
@@ -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); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/t3t/frontserver/member/model/request/MemberGradePolicyCreationRequest.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 |
---|---|---|
@@ -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; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/t3t/frontserver/member/model/request/MemberGradePolicyUpdateRequest.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 |
---|---|---|
@@ -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; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/t3t/frontserver/member/service/MemberGradePolicyService.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 |
---|---|---|
@@ -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
44
src/main/resources/templates/main/page/memberGradePolicy.html
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,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> |