提交 9fc6a01d authored 作者: Whispa's avatar Whispa

commit

上级 699c184f
...@@ -34,6 +34,7 @@ public class AddressController extends Controller{ ...@@ -34,6 +34,7 @@ public class AddressController extends Controller{
@PostMapping @PostMapping
public Result addUserInfo(@RequestBody TbCfAddress address) { public Result addUserInfo(@RequestBody TbCfAddress address) {
ResultCodeEnum e = ResultCodeEnum.VALIDATE_ERROR; ResultCodeEnum e = ResultCodeEnum.VALIDATE_ERROR;
String userId = user.userId();
if( address == null ) if( address == null )
return new Result(e.getCode(),e.getDesc()); return new Result(e.getCode(),e.getDesc());
if( address.getAddressDetail() == null || address.getAddressDetail().trim().isEmpty()) if( address.getAddressDetail() == null || address.getAddressDetail().trim().isEmpty())
...@@ -42,11 +43,11 @@ public class AddressController extends Controller{ ...@@ -42,11 +43,11 @@ public class AddressController extends Controller{
return new Result(e.getCode(),"Delivery name is required"); return new Result(e.getCode(),"Delivery name is required");
if( address.getPhone() == null || address.getPhone().trim().isEmpty()) if( address.getPhone() == null || address.getPhone().trim().isEmpty())
return new Result(e.getCode(),"Phone is required"); return new Result(e.getCode(),"Phone is required");
if( repository.existsByAddressDetail(address.getAddressDetail())) if( repository.existsByAddressDetailAndUserId(address.getAddressDetail(), userId))
return new Result(e.getCode(),"Address already existed"); return new Result(e.getCode(),"Address already existed");
address.setUserId(user.userId()); address.setUserId(userId);
address.setAddressId(uid()); address.setAddressId(uid());
return new Result<>(repository.save(address)); return new Result<>(repository.save(address));
} }
......
...@@ -17,5 +17,5 @@ public interface TbCfAddressRepository extends PagingAndSortingRepository<TbCfAd ...@@ -17,5 +17,5 @@ public interface TbCfAddressRepository extends PagingAndSortingRepository<TbCfAd
@Query(value = "update tb_cf_address set default_flag=0 where user_id=:user_id",nativeQuery = true) @Query(value = "update tb_cf_address set default_flag=0 where user_id=:user_id",nativeQuery = true)
void resetToDefault(@Param("user_id") String userId); void resetToDefault(@Param("user_id") String userId);
boolean existsByAddressDetail(String deliveryName); boolean existsByAddressDetailAndUserId(String addressDetail, String userId);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论