/
post_gw.proto
316 lines (290 loc) · 7.36 KB
/
post_gw.proto
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
syntax = "proto3";
package api.community_gw.v1;
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "tagger/tagger.proto";
import "validate/validate.proto";
option go_package = "community_gw/api/community_gw/v1;v1";
// Default settings for generating swagger documents
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
host: "localhost:8080"
base_path: ""
info: {
title: "comment api docs";
version: "2.0";
}
schemes: HTTP;
schemes: HTTPS;
consumes: "application/json";
produces: "application/json";
security_definitions: {
security: {
key: "BearerAuth";
value: {
type: TYPE_API_KEY;
in: IN_HEADER;
name: "Authorization";
description: "Input a \"Bearer your-jwt-token\" to Value";
}
}
}
};
service PostService {
// 创建帖子
rpc Create (CreatePostRequest) returns (CreatePostReply) {
option (google.api.http) = {
post: "/api/v1/post"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "创建帖子",
description: "创建帖子",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 更新帖子内容
rpc UpdateContent (UpdatePostContentRequest) returns (UpdatePostContentReply) {
option (google.api.http) = {
put: "/api/v1/post/update"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "更新帖子内容",
description: "更新帖子内容",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 删除帖子
rpc Delete (DeletePostRequest) returns (DeletePostReply) {
option (google.api.http) = {
post: "/api/v1/post/delete"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "删除帖子",
description: "删除帖子",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 根据id获取帖子详情
rpc GetByID (GetPostByIDRequest) returns (GetPostByIDReply) {
option (google.api.http) = {
get: "/api/v1/post/{id}"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "获取帖子信息",
description: "获取帖子信息",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 用户发布过的帖子列表
rpc ListByUserID (ListPostByUserIDRequest) returns (ListPostByUserIDReply) {
option (google.api.http) = {
post: "/api/v1/post/user/list"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "用户发布过的帖子列表",
description: "用户发布过的帖子列表",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 最新的帖子列表
rpc ListLatest (ListPostLatestRequest) returns (ListPostLatestReply) {
option (google.api.http) = {
post: "/api/v1/post/latest/list"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "最新的帖子列表",
description: "最新的帖子列表",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 热门的帖子列表
rpc ListHot (ListPostHotRequest) returns (ListPostHotReply) {
option (google.api.http) = {
post: "/api/v1/post/hot/list"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "热门的帖子列表",
description: "热门的帖子列表",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 观看数量+1
rpc IncrViewCount (IncrPostViewCountRequest) returns (IncrPostViewCountReply) {
option (google.api.http) = {
post: "/api/v1/post/view"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "观看数量+1",
description: "观看数量+1",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
// 分享数量+1
rpc IncrShareCount (IncrPostShareCountRequest) returns (IncrPostShareCountReply) {
option (google.api.http) = {
post: "/api/v1/post/share"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "分享数量+1",
description: "分享数量+1",
security: {
security_requirement: {
key: "BearerAuth";
value: {}
}
}
};
}
}
message PostInfo {
uint64 id = 1;
int32 postType = 2;
uint64 userId = 3;
string title = 4;
string content = 5;
int64 viewCount = 6;
int64 likeCount = 7;
int64 commentCount = 8;
int64 collectCount = 9;
int64 shareCount = 10;
int32 delFlag = 11;
int32 visible = 12;
float longitude = 13;
float latitude = 14;
float position = 15;
int64 createdAt = 16;
int64 updatedAt = 17;
}
message CreatePostRequest {
uint64 userId = 1 [(validate.rules).uint64.gte = 1];
string title = 2 [(validate.rules).string.min_len = 1];
string text = 3;
string picKeys = 4;
string videoKey = 5;
int32 videoDuration = 6;
string coverKey = 7;
int32 coverWidth = 8;
int32 coverHeight = 9;
float longitude = 10;
float latitude = 11;
string position = 12;
}
message CreatePostReply {
PostInfo post = 1;
}
message UpdatePostContentRequest {
uint64 id = 1 [(validate.rules).uint64.gte = 1];
string title = 2 [(validate.rules).string.min_len = 1];
string text = 3;
string picKeys = 4;
string videoKey = 5;
int32 videoDuration = 6;
string coverKey = 7;
int32 coverWidth = 8;
int32 coverHeight = 9;
float longitude = 10;
float latitude = 11;
string position = 12;
}
message UpdatePostContentReply {}
message DeletePostRequest {
uint64 id = 1 [(validate.rules).uint64.gte = 1];
uint64 userId = 2 [(validate.rules).uint64.gte = 1];
int32 delFlag = 3 [(validate.rules).int32 = {gte:1, lte: 2}];
}
message DeletePostReply {
}
message GetPostByIDRequest {
uint64 id = 1 [(validate.rules).uint64.gte = 1, (tagger.tags) = "uri:\"id\"" ];
}
message GetPostByIDReply {
PostInfo post = 1;
}
message ListPostByIDsRequest {
repeated uint64 ids = 1 [(validate.rules).repeated = {min_items: 1, max_items: 100}];
}
message ListPostByIDsReply {
repeated PostInfo posts = 1;
}
message ListPostByUserIDRequest {
uint64 userId = 1 [(validate.rules).uint64.gte = 1];
int32 page = 2 [(validate.rules).int32.gte = 0];
int32 limit = 3 [(validate.rules).int32 = {gt:0, lte: 100}];
}
message ListPostByUserIDReply {
repeated PostInfo posts = 1;
int64 total = 2;
}
message ListPostLatestRequest {
int32 page = 1 [(validate.rules).int32.gte = 0];
int32 limit = 2 [(validate.rules).int32 = {gt:0, lte: 100}];
}
message ListPostLatestReply {
repeated PostInfo posts = 1;
int64 total = 2;
}
message ListPostHotRequest {
int32 page = 1 [(validate.rules).int32.gte = 0];
int32 limit = 2 [(validate.rules).int32 = {gt:0, lte: 100}];
}
message ListPostHotReply {
repeated PostInfo posts = 1;
int64 total = 2;
}
message IncrPostViewCountRequest {
uint64 id = 1 [(validate.rules).uint64.gte = 1];
uint64 userId = 2 [(validate.rules).uint64.gte = 1];
}
message IncrPostViewCountReply {}
message IncrPostShareCountRequest {
uint64 id = 1 [(validate.rules).uint64.gte = 1];
uint64 userId = 2 [(validate.rules).uint64.gte = 1];
}
message IncrPostShareCountReply {}