59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
|
|
package com.xjhs.findmemerchant.controller;
|
||
|
|
|
||
|
|
import com.xjhs.findmemerchant.common.ApiResult;
|
||
|
|
import com.xjhs.findmemerchant.dto.MerchantDto;
|
||
|
|
import com.xjhs.findmemerchant.entity.Merchant;
|
||
|
|
import com.xjhs.findmemerchant.service.MerchantService;
|
||
|
|
import com.xjhs.findmemerchant.vo.merchant.MerchantUpdateVo;
|
||
|
|
import com.xjhs.findmemerchant.vo.merchant.MerchantVerifyVo;
|
||
|
|
import jakarta.validation.Valid;
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
import java.security.Principal;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/merchant")
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
public class MerchantController {
|
||
|
|
private final MerchantService merchantService;
|
||
|
|
|
||
|
|
@GetMapping
|
||
|
|
public ApiResult<MerchantDto> getMerchant(Principal principal) {
|
||
|
|
if (principal instanceof Merchant merchant) {
|
||
|
|
return this.merchantService.getById(merchant.getId())
|
||
|
|
.map(ApiResult::data)
|
||
|
|
.orElse(ApiResult.fail("商户信息不存在"));
|
||
|
|
}
|
||
|
|
return ApiResult.fail("商户信息不存在");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping
|
||
|
|
public ApiResult<MerchantDto> updateMerchant(Principal principal,@Valid @RequestBody MerchantUpdateVo merchantUpdateVo) {
|
||
|
|
if (principal instanceof Merchant merchant) {
|
||
|
|
try {
|
||
|
|
var dto = this.merchantService.updateMerchant(merchant.getId(),merchantUpdateVo);
|
||
|
|
return ApiResult.data(dto);
|
||
|
|
} catch (Exception e) {
|
||
|
|
return ApiResult.fail(e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return ApiResult.fail("商户信息不存在");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/verify")
|
||
|
|
public ApiResult<MerchantDto> verifyMerchant(Principal principal,@Valid @RequestBody MerchantVerifyVo merchantVerifyVo) {
|
||
|
|
if (principal instanceof Merchant merchant) {
|
||
|
|
try {
|
||
|
|
var dto = this.merchantService.verifyMerchant(merchant.getId(),merchantVerifyVo.getIdCardNo(),merchantVerifyVo.getRealName());
|
||
|
|
return ApiResult.data(dto);
|
||
|
|
} catch (Exception e) {
|
||
|
|
return ApiResult.fail(e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return ApiResult.fail("商户信息不存在");
|
||
|
|
}
|
||
|
|
}
|