Skip to content

Commit

Permalink
Merge pull request #347 from TrandPick/feat/346_withDrawModify
Browse files Browse the repository at this point in the history
Feat/346 with draw modify
  • Loading branch information
angelSuho authored Jul 9, 2023
2 parents 545a7a0 + 43a6d5b commit 2d5ac17
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public Member getLogin() {
public Boolean checkMember() {
return getLogin().getRole().equals(RoleType.MEMBER);
}
public Boolean admin() {
return getLogin().getRole().equals(RoleType.ADMIN);
}
public Member getMember() {
Member member = getLogin();
if (member.getRole().equals(RoleType.MEMBER)) {
Expand All @@ -154,13 +157,25 @@ public Member getMember() {
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}

public Member getRollMember(){
Member member=getLogin();
if(member.getRole().equals(RoleType.MEMBER)){
return member;
}else if(member.getRole().equals(RoleType.BRAND_ADMIN)){
return member;
}else if(member.getRole().equals(RoleType.ADMIN)){
return member;
}
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}
public Member getBrandMember() {
Member member = getLogin();
if (member.getRole().equals(RoleType.BRAND_ADMIN)) {
return member;
}
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}

public Boolean checkAdmin() {
return !checkMember();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsername(String username);
Optional<Member> findByEmail(String email);
Page<Member> findAllByRoleAndRecentlyAccessDateBetween(RoleType role, LocalDateTime fromDate, LocalDateTime toDate, Pageable pageable);

Member findByBrand(String brand);
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public RsData<Member> manageAccount(Member member, String bank_name, String acco
public Member findById(Long id) {
return memberRepository.findById(id).orElseThrow(() -> new MemberNotFoundException("존재하지 않는 회원입니다."));
}

public Member findByBrandMember(String name){
return memberRepository.findByBrand(name);
}
public Optional<Member> findByUsername(String username) {
return memberRepository.findByUsername(username);
}
Expand All @@ -184,7 +186,7 @@ public static class AddCashRsDataBody {

@Transactional
public RsData<AddCashRsDataBody> addCash(String brand, long price, Brand relEntity, CashLog.EvenType eventType) {
Member member=rq.getBrandMember();
Member member=findByBrandMember(brand);
if(!member.getBrand().equals(brand)){
return RsData.of("F-1","해당 브랜드와 관리자가 일치하지 않습니다.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public RsData<Order> productToOrder(Member member, Long id, int quantity, String
public void orderToOrder(@Payload String Id) throws JsonProcessingException {
// delay 2sec
try {
Thread.sleep(500);
Thread.sleep(750);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
public class AdmRebateController {
private final RebateService rebateService;
private final Rq rq;

@GetMapping("/makeData")
@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
public String showMakeData() {
if(!rq.getRollMember().getRole().getValue().equals("BRAND_ADMIN")){
return rq.historyBack("브랜드 관리자만 접근할 수 있습니다.");
}
return "trendpick/admin/makeData";
}

Expand All @@ -49,6 +53,10 @@ public String makeData(String yearMonth) {
@GetMapping("/rebateOrderItemList")
@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
public String showRebateOrderItemList(String yearMonth, Model model) {
if(!rq.getRollMember().getRole().getValue().equals("BRAND_ADMIN")){
return rq.historyBack("브랜드 관리자만 접근할 수 있습니다.");
}

if (!StringUtils.hasText(yearMonth)) {
yearMonth = Ut.date.getCurrentYearMonth();
}
Expand All @@ -75,7 +83,6 @@ public String rebateOne(@PathVariable long orderItemId, HttpServletRequest req)
@PostMapping("/rebate")
@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
public String rebate(String ids, HttpServletRequest req) {

String[] idsArr = ids.split(",");

Arrays.stream(idsArr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@ public class AdmWithdrawController {
private final WithdrawService withdrawService;
private final Rq rq;

@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
@PreAuthorize("hasAuthority({'ADMIN', 'BRAND_ADMIN'})")
@GetMapping("/withDrawList")
public String showApplyList(Model model) {
Member member=rq.getBrandMember();
System.out.println(member.getId()+"!!");
List<WithdrawApply> withdrawApplies = withdrawService.findByWithdrawApplyId(member.getId());

Member member=rq.getRollMember();
List<WithdrawApply> withdrawApplies;
if(member.getRole().getValue().equals("ADMIN")) {
withdrawApplies = withdrawService.findAll();
}else{
withdrawApplies=withdrawService.findByWithdrawApplyId(member.getId());
}
model.addAttribute("withdrawApplies", withdrawApplies);
return "trendpick/admin/withDrawList";
}

@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
@PreAuthorize("hasAuthority({'ADMIN'})")
@PostMapping("/{withdrawApplyId}")
public String applyDone(@PathVariable Long withdrawApplyId) {
RsData withdrawRsData = withdrawService.withdraw(withdrawApplyId);

return rq.redirectWithMsg("/trendpick/admin/withDrawList", withdrawRsData);
}

@PreAuthorize("hasAuthority({'BRAND_ADMIN'})")
@PreAuthorize("hasAuthority({'ADMIN'})")
@PostMapping("/{withdrawApplyId}/cancel")
public String cancel(@PathVariable Long withdrawApplyId) {
RsData withdrawRsData = withdrawService.cancelApply(withdrawApplyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import project.trendpick_pro.domain.common.base.rq.Rq;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.service.MemberService;
import project.trendpick_pro.domain.withdraw.entity.WithdrawApply;
import project.trendpick_pro.domain.withdraw.entity.dto.WithDrawApplyForm;
Expand All @@ -27,6 +28,9 @@ public class WithdrawController {

@GetMapping("/withDraw")
public String showApply(Model model) {
if(!rq.getRollMember().getRole().getValue().equals("BRAND_ADMIN")){
return rq.historyBack("브랜드 관리자만 접근할 수 있습니다.");
}
long actorRestCash = memberService.getRestCash(rq.getBrandMember());
model.addAttribute("actorRestCash", actorRestCash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ <h1 class="font-bold text-lg">
<span th:text="${item.msg}"></span>
</td>
<td>
<a th:if="${item.applyDoneAvailable}" href="javascript:;" onclick="$(this).next().submit();"
<a th:if="${@rq.admin() and item.applyDoneAvailable}" href="javascript:;" onclick="$(this).next().submit();"
class="btn btn-primary btn-xs">출금</a>
<form method="POST" th:action="@{|/trendpick/admin/${item.id}|}" hidden></form>
<button th:if="${item.applyDone}" disabled class="btn btn-primary btn-xs" type="button">
출금완료
</button>

<a th:if="${item.cancelAvailable}" href="javascript:;"
<a th:if="${@rq.admin() and item.cancelAvailable}" href="javascript:;"
onclick="confirm('정말로 취소하시겠습니까?') && $(this).next().submit();"
class="btn btn-warning btn-outline btn-xs">취소</a>
<form method="POST" th:action="@{|/trendpick/admin/${item.id}/cancel|}" hidden></form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h1 class="text-4xl font-bold ml-4 inline-block">TrendPick</h1>
</li>
<li>
<span>
<a th:href="@{|/trendpick/admin/withDrawList|}"><span>출금목록</span></a>
<a th:href="@{|/trendpick/admin/withDrawList|}"><span>출금신청목록</span></a>
</span>
</li>
<li>
Expand Down

0 comments on commit 2d5ac17

Please sign in to comment.