diff --git a/src/main/java/com/t3t/frontserver/admin/controller/CouponController.java b/src/main/java/com/t3t/frontserver/admin/controller/CouponController.java new file mode 100644 index 00000000..9eab34be --- /dev/null +++ b/src/main/java/com/t3t/frontserver/admin/controller/CouponController.java @@ -0,0 +1,17 @@ +package com.t3t.frontserver.admin.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class CouponController { + @GetMapping("/admin/coupons/register") + public String getRegisterView(){ + return "admin/page/couponRegister"; + } + + @GetMapping("/admin/coupons/usageHistory") + public String getUsage(){ + return "admin/page/couponHistory"; + } +} \ No newline at end of file diff --git a/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java b/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java new file mode 100644 index 00000000..54beada2 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java @@ -0,0 +1,40 @@ +package com.t3t.frontserver.coupon.adapter; + +import com.t3t.frontserver.coupon.client.CouponApiClient; +import com.t3t.frontserver.member.exception.CouponApiClientException; +import com.t3t.frontserver.util.FeignClientUtils; +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class CouponAdapter { + private final CouponApiClient couponApiClient; + + /** + * 회원이 도서 쿠폰 발급받기 위해 사용하는 api + * @author joohyun1996(이주현) + */ + public String registerBookCouponByMember(){ + try{ + couponApiClient.registerBookCoupon(); + return "쿠폰이 등록되었습니다"; + }catch(FeignException e){ + throw new CouponApiClientException("도서쿠폰 등록에 실패하였습니다 " + FeignClientUtils.getMessageFromFeignException(e)); + } + } + + /** + * 회원이 카테고리 쿠폰 발급받기 위해 사용하는 api + * @author joohyun1996(이주현) + */ + public String registerCategoryCouponByMember(){ + try{ + couponApiClient.registerCategoryCoupon(); + return "쿠폰이 등록되었습니다"; + }catch(FeignException e){ + throw new CouponApiClientException("카테고리쿠폰 등록에 실패하였습니다 " + FeignClientUtils.getMessageFromFeignException(e)); + } + } +} diff --git a/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java b/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java new file mode 100644 index 00000000..2d29cb5c --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java @@ -0,0 +1,17 @@ +package com.t3t.frontserver.coupon.client; + +import com.t3t.frontserver.model.response.BaseResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; + + +@FeignClient(name = "couponApiClient", url = "${t3t.feignClient.url}") +public interface CouponApiClient { + + @PostMapping("/at/bookstore/members/coupons/book") + ResponseEntity> registerBookCoupon(); + + @PostMapping("/at/bookstore/members/coupons/category") + ResponseEntity> registerCategoryCoupon(); +} diff --git a/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java b/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java new file mode 100644 index 00000000..28e7c61c --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java @@ -0,0 +1,22 @@ +package com.t3t.frontserver.coupon.controller; + +import com.t3t.frontserver.coupon.service.CouponService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class CouponRestController { + private final CouponService couponService; + + @PostMapping("/coupons/book") + public void registerBookCouponByMember(){ + couponService.registerBookCoupon(); + } + + @PostMapping("/coupons/category") + public void registerCategoryCouponByMember(){ + couponService.registerCategoryCoupon(); + } +} diff --git a/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java new file mode 100644 index 00000000..6a0375b9 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java @@ -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; +} diff --git a/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java new file mode 100644 index 00000000..d4c760ab --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java @@ -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; +} diff --git a/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java b/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java new file mode 100644 index 00000000..60ae65c5 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java @@ -0,0 +1,19 @@ +package com.t3t.frontserver.coupon.service; + +import com.t3t.frontserver.coupon.adapter.CouponAdapter; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CouponService { + private final CouponAdapter couponAdapter; + + public String registerBookCoupon(){ + return couponAdapter.registerBookCouponByMember(); + } + + public String registerCategoryCoupon(){ + return couponAdapter.registerCategoryCouponByMember(); + } +} diff --git a/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java b/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java index d4cfd309..78405a89 100644 --- a/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java +++ b/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java @@ -1,10 +1,14 @@ 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; import com.t3t.frontserver.member.model.dto.MemberAddressDto; import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest; import com.t3t.frontserver.member.model.request.MemberRegistrationRequest; +import com.t3t.frontserver.member.model.response.MemberAdminResponse; import com.t3t.frontserver.member.model.response.MemberInfoResponse; import com.t3t.frontserver.member.model.response.MemberRegistrationResponse; import com.t3t.frontserver.model.response.BaseResponse; @@ -128,4 +132,53 @@ public void verifyMemberActivationCode(long memberId, String code) { throw new MemberApiClientException("회원 활성화 코드 검증에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); } } + + /** + * 회원 목록 이름으로 조회 + * @param name + * @author joohyun1996(이주현) + */ + public List findMemberByName(String name) { + try { + return Optional.ofNullable(memberApiClient.findMemberByName(name).getBody()) + .map(BaseResponse::getData) + .orElseThrow(MemberApiClientException::new); + } catch (FeignException e) { + throw new MemberApiClientException("회원 이름 목록 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); + } + } + + /** + * 회원에게 관리자가 쿠폰 등록 + * @author joohyun1996(이주현) + */ + + public String registerCouponToMemberByAdmin(String couponType, Long memberId){ + try{ + memberApiClient.registerCouponToMemberByAdmin(couponType, memberId); + return "쿠폰 등록에 성공하였습니다"; + }catch (FeignException e){ + throw new CouponApiClientException("쿠폰 등록에 실패하였습니다 " + FeignClientUtils.getMessageFromFeignException(e)); + } + } + + public List 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)); + } + } } diff --git a/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java b/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java index a75fce9c..64545d0f 100644 --- a/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java +++ b/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java @@ -1,8 +1,11 @@ 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; +import com.t3t.frontserver.member.model.response.MemberAdminResponse; import com.t3t.frontserver.member.model.response.MemberInfoResponse; import com.t3t.frontserver.member.model.response.MemberRegistrationResponse; import com.t3t.frontserver.model.response.BaseResponse; @@ -37,6 +40,14 @@ public interface MemberApiClient { @GetMapping(value = "/t3t/bookstore/members/{memberId}") ResponseEntity> getMemberById(@PathVariable("memberId") long memberId); + /** + * 회원 목록 이름으로 조회 + * @param name + * @author joohyun1996(이주현) + */ + @GetMapping(value = "/at/bookstore/members") + ResponseEntity>> findMemberByName(@RequestParam("name") String name); + /** * 회원 식별자로 특정 회원이 등록한 모든 회원 주소 정보들을 조회하는 API * @@ -83,4 +94,19 @@ public interface MemberApiClient { @PostMapping("/t3t/bookstore/members/{memberId}/codes?type=verify") BaseResponse verifyMemberActivationCertCode(@PathVariable("memberId") Long memberId, @RequestParam("value") String code); + + /** + * 관리자가 회원에게 쿠폰 등록하기 위한 API + * + * @author joohyun1996(이주현) + */ + @PostMapping("/at/bookstore/members/coupons/{memberId}/{couponType}") + BaseResponse registerCouponToMemberByAdmin(@PathVariable("couponType") String couponType, + @PathVariable("memberId") Long memberId); + + @GetMapping("/at/bookstore/members/coupons") + ResponseEntity>> findAllCoupon(); + + @GetMapping("/at/coupon/details/{couponId}") + ResponseEntity> getCouponDetails(@PathVariable("couponId") String id); } diff --git a/src/main/java/com/t3t/frontserver/member/controller/MemberController.java b/src/main/java/com/t3t/frontserver/member/controller/MemberController.java index b63e4fdc..b7ffde54 100644 --- a/src/main/java/com/t3t/frontserver/member/controller/MemberController.java +++ b/src/main/java/com/t3t/frontserver/member/controller/MemberController.java @@ -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; @@ -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 @@ -34,6 +38,20 @@ public String registerView(Model model) { return "main/page/register"; } + @GetMapping("/members/coupons") + public String couponView(Model model){ + List responseList = memberService.findAllCouponsByMemberId(); + List 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"; + } + /** * 회원 가입 요청 처리 * diff --git a/src/main/java/com/t3t/frontserver/member/controller/MemberRestController.java b/src/main/java/com/t3t/frontserver/member/controller/MemberRestController.java new file mode 100644 index 00000000..3173ebe0 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/member/controller/MemberRestController.java @@ -0,0 +1,30 @@ +package com.t3t.frontserver.member.controller; + +import com.t3t.frontserver.member.model.response.MemberAdminResponse; +import com.t3t.frontserver.member.service.MemberService; +import com.t3t.frontserver.model.response.BaseResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +public class MemberRestController { + private final MemberService memberService; + + @GetMapping("/members") + public ResponseEntity> findAllMembersByName(@RequestParam("name") String name){ + BaseResponse> data = new BaseResponse>().data(memberService.findMemberByName(name)); + + return ResponseEntity.status(HttpStatus.OK).body(data.getData()); + } + + @PostMapping("/coupon/{couponType}/{memberId}") + public ResponseEntity> registerCouponToUserByAdmin(@PathVariable("couponType") String couponType, + @PathVariable("memberId") Long memberId){ + return ResponseEntity.status(HttpStatus.CREATED).body(new BaseResponse().message(memberService.registCouponToMemberByAdmin(couponType, memberId))); + } +} diff --git a/src/main/java/com/t3t/frontserver/member/exception/CouponApiClientException.java b/src/main/java/com/t3t/frontserver/member/exception/CouponApiClientException.java new file mode 100644 index 00000000..cc0cc232 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/member/exception/CouponApiClientException.java @@ -0,0 +1,13 @@ +package com.t3t.frontserver.member.exception; + +public class CouponApiClientException extends RuntimeException{ + private static final String DEFAULT_MESSAGES = "쿠폰 발급에 실패하였습니다"; + + public CouponApiClientException() { + super(DEFAULT_MESSAGES); + } + + public CouponApiClientException(String message) { + super(message); + } +} diff --git a/src/main/java/com/t3t/frontserver/member/model/response/MemberAdminResponse.java b/src/main/java/com/t3t/frontserver/member/model/response/MemberAdminResponse.java new file mode 100644 index 00000000..fe543895 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/member/model/response/MemberAdminResponse.java @@ -0,0 +1,16 @@ +package com.t3t.frontserver.member.model.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MemberAdminResponse { + public Long id; + public String name; + public String email; +} diff --git a/src/main/java/com/t3t/frontserver/member/service/MemberService.java b/src/main/java/com/t3t/frontserver/member/service/MemberService.java index 5572c11e..e3e0ad61 100644 --- a/src/main/java/com/t3t/frontserver/member/service/MemberService.java +++ b/src/main/java/com/t3t/frontserver/member/service/MemberService.java @@ -1,13 +1,15 @@ 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; import com.t3t.frontserver.member.model.request.MemberRegistrationRequest; +import com.t3t.frontserver.member.model.response.MemberAdminResponse; import com.t3t.frontserver.member.model.response.MemberInfoResponse; import com.t3t.frontserver.member.model.response.MemberRegistrationResponse; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; @@ -92,4 +94,20 @@ public void issueMemberActivationCode(long memberId) { public void verifyMemberActivationCode(long memberId, String activationCode) { memberAdaptor.verifyMemberActivationCode(memberId, activationCode); } + + public List findMemberByName(String name){ + return memberAdaptor.findMemberByName(name); + } + + public String registCouponToMemberByAdmin(String couponType, Long memberId){ + return memberAdaptor.registerCouponToMemberByAdmin(couponType, memberId); + } + + public List findAllCouponsByMemberId(){ + return memberAdaptor.findAllCouponsByMemberId(); + } + + public CouponDetailFindResponse findCouponDetails(String id){ + return memberAdaptor.getCouponDetails(id); + } } diff --git a/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java b/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java index dfe1482c..b53311ea 100644 --- a/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java +++ b/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java @@ -15,4 +15,20 @@ public BaseResponse(String message, T data) { this.message = message; this.data = data; } + + /** + * 응답 객체에 데이터를 설정한다. + * @param data 응답할 데이터 + * @return BaseResponse + */ + public BaseResponse data(T data) { + this.data = data; + return this; + } + + + public BaseResponse message(String message) { + this.message = message; + return this; + } } diff --git a/src/main/resources/static/assets/admin/js/adminCoupon.js b/src/main/resources/static/assets/admin/js/adminCoupon.js new file mode 100644 index 00000000..04bc408b --- /dev/null +++ b/src/main/resources/static/assets/admin/js/adminCoupon.js @@ -0,0 +1,170 @@ +/** + * 확인 버튼을 클릭했을 때 실행되는 이벤트 핸들러 + * 회원 선택 버튼과 쿠폰 선택 버튼을 생성하고 테이블에 추가 + * @author joohyun1996(이주현) + */ +document.getElementById('confirmBtn').addEventListener('click', function () { + + var count = document.getElementById('memberCount').value; + var tableBody = document.getElementById('memberButtonTable').getElementsByTagName('tbody')[0]; + tableBody.innerHTML = ''; + + for (var i = 1; i <= count; i++) { + var row = document.createElement('tr'); + // 첫 번째 열 : 참여자 선택 버튼 + var memberCell = document.createElement('td'); + var memberButton = document.createElement('button'); + memberButton.type = 'button'; + memberButton.id = 'participantButton_' + i; + memberButton.innerText = '회원 선택'; + memberButton.classList.add('btn', 'btn-secondary'); + memberButton.dataset.bsToggle = 'modal'; + memberButton.dataset.bsTarget = '#memberModal'; + memberButton.dataset.index = i; + memberButton.addEventListener('click', function () { + $('#memberModal').data('index', this.dataset.index); + }); + memberCell.appendChild(memberButton); + row.appendChild(memberCell); + + // 두 번째 열 : 쿠폰 선택 버튼 + var couponCell = document.createElement('td'); + var couponButton = document.createElement('button'); + couponButton.type = 'button'; + couponButton.id = 'couponButton_' + i; + couponButton.innerText = '쿠폰 선택'; + couponButton.classList.add('btn', 'btn-secondary'); + couponButton.dataset.bsToggle = 'modal'; + couponButton.dataset.bsTarget = '#couponModal'; + couponButton.dataset.index = i; + couponButton.addEventListener('click', function () { + $('#couponModal').data('index', this.dataset.index); + fetchCouponsAndUpdateModal(); + }); + couponCell.appendChild(couponButton); + row.appendChild(couponCell); + + tableBody.appendChild(row); + + // 세 번째 열 : 선택 버튼 + var selectCell = document.createElement('td'); + var selectButton = document.createElement('button'); + selectButton.type = 'button'; + selectButton.id = 'selectButton_' + i; + selectButton.innerText = '등록'; + selectButton.classList.add('btn', 'btn-success'); + selectButton.addEventListener('click', function () { + var selectedMember = document.querySelector('#memberTable input[type="radio"]:checked'); + var selectedCoupon = document.querySelector('#couponTable input[type="radio"]:checked'); + + if (selectedMember && selectedCoupon) { + // 선택된 회원의 이름과 쿠폰의 종류를 가져옵니다. + var memberId = selectedMember.closest('tr').children[1].innerText; + var couponType = selectedCoupon.closest('tr').children[1].innerText; + + // 쿠폰의 종류에 따라 다른 URL로 POST 요청을 보냅니다. + var url = '/coupon/' + couponType + '/' + memberId; + sendPostRequest(url, { index: i }); + } else { + console.log(selectedMember); + console.log(selectedCoupon); + alert('회원과 쿠폰을 선택해주세요.'); + } + }); + selectCell.appendChild(selectButton); + row.appendChild(selectCell); + + tableBody.appendChild(row); + } +}); + +document.getElementById('searchButton').addEventListener('click', function () { + var searchInput = document.getElementById('memberSearchInput').value; + + // 여기서 searchInput을 사용하여 회원을 검색합니다. + // 이 예제에서는 검색 결과를 담은 배열인 searchResults를 사용하겠습니다. + fetch('/members?name=' + searchInput, { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => { + if (!response.ok) { + throw new Error("Network response not ok") + } + let a = response.data; + return response.json(); + }) + .then(data => { + console.log(data) + let list = data.content; + console.log(list) + var tableBody = document.getElementById('memberTable').getElementsByTagName('tbody')[0]; + tableBody.innerHTML = ''; + + if(Array.isArray(data)) { + data.forEach(result => { + var row = document.createElement('tr'); + + var radioCell = document.createElement('td'); + var radioButton = document.createElement('input'); + radioButton.type = 'radio'; + radioButton.name = "memberName"; + radioCell.appendChild(radioButton); + row.appendChild(radioCell); + + var idCell = document.createElement('td'); + idCell.innerText = result.id; + row.appendChild(idCell); + + var nameCell = document.createElement('td'); + nameCell.innerText = result.name; + row.appendChild(nameCell); + + var emailCell = document.createElement('td'); + emailCell.innerText = result.email; + row.appendChild(emailCell); + + tableBody.appendChild(row); + }); + } + }) + .catch(error => console.error('Error:', error)); +}); + +function fetchCouponsAndUpdateModal() { + var tableBody = document.getElementById('couponTable').getElementsByTagName('tbody')[0]; + tableBody.innerHTML = ''; + + var couponTypes = ['general_coupon', 'book_coupon', 'category_coupon']; + + couponTypes.forEach((couponType, index) => { + var row = document.createElement('tr'); + + var radioCell = document.createElement('td'); + var radioButton = document.createElement('input'); + radioButton.type = 'radio'; + radioButton.name = "couponType"; + radioCell.appendChild(radioButton); + row.appendChild(radioCell); + + var couponNameCell = document.createElement('td'); + couponNameCell.innerText = couponType; + row.appendChild(couponNameCell); + tableBody.appendChild(row); + }); +} + +function sendPostRequest(url, data) { + fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + .then(response => response.json()) + .then(data => console.log(data)) + .catch(error => console.error('Error:', error)); +} \ No newline at end of file diff --git a/src/main/resources/templates/admin/fragment/couponModal.html b/src/main/resources/templates/admin/fragment/couponModal.html new file mode 100644 index 00000000..5b5764b6 --- /dev/null +++ b/src/main/resources/templates/admin/fragment/couponModal.html @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/admin/fragment/memberModal.html b/src/main/resources/templates/admin/fragment/memberModal.html new file mode 100644 index 00000000..50f99a50 --- /dev/null +++ b/src/main/resources/templates/admin/fragment/memberModal.html @@ -0,0 +1,39 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/admin/fragment/sidebar.html b/src/main/resources/templates/admin/fragment/sidebar.html index ecc4056f..f03c1ef9 100644 --- a/src/main/resources/templates/admin/fragment/sidebar.html +++ b/src/main/resources/templates/admin/fragment/sidebar.html @@ -56,17 +56,12 @@