resource 就1行代码调用service 层, 看着就舒服、漂亮、美

写在serivce 层方面 单元测试
前置校验在service 层,不再resource,也不在Dao ,可以避免重复检验

resoucre 层 没有 compoment 注解, spring 不会自动装配, 所以有些依赖Spring 的会执行不上。service没有问题 (应该是会自动装配,装配serivce,待调查)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
*/
@Path("/v1/mini_app")
public class MiniAppResource {

@Autowired
MiniAppService miniAppService;

@Path("add.json")
@POST
@Produces(MediaType.APPLICATION_JSON)
@BaseInfo(
idx = 1,
desc = "往小程序购物车中添加一种商品",
protocol = BaseInfo.Protocol.HTTPS,
authPolicy = BaseInfo.AuthPolicy.PUBLIC,
apiStatus = BaseInfo.ApiStatus.PUBLIC
)
public ApiCartProduct add(
@FormParam("sub_product_id")
long subProductId,
@FormParam("count")
int count,
@FormParam("device_token")
String deviceToken,
@HeaderParam("from_user_id")
Long fromUserId
) {
return miniAppService.add(subProductId, count, fromUserId, deviceToken);
}

@Path("delete.json")
@POST
@Produces(MediaType.APPLICATION_JSON)
@BaseInfo(
idx = 2,
desc = "批量删除购物车中商品",
protocol = BaseInfo.Protocol.HTTPS,
authPolicy = BaseInfo.AuthPolicy.PUBLIC,
apiStatus = BaseInfo.ApiStatus.PUBLIC,
resultDemo = CommonResult.class)
public CommonResult delete(
@FormParam("sub_product_id")
String subProductIdStr,
@FormParam("device_token")
String deviceToken,
@HeaderParam("from_user_id")
Long fromUserId
) {
return CommonResult.booleanCommonResult(
miniAppService.remove(fromUserId, deviceToken, subProductIdStr));
}

@Path("update.json")
@POST
@Produces(MediaType.APPLICATION_JSON)
@BaseInfo(
idx = 3,
desc = "更新购物车",
protocol = BaseInfo.Protocol.HTTPS,
authPolicy = BaseInfo.AuthPolicy.PUBLIC,
apiStatus = BaseInfo.ApiStatus.PUBLIC,
resultDemo = CommonResult.class)
public CommonResult update(
@FormParam("meta")
String metaStr,
@FormParam("device_token")
String deviceToken,
@HeaderParam("from_user_id")
Long fromUserId
) {
return CommonResult.booleanCommonResult(
miniAppService.update(fromUserId, deviceToken, metaStr));
}

}