Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
git test
Jpress
Commits
576dcaea
Commit
576dcaea
authored
3 years ago
by
yangfuhai
Browse files
Options
Download
Email Patches
Plain Diff
完善产品、购物车、优惠券的相关 API
parent
b767e749
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
jpress-service/src/main/java/io/jpress/service/UserCartService.java
+3
-0
...vice/src/main/java/io/jpress/service/UserCartService.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/ProductApiController.java
+13
-11
...s/module/product/controller/api/ProductApiController.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/ProductCategoryApiController.java
+12
-11
.../product/controller/api/ProductCategoryApiController.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserAddressApiController.java
+27
-29
...dule/product/controller/api/UserAddressApiController.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserCartApiController.java
+22
-12
.../module/product/controller/api/UserCartApiController.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserCouponApiController.java
+28
-1
...odule/product/controller/api/UserCouponApiController.java
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserOrderApiController.java
+25
-20
...module/product/controller/api/UserOrderApiController.java
with
130 additions
and
84 deletions
+130
-84
jpress-service/src/main/java/io/jpress/service/UserCartService.java
+
3
-
0
View file @
576dcaea
...
...
@@ -32,6 +32,9 @@ public interface UserCartService {
boolean
delete
(
UserCart
model
);
boolean
deleteById
(
Object
id
);
/**
* 新增 Model 数据
*
...
...
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/ProductApiController.java
+
13
-
11
View file @
576dcaea
...
...
@@ -97,25 +97,27 @@ public class ProductApiController extends ApiControllerBase {
}
/**
* 创建新的产品
* @param article
* @return
* 删除商品
*/
public
Ret
create
(
@JsonBody
@NotNull
Product
article
)
{
productService
.
save
(
article
);
public
Ret
doDelete
(
@NotNull
Long
id
)
{
productService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
* 新增商品
*/
public
Ret
doCreate
(
@JsonBody
Product
product
)
{
Object
id
=
productService
.
save
(
product
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
* 更新产品
* @param article
* @return
* 更新商品
*/
public
Ret
u
pdate
(
@JsonBody
@NotNull
Product
article
)
{
productService
.
update
(
article
);
public
Ret
doU
pdate
(
@JsonBody
Product
product
)
{
productService
.
update
(
product
);
return
Rets
.
OK
;
}
...
...
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/ProductCategoryApiController.java
+
12
-
11
View file @
576dcaea
...
...
@@ -46,24 +46,25 @@ public class ProductCategoryApiController extends ApiControllerBase {
/**
* 创建新的产品
*
* @param productCategory
* @return
* 删除商品分类
*/
public
Ret
create
(
@JsonBody
@NotNull
ProductCategory
productCategory
)
{
productCategoryService
.
save
(
productCategory
);
public
Ret
doDelete
(
@NotNull
Long
id
)
{
productCategoryService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
* 新增商品分类
*/
public
Ret
doCreate
(
@JsonBody
ProductCategory
productCategory
)
{
Object
id
=
productCategoryService
.
save
(
productCategory
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
* 更新产品
*
* @param productCategory
* @return
* 更新商品分类
*/
public
Ret
u
pdate
(
@JsonBody
@NotNull
ProductCategory
productCategory
)
{
public
Ret
doU
pdate
(
@JsonBody
ProductCategory
productCategory
)
{
productCategoryService
.
update
(
productCategory
);
return
Rets
.
OK
;
}
...
...
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserAddressApiController.java
+
27
-
29
View file @
576dcaea
...
...
@@ -18,12 +18,13 @@ package io.jpress.module.product.controller.api;
import
com.jfinal.aop.Inject
;
import
com.jfinal.kit.Ret
;
import
io.jboot.web.controller.annotation.RequestMapping
;
import
io.jboot.web.
validate.EmptyValidate
;
import
io.j
boot.web.validate.Form
;
import
io.jboot.web.
json.JsonBody
;
import
io.j
press.commons.Rets
;
import
io.jpress.model.UserAddress
;
import
io.jpress.service.UserAddressService
;
import
io.jpress.web.base.ApiControllerBase
;
import
javax.validation.constraints.NotNull
;
import
java.util.List
;
/**
...
...
@@ -40,52 +41,49 @@ public class UserAddressApiController extends ApiControllerBase {
/**
* 收货地址列表
*/
public
void
detail
()
{
List
<
UserAddress
>
addresses
=
userAddressService
.
findListByUserId
(
getLoginedUser
().
getId
());
renderOkJson
(
"data"
,
addresses
);
public
Ret
detail
(
@NotNull
Long
id
)
{
return
Ret
.
ok
().
set
(
"address"
,
userAddressService
.
findById
(
id
));
}
/**
* 收货地址列表
*/
public
void
listByUserId
()
{
List
<
UserAddress
>
addresses
=
userAddressService
.
findListByUserId
(
getLoginedUser
().
getId
()
);
re
nderOkJson
(
"data
"
,
addresses
);
public
Ret
listByUserId
(
@NotNull
Long
userId
)
{
List
<
UserAddress
>
addresses
=
userAddressService
.
findListByUserId
(
userId
);
re
turn
Ret
.
ok
().
set
(
"addresses
"
,
addresses
);
}
/**
*
删除
收货地址
*
获取用户默认的
收货地址
*/
@EmptyValidate
({
@Form
(
name
=
"id"
,
message
=
"收货地址ID不能为空"
)})
public
void
doDelUserAddress
(
Long
id
)
{
UserAddress
address
=
userAddressService
.
findById
(
id
);
if
(
isLoginedUserModel
(
address
))
{
userAddressService
.
delete
(
address
);
}
renderOkJson
();
public
Ret
findUserDefaultAddress
(
@NotNull
Long
userId
)
{
return
Ret
.
ok
(
"address"
,
userAddressService
.
findDefaultAddress
(
userId
));
}
/**
*
添加收货
地址
*
删除用户
地址
*/
@EmptyValidate
({
@Form
(
name
=
"address.username"
,
message
=
"请填写联系人"
),
@Form
(
name
=
"address.mobile"
,
message
=
"请填写联系方式"
),
@Form
(
name
=
"address.detail"
,
message
=
"请填写联系地址"
),
})
public
void
doAddUserAddress
()
{
UserAddress
address
=
getBean
(
UserAddress
.
class
,
"address"
);
userAddressService
.
addUserAddress
(
address
,
getLoginedUser
().
getId
());
renderJson
(
Ret
.
ok
());
public
Ret
doDelete
(
@NotNull
Long
id
)
{
userAddressService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
* 新增用户地址
*/
public
Ret
doCreate
(
@JsonBody
UserAddress
userAddress
)
{
Object
id
=
userAddressService
.
save
(
userAddress
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
*
获取用户默认的收货
地址
*
更新用户
地址
*/
public
void
findDefaultAddress
()
{
renderOkJson
(
"data"
,
userAddressService
.
findDefaultAddress
(
getLoginedUser
().
getId
()));
public
Ret
doUpdate
(
@JsonBody
UserAddress
userAddress
)
{
userAddressService
.
update
(
userAddress
);
return
Rets
.
OK
;
}
...
...
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserCarApiController.java
→
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserCar
t
ApiController.java
+
22
-
12
View file @
576dcaea
...
...
@@ -15,45 +15,55 @@
*/
package
io.jpress.module.product.controller.api
;
import
com.jfinal.kit.Ret
;
import
io.jboot.web.controller.annotation.RequestMapping
;
import
io.jboot.web.json.JsonBody
;
import
io.jpress.commons.Rets
;
import
io.jpress.model.UserCart
;
import
io.jpress.service.UserCartService
;
import
io.jpress.web.base.ApiControllerBase
;
import
javax.validation.constraints.NotNull
;
/**
* @author haicuan139 (haicuan139@163.com)
* @Date: 2019/12/24
*/
@RequestMapping
(
"/api/usercar"
)
public
class
UserCarApiController
extends
ApiControllerBase
{
@RequestMapping
(
"/api/userCart"
)
public
class
UserCartApiController
extends
ApiControllerBase
{
private
UserCartService
userCartService
;
/**
* 购物车列表
*/
public
void
index
(
){
public
Ret
listByUser
(
@NotNull
Long
userId
){
return
Ret
.
ok
().
set
(
"list"
,
userCartService
.
findListByUserId
(
userId
));
}
/**
* 购物车中删除
*/
public
void
doDelCar
(){
public
Ret
doDelete
(
@NotNull
Long
id
){
userCartService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
* 添加到购物车
*/
public
void
doAddCar
(){
public
Ret
doCreate
(
@JsonBody
UserCart
userCart
){
Object
id
=
userCartService
.
save
(
userCart
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
* 改变购物车中商品的数量
*/
public
void
changeCount
(){
public
Ret
doUpdate
(
@JsonBody
UserCart
userCart
){
userCartService
.
update
(
userCart
);
return
Rets
.
OK
;
}
}
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserCouponApiController.java
+
28
-
1
View file @
576dcaea
...
...
@@ -16,11 +16,15 @@
package
io.jpress.module.product.controller.api
;
import
com.jfinal.aop.Inject
;
import
com.jfinal.kit.Ret
;
import
io.jboot.web.controller.annotation.RequestMapping
;
import
io.jboot.web.json.JsonBody
;
import
io.jpress.commons.Rets
;
import
io.jpress.model.CouponCode
;
import
io.jpress.service.CouponCodeService
;
import
io.jpress.web.base.ApiControllerBase
;
import
javax.validation.constraints.NotNull
;
import
java.math.BigDecimal
;
import
java.util.List
;
...
...
@@ -28,7 +32,7 @@ import java.util.List;
* @author haicuan139 (haicuan139@163.com)
* @Date: 2019/12/24
*/
@RequestMapping
(
"/api/user
c
oupon"
)
@RequestMapping
(
"/api/user
C
oupon"
)
public
class
UserCouponApiController
extends
ApiControllerBase
{
@Inject
...
...
@@ -51,6 +55,29 @@ public class UserCouponApiController extends ApiControllerBase {
renderOkDataJson
(
couponCodes
);
}
/**
* 购物车中删除
*/
public
Ret
doDelete
(
@NotNull
Long
id
)
{
couponCodeService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
* 添加到购物车
*/
public
Ret
doCreate
(
@JsonBody
CouponCode
couponCode
)
{
Object
id
=
couponCodeService
.
save
(
couponCode
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
* 改变购物车中商品的数量
*/
public
Ret
doUpdate
(
@JsonBody
CouponCode
couponCode
)
{
couponCodeService
.
update
(
couponCode
);
return
Rets
.
OK
;
}
}
This diff is collapsed.
Click to expand it.
module-product/module-product-web/src/main/java/io/jpress/module/product/controller/api/UserOrderApiController.java
+
25
-
20
View file @
576dcaea
...
...
@@ -15,52 +15,57 @@
*/
package
io.jpress.module.product.controller.api
;
import
com.jfinal.kit.Ret
;
import
io.jboot.aop.annotation.DefaultValue
;
import
io.jboot.web.controller.annotation.RequestMapping
;
import
io.jboot.web.json.JsonBody
;
import
io.jpress.commons.Rets
;
import
io.jpress.model.UserOrder
;
import
io.jpress.service.UserOrderService
;
import
io.jpress.web.base.ApiControllerBase
;
import
javax.validation.constraints.NotNull
;
/**
* @author haicuan139 (haicuan139@163.com)
* @Date: 2019/12/24
*/
@RequestMapping
(
"/api/user
o
rder"
)
@RequestMapping
(
"/api/user
O
rder"
)
public
class
UserOrderApiController
extends
ApiControllerBase
{
/**
* 订单列表
*/
public
void
index
(){
}
private
UserOrderService
userOrderService
;
/**
*
添加到订单
*
购物车列表
*/
public
void
doDelOrder
()
{
public
Ret
paginateByUserId
(
@DefaultValue
(
"1"
)
int
pageNumber
,
@DefaultValue
(
"10"
)
int
pageSize
,
@NotNull
Long
userId
,
String
title
,
String
ns
)
{
return
Ret
.
ok
().
set
(
"page"
,
userOrderService
.
paginateByUserId
(
pageNumber
,
pageSize
,
userId
,
title
,
ns
));
}
/**
*
订单
中删除
*
购物车
中删除
*/
public
void
doCreateOrder
(){
public
Ret
doDelete
(
@NotNull
Long
id
)
{
userOrderService
.
deleteById
(
id
);
return
Rets
.
OK
;
}
/**
*
改变订单中商品的数量
*
添加到购物车
*/
public
void
changeCount
(){
public
Ret
doCreate
(
@JsonBody
UserOrder
userOrder
)
{
Object
id
=
userOrderService
.
save
(
userOrder
);
return
Ret
.
ok
().
set
(
"id"
,
id
);
}
/**
*
对订单进行支付
*
改变购物车中商品的数量
*/
public
void
payOrder
(){
public
Ret
doUpdate
(
@JsonBody
UserOrder
userOrder
)
{
userOrderService
.
update
(
userOrder
);
return
Rets
.
OK
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment