Skip to content

Commit

Permalink
feature:#102 마이페이지 자신 쿠폰 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
joohyun1996 committed May 15, 2024
1 parent c17a7a6 commit bf6b89e
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.t3t.frontserver.coupon.model.response;

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

import java.math.BigDecimal;
import java.time.LocalDate;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CouponDetailFindResponse {
public String couponId;
public BigDecimal discountRate;
public BigDecimal discountFee;
public LocalDate couponExpireDate;
public String couponType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.t3t.frontserver.coupon.model.response;

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

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CouponDetailResponse {
public String couponId;
public String couponUseType;
public LocalDateTime couponUseDate;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.t3t.frontserver.member.adaptor;

import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse;
import com.t3t.frontserver.coupon.model.response.CouponDetailResponse;
import com.t3t.frontserver.member.client.MemberApiClient;
import com.t3t.frontserver.member.exception.CouponApiClientException;
import com.t3t.frontserver.member.exception.MemberApiClientException;
Expand Down Expand Up @@ -160,4 +162,23 @@ public String registerCouponToMemberByAdmin(String couponType, Long memberId){
}
}

public List<CouponDetailResponse> findAllCouponsByMemberId(){
try {
return Optional.ofNullable(memberApiClient.findAllCoupon().getBody())
.map(BaseResponse::getData)
.orElseThrow(CouponApiClientException::new);
} catch (FeignException e) {
throw new CouponApiClientException("쿠폰 목록 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e));
}
}

public CouponDetailFindResponse getCouponDetails(String id){
try {
return Optional.ofNullable(memberApiClient.getCouponDetails(id).getBody())
.map(BaseResponse::getData)
.orElseThrow(CouponApiClientException::new);
} catch (FeignException e) {
throw new CouponApiClientException("쿠폰 세부사항 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.t3t.frontserver.member.client;

import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse;
import com.t3t.frontserver.coupon.model.response.CouponDetailResponse;
import com.t3t.frontserver.member.model.dto.MemberAddressDto;
import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest;
import com.t3t.frontserver.member.model.request.MemberRegistrationRequest;
Expand Down Expand Up @@ -101,4 +103,10 @@ public interface MemberApiClient {
@PostMapping("/at/bookstore/members/coupons/{memberId}/{couponType}")
BaseResponse<Void> registerCouponToMemberByAdmin(@PathVariable("couponType") String couponType,
@PathVariable("memberId") Long memberId);

@GetMapping("/at/bookstore/members/coupons")
ResponseEntity<BaseResponse<List<CouponDetailResponse>>> findAllCoupon();

@GetMapping("/at/coupon/details/{couponId}")
ResponseEntity<BaseResponse<CouponDetailFindResponse>> getCouponDetails(@PathVariable("couponId") String id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.t3t.frontserver.member.controller;

import com.t3t.frontserver.auth.util.SecurityContextUtils;
import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse;
import com.t3t.frontserver.coupon.model.response.CouponDetailResponse;
import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest;
import com.t3t.frontserver.member.model.request.MemberRegistrationRequest;
import com.t3t.frontserver.member.service.MemberService;
Expand All @@ -15,6 +17,8 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Controller
Expand All @@ -34,6 +38,20 @@ public String registerView(Model model) {
return "main/page/register";
}

@GetMapping("/members/coupons")
public String couponView(Model model){
List<CouponDetailResponse> responseList = memberService.findAllCouponsByMemberId();
List<CouponDetailFindResponse> couponDetailFindResponseList = new ArrayList<>();
for (CouponDetailResponse couponDetailResponse : responseList) {
CouponDetailFindResponse response = memberService.findCouponDetails(couponDetailResponse.getCouponId());
response.setCouponId(couponDetailResponse.getCouponId());

couponDetailFindResponseList.add(response);
}
model.addAttribute("couponList", couponDetailFindResponseList);
return "main/page/coupon";
}

/**
* 회원 가입 요청 처리
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.t3t.frontserver.member.service;

import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse;
import com.t3t.frontserver.coupon.model.response.CouponDetailResponse;
import com.t3t.frontserver.member.adaptor.MemberAdaptor;
import com.t3t.frontserver.member.model.dto.MemberAddressDto;
import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest;
Expand Down Expand Up @@ -100,4 +102,12 @@ public List<MemberAdminResponse> findMemberByName(String name){
public String registCouponToMemberByAdmin(String couponType, Long memberId){
return memberAdaptor.registerCouponToMemberByAdmin(couponType, memberId);
}

public List<CouponDetailResponse> findAllCouponsByMemberId(){
return memberAdaptor.findAllCouponsByMemberId();
}

public CouponDetailFindResponse findCouponDetails(String id){
return memberAdaptor.getCouponDetails(id);
}
}
8 changes: 4 additions & 4 deletions src/main/resources/templates/main/fragment/mypageSidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ <h4>주문 정보</h4>
<h4>쿠폰 및 포인트 정보</h4>
<ul class="list-unstyled">
<li id="coupon-history">
<a href="#">보유 쿠폰 내역</a>
<a href="/members/coupons">보유 쿠폰 내역</a>
</li>
<li id="point-history">
<a href="#">포인트 이력</a>
</li>
<li id="coupon-usage">
<a href="#">쿠폰 이력</a>
</li>
<!--<li id="coupon-usage">
<a href="/members/coupons/history">쿠폰 이력</a>
</li>-->
</ul>
</div>
</div>
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/templates/main/page/coupon.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
<div class="container mt-5">
<h1>보유 쿠폰 조회</h1>
<table class="table">
<tbody>
<thead>
<tr>
<th scope="row">쿠폰명</th>
<th scope="row">할인액(율)</th>
<th scope="row">할인액</th>
<th scope="row">할인율</th>
<th scope="row">유효기간</th>
<th scope="row">쿠폰종류</th>
</tr>
</thead>
<tbody>
<tr th:each="coupon : ${couponList}">
<td th:text="${coupon.couponId}"></td>
<td th:text="${coupon.discountRate != null ? coupon.discountRate : 'N/A'}"></td>
<td th:text="${coupon.discountFee != null ? coupon.discountFee : 'N/A'}"></td>
<td th:text="${coupon.couponExpireDate}"></td>
<td th:text="${coupon.couponType}"></td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit bf6b89e

Please sign in to comment.