提交 4f855b05 authored 作者: Whispa's avatar Whispa

commit

上级 9fc6a01d
...@@ -54,8 +54,26 @@ public class AddressController extends Controller{ ...@@ -54,8 +54,26 @@ public class AddressController extends Controller{
@PutMapping("/{addressId}") @PutMapping("/{addressId}")
public Result editAddressInfo(@PathVariable("addressId") String addressId,@RequestBody TbCfAddress address) { public Result editAddressInfo(@PathVariable("addressId") String addressId,@RequestBody TbCfAddress address) {
address.setUserId(user.userId());
ResultCodeEnum e = ResultCodeEnum.VALIDATE_ERROR;
if( !repository.existsById(addressId) )
return new Result(e.getCode(),"Address doesn't exist");
String userId = user.userId();
if( address == null )
return new Result(e.getCode(),e.getDesc());
if( address.getAddressDetail() == null || address.getAddressDetail().trim().isEmpty())
return new Result(e.getCode(),"Address is required");
if( address.getDeliveryName() == null || address.getDeliveryName().trim().isEmpty())
return new Result(e.getCode(),"Delivery name is required");
if( address.getPhone() == null || address.getPhone().trim().isEmpty())
return new Result(e.getCode(),"Phone is required");
if( repository.existsByAddressDetailAndUserIdAndAddressIdIsNot(address.getAddressDetail(), userId,addressId))
return new Result(e.getCode(),"Address already existed");
address.setAddressId(addressId); address.setAddressId(addressId);
address.setUserId(userId);
return new Result<>(repository.save(address)); return new Result<>(repository.save(address));
} }
......
...@@ -18,4 +18,6 @@ public interface TbCfAddressRepository extends PagingAndSortingRepository<TbCfAd ...@@ -18,4 +18,6 @@ public interface TbCfAddressRepository extends PagingAndSortingRepository<TbCfAd
void resetToDefault(@Param("user_id") String userId); void resetToDefault(@Param("user_id") String userId);
boolean existsByAddressDetailAndUserId(String addressDetail, String userId); boolean existsByAddressDetailAndUserId(String addressDetail, String userId);
boolean existsByAddressDetailAndUserIdAndAddressIdIsNot(String addressDetail, String userId, String addressId);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论