package com.tcm.training.admin.member.controller;
|
|
import com.tcm.training.admin.common.ApiResponse;
|
import com.tcm.training.admin.common.PageResponse;
|
import com.tcm.training.admin.member.service.MemberPurchaseOrderAppService;
|
import com.tcm.training.admin.member.vo.MemberPurchaseOrderListItemVO;
|
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.time.LocalDateTime;
|
|
@Validated
|
@RestController
|
@RequestMapping({"/api/v1", "/api"})
|
public class MemberPurchaseOrderController {
|
|
private final MemberPurchaseOrderAppService memberPurchaseOrderAppService;
|
|
public MemberPurchaseOrderController(MemberPurchaseOrderAppService memberPurchaseOrderAppService) {
|
this.memberPurchaseOrderAppService = memberPurchaseOrderAppService;
|
}
|
|
@GetMapping("/member/purchase-orders")
|
public ApiResponse<PageResponse<MemberPurchaseOrderListItemVO>> page(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int pageSize,
|
@RequestParam(required = false) String orderNo,
|
@RequestParam(required = false) String userPhone,
|
@RequestParam(required = false) String memberType,
|
@RequestParam(required = false) String paymentMethod,
|
@RequestParam(required = false) String status,
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) {
|
return ApiResponse.ok(memberPurchaseOrderAppService.page(
|
page, pageSize, orderNo, userPhone, memberType, paymentMethod, status, createdFrom, createdTo
|
));
|
}
|
|
@GetMapping("/member/purchase-orders/export")
|
public void export(HttpServletResponse response,
|
@RequestParam(required = false) String orderNo,
|
@RequestParam(required = false) String userPhone,
|
@RequestParam(required = false) String memberType,
|
@RequestParam(required = false) String paymentMethod,
|
@RequestParam(required = false) String status,
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) throws IOException {
|
memberPurchaseOrderAppService.export(orderNo, userPhone, memberType, paymentMethod, status, createdFrom, createdTo, response);
|
}
|
|
@PostMapping("/member/purchase-orders/{id}/refund")
|
public ApiResponse<Void> refund(@PathVariable Long id) {
|
memberPurchaseOrderAppService.refund(id);
|
return ApiResponse.ok(null);
|
}
|
|
@DeleteMapping("/member/purchase-orders/{id}")
|
public ApiResponse<Void> delete(@PathVariable Long id) {
|
memberPurchaseOrderAppService.delete(id);
|
return ApiResponse.ok(null);
|
}
|
}
|