Skip to content

Commit

Permalink
Merge pull request #42 from Central-MakeUs/dev
Browse files Browse the repository at this point in the history
feat: 수정사항 반영 및 어드민 기능 추가
  • Loading branch information
KarmaPol authored Feb 8, 2024
2 parents ee317f8 + a7540e6 commit 44c1c6e
Show file tree
Hide file tree
Showing 26 changed files with 894 additions and 514 deletions.
Original file line number Diff line number Diff line change
@@ -1,55 +1,124 @@
package com.mm.api.domain.admin.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mm.api.common.response.CommonResponse;
import com.mm.api.domain.admin.dto.request.RejectBuyRefundStatusRequest;
import com.mm.api.domain.admin.dto.response.AdminItemListResponse;
import com.mm.api.domain.admin.dto.response.BuyListResponse;
import com.mm.api.domain.admin.dto.response.WithdrawListResponse;
import com.mm.api.domain.admin.service.AdminService;
import com.mm.api.domain.buy.dto.response.BuyResponse;
import com.mm.api.domain.buy.service.BuyService;
import com.mm.api.domain.item.dto.response.ItemDetailResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "어드민", description = "어드민 관련 API 입니다.")
@RestController
@RequestMapping("/api/v1/admin")
@RequiredArgsConstructor
public class AdminController {
private final AdminService adminService;

@Operation(summary = "url을 입력해 상품글을 크롤링합니다.", description = "zigzag url만 가능, ex) https://s.zigzag.kr/dV7jnGouAl?af=1")
@PostMapping("/items/crawl")
public CommonResponse<ItemDetailResponse> crawlItem(@RequestParam String url) {
ItemDetailResponse response = adminService.crawlItem(url);
return CommonResponse.created(response);
}

@Operation(summary = "크롤링으로 생성된 상품글에 video url을 추가합니다")
@PatchMapping("/items/{itemId}/video-url")
public CommonResponse<?> updateVideoUrl(@PathVariable Long itemId,
@RequestParam String url) {
adminService.updateVideoUrl(itemId, url);
return CommonResponse.noContent();
}

@Operation(summary = "관리자 페이지 표시용 상품 데이터를 가져옵니다")
@GetMapping("/items")
public CommonResponse<AdminItemListResponse> getItemsForAdmin(
@RequestParam(required = false, defaultValue = "1") Integer page) {
AdminItemListResponse response = adminService.getItems(page);
return CommonResponse.ok(response);
}

@Operation(summary = "특정 상품을 추천 상품으로 등록합니다")
@PatchMapping("/items/{itemId}/suggest")
public CommonResponse<?> updateItemSuggest(@PathVariable Long itemId) {
adminService.updateItemSuggest(itemId);
return CommonResponse.noContent();
}

@Operation(summary = "특정 상품을 추천 상품에서 해제합니다")
@PatchMapping("/items/{itemId}/not-suggest")
public CommonResponse<?> updateItemNotSuggest(@PathVariable Long itemId) {
adminService.updateItemNotSuggest(itemId);
return CommonResponse.noContent();
}
private final AdminService adminService;
private final BuyService buyService;

@Operation(summary = "url을 입력해 상품글을 크롤링합니다.", description = "zigzag url만 가능, ex) https://s.zigzag.kr/dV7jnGouAl?af=1")
@PostMapping("/items/crawl")
public CommonResponse<ItemDetailResponse> crawlItem(@RequestParam String url) {
ItemDetailResponse response = adminService.crawlItem(url);
return CommonResponse.created(response);
}

@Operation(summary = "크롤링으로 생성된 상품글에 video url을 추가합니다")
@PatchMapping("/items/{itemId}/video-url")
public CommonResponse<?> updateVideoUrl(@PathVariable Long itemId,
@RequestParam String url) {
adminService.updateVideoUrl(itemId, url);
return CommonResponse.noContent();
}

@Operation(summary = "관리자 페이지 표시용 상품 데이터를 가져옵니다")
@GetMapping("/items")
public CommonResponse<AdminItemListResponse> getItemsForAdmin(
@RequestParam(required = false, defaultValue = "1") Integer page) {
AdminItemListResponse response = adminService.getItems(page);
return CommonResponse.ok(response);
}

@Operation(summary = "특정 상품을 추천 상품으로 등록합니다")
@PatchMapping("/items/{itemId}/suggest")
public CommonResponse<?> updateItemSuggest(@PathVariable Long itemId) {
adminService.updateItemSuggest(itemId);
return CommonResponse.noContent();
}

@Operation(summary = "특정 상품을 추천 상품에서 해제합니다")
@PatchMapping("/items/{itemId}/not-suggest")
public CommonResponse<?> updateItemNotSuggest(@PathVariable Long itemId) {
adminService.updateItemNotSuggest(itemId);
return CommonResponse.noContent();
}

@Operation(summary = "전체 구매 인증을 페이지 단위로 가져옵니다")
@GetMapping("/buys")
public CommonResponse<BuyListResponse> getBuys(@RequestParam(required = false, defaultValue = "1") Integer page) {
BuyListResponse responses = adminService.getBuys(page);
return CommonResponse.ok(responses);
}

@Operation(summary = "구매 인증을 승인 처리합니다")
@PatchMapping("/buys/{buyId}/approve")
public CommonResponse<BuyResponse> approveBuyRefundStatus(@PathVariable Long buyId) {
BuyResponse response = adminService.approveBuyRefundStatus(buyId);
return CommonResponse.ok(response);
}

@Operation(summary = "구매 인증을 미승인 처리합니다", description = "미승인 사유를 입력해주세요.")
@PatchMapping("/buys/{buyId}/reject")
public CommonResponse<BuyResponse> rejectBuyRefundStatus(@PathVariable Long buyId,
@RequestBody RejectBuyRefundStatusRequest request) {
BuyResponse response = adminService.rejectBuyRefundStatus(buyId, request);
return CommonResponse.ok(response);
}

@Operation(summary = "전체 출금 신청을 페이지 단위로 가져옵니다")
@GetMapping("/buys/{buyId}/withdraw")
public CommonResponse<WithdrawListResponse> getWithdraws(
@RequestParam(required = false, defaultValue = "1") Integer page) {
WithdrawListResponse response = adminService.getWithdraws(page);
return CommonResponse.ok(response);
}

@Operation(summary = "특정 유저 출금 신청을 페이지 단위로 가져옵니다")
@GetMapping("/buys/{buyId}/withdraw/members/{memberId}")
public CommonResponse<WithdrawListResponse> getWithdraws(
@RequestParam(required = false, defaultValue = "1") Integer page,
@PathVariable Long memberId) {
WithdrawListResponse response = adminService.getWithdrawsByMember(page, memberId);
return CommonResponse.ok(response);
}

@Operation(summary = "출금 신청을 승인 처리합니다")
@PatchMapping("/buys/{buyId}/withdraw/approve")
public CommonResponse<BuyResponse> approvePointsWithdraw(@PathVariable Long buyId) {
BuyResponse response = adminService.approvePointsWithdraw(buyId);
return CommonResponse.ok(response);
}

@Operation(summary = "출금 신청을 미승인 처리합니다")
@PatchMapping("/buys/{buyId}/withdraw/reject")
public CommonResponse<BuyResponse> rejectPointsWithdraw(@PathVariable Long buyId,
@RequestBody RejectBuyRefundStatusRequest request) {
BuyResponse response = adminService.rejectPointsWithdraw(buyId, request);
return CommonResponse.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mm.api.domain.buy.dto.request;
package com.mm.api.domain.admin.dto.request;

public record RejectBuyRefundStatusRequest(String rejectReason) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static record AdminItemResponse(Long id,
Integer price,
Integer refund,
String thumbnailUrl,
Boolean isSuggested,
List<String> imageUrls,
List<String> videoUrls) {
public static AdminItemResponse of(Item item, List<String> imageUrls, List<String> videoUrls) {
Expand All @@ -24,6 +25,7 @@ public static AdminItemResponse of(Item item, List<String> imageUrls, List<Strin
item.getPrice(),
item.getRefund(),
item.getThumbnailUrl(),
item.getIsSuggested(),
imageUrls,
videoUrls
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mm.api.domain.admin.dto.response;

import java.util.List;

import com.mm.api.domain.buy.dto.response.BuyResponse;

public record BuyListResponse(Long pageNum, List<BuyResponse> buys) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mm.api.domain.admin.dto.response;

import java.util.List;

public record WithdrawListResponse(Long pageNum, List<WithdrawResponse> withdrawResponses) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mm.api.domain.admin.dto.response;

import java.time.LocalDateTime;

import com.mm.coredomain.domain.Buy;
import com.mm.coredomain.domain.Member;
import com.mm.coredomain.domain.RefundStatus;

import lombok.Builder;

@Builder
public record WithdrawResponse(Long id,
Long memberId,
String redirectUrl,
LocalDateTime uploadTime,
LocalDateTime approvedTime,
Integer pointsBeforeRefund,
Integer pointsAfterRefund,
Integer purchase,
Integer refund,
RefundStatus refundStatus,
String rejectReason,
String depositor,
String account,
String accountBank
) {
public static WithdrawResponse of(Buy buy, Member member) {
return WithdrawResponse.builder()
.id(buy.getId())
.memberId(member.getId())
.redirectUrl(buy.getRedirectUrl())
.uploadTime(buy.getUploadTime())
.approvedTime(buy.getApprovedTime())
.pointsBeforeRefund(buy.getPointsBeforeRefund())
.pointsAfterRefund(buy.getPointsAfterRefund())
.purchase(buy.getPurchase())
.refund(buy.getRefund())
.refundStatus(buy.getRefundStatus())
.rejectReason(buy.getRejectReason())
.depositor(member.getDepositorName())
.account(member.getAccount())
.accountBank(member.getAccountBank())
.build();
}
}
Loading

0 comments on commit 44c1c6e

Please sign in to comment.