user_service.proto 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. syntax = "proto3";
  2. package memos.api.v1;
  3. import "api/v1/common.proto";
  4. import "google/api/annotations.proto";
  5. import "google/api/client.proto";
  6. import "google/api/field_behavior.proto";
  7. import "google/api/httpbody.proto";
  8. import "google/protobuf/empty.proto";
  9. import "google/protobuf/field_mask.proto";
  10. import "google/protobuf/timestamp.proto";
  11. option go_package = "gen/api/v1";
  12. service UserService {
  13. // ListUsers returns a list of users.
  14. rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) {
  15. option (google.api.http) = {get: "/api/v1/users"};
  16. }
  17. // GetUser gets a user by name.
  18. rpc GetUser(GetUserRequest) returns (User) {
  19. option (google.api.http) = {get: "/api/v1/{name=users/*}"};
  20. option (google.api.method_signature) = "name";
  21. }
  22. // GetUserByUsername gets a user by username.
  23. rpc GetUserByUsername(GetUserByUsernameRequest) returns (User) {
  24. option (google.api.http) = {get: "/api/v1/users:username"};
  25. option (google.api.method_signature) = "username";
  26. }
  27. // GetUserAvatarBinary gets the avatar of a user.
  28. rpc GetUserAvatarBinary(GetUserAvatarBinaryRequest) returns (google.api.HttpBody) {
  29. option (google.api.http) = {get: "/file/{name=users/*}/avatar"};
  30. option (google.api.method_signature) = "name";
  31. }
  32. // CreateUser creates a new user.
  33. rpc CreateUser(CreateUserRequest) returns (User) {
  34. option (google.api.http) = {
  35. post: "/api/v1/users"
  36. body: "user"
  37. };
  38. option (google.api.method_signature) = "user";
  39. }
  40. // UpdateUser updates a user.
  41. rpc UpdateUser(UpdateUserRequest) returns (User) {
  42. option (google.api.http) = {
  43. patch: "/api/v1/{user.name=users/*}"
  44. body: "user"
  45. };
  46. option (google.api.method_signature) = "user,update_mask";
  47. }
  48. // DeleteUser deletes a user.
  49. rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty) {
  50. option (google.api.http) = {delete: "/api/v1/{name=users/*}"};
  51. option (google.api.method_signature) = "name";
  52. }
  53. // ListAllUserStats returns all user stats.
  54. rpc ListAllUserStats(ListAllUserStatsRequest) returns (ListAllUserStatsResponse) {
  55. option (google.api.http) = {post: "/api/v1/users/-/stats"};
  56. }
  57. // GetUserStats returns the stats of a user.
  58. rpc GetUserStats(GetUserStatsRequest) returns (UserStats) {
  59. option (google.api.http) = {get: "/api/v1/{name=users/*}/stats"};
  60. option (google.api.method_signature) = "name";
  61. }
  62. // GetUserSetting gets the setting of a user.
  63. rpc GetUserSetting(GetUserSettingRequest) returns (UserSetting) {
  64. option (google.api.http) = {get: "/api/v1/{name=users/*}/setting"};
  65. option (google.api.method_signature) = "name";
  66. }
  67. // UpdateUserSetting updates the setting of a user.
  68. rpc UpdateUserSetting(UpdateUserSettingRequest) returns (UserSetting) {
  69. option (google.api.http) = {
  70. patch: "/api/v1/{setting.name=users/*/setting}"
  71. body: "setting"
  72. };
  73. option (google.api.method_signature) = "setting,update_mask";
  74. }
  75. // ListUserAccessTokens returns a list of access tokens for a user.
  76. rpc ListUserAccessTokens(ListUserAccessTokensRequest) returns (ListUserAccessTokensResponse) {
  77. option (google.api.http) = {get: "/api/v1/{name=users/*}/access_tokens"};
  78. option (google.api.method_signature) = "name";
  79. }
  80. // CreateUserAccessToken creates a new access token for a user.
  81. rpc CreateUserAccessToken(CreateUserAccessTokenRequest) returns (UserAccessToken) {
  82. option (google.api.http) = {
  83. post: "/api/v1/{name=users/*}/access_tokens"
  84. body: "*"
  85. };
  86. option (google.api.method_signature) = "name";
  87. }
  88. // DeleteUserAccessToken deletes an access token for a user.
  89. rpc DeleteUserAccessToken(DeleteUserAccessTokenRequest) returns (google.protobuf.Empty) {
  90. option (google.api.http) = {delete: "/api/v1/{name=users/*}/access_tokens/{access_token}"};
  91. option (google.api.method_signature) = "name,access_token";
  92. }
  93. // ListShortcuts returns a list of shortcuts for a user.
  94. rpc ListShortcuts(ListShortcutsRequest) returns (ListShortcutsResponse) {
  95. option (google.api.http) = {get: "/api/v1/{parent=users/*}/shortcuts"};
  96. option (google.api.method_signature) = "parent";
  97. }
  98. // CreateShortcut creates a new shortcut for a user.
  99. rpc CreateShortcut(CreateShortcutRequest) returns (Shortcut) {
  100. option (google.api.http) = {
  101. post: "/api/v1/{parent=users/*}/shortcuts"
  102. body: "shortcut"
  103. };
  104. option (google.api.method_signature) = "parent,shortcut";
  105. }
  106. // UpdateShortcut updates a shortcut for a user.
  107. rpc UpdateShortcut(UpdateShortcutRequest) returns (Shortcut) {
  108. option (google.api.http) = {
  109. patch: "/api/v1/{parent=users/*}/shortcuts/{shortcut.id}"
  110. body: "shortcut"
  111. };
  112. option (google.api.method_signature) = "parent,shortcut,update_mask";
  113. }
  114. // DeleteShortcut deletes a shortcut for a user.
  115. rpc DeleteShortcut(DeleteShortcutRequest) returns (google.protobuf.Empty) {
  116. option (google.api.http) = {delete: "/api/v1/{parent=users/*}/shortcuts/{id}"};
  117. option (google.api.method_signature) = "parent,id";
  118. }
  119. }
  120. message User {
  121. // The name of the user.
  122. // Format: users/{id}, id is the system generated auto-incremented id.
  123. string name = 1;
  124. enum Role {
  125. ROLE_UNSPECIFIED = 0;
  126. HOST = 1;
  127. ADMIN = 2;
  128. USER = 3;
  129. }
  130. Role role = 3;
  131. string username = 4;
  132. string email = 5;
  133. string nickname = 6;
  134. string avatar_url = 7;
  135. string description = 8;
  136. string password = 9 [(google.api.field_behavior) = INPUT_ONLY];
  137. State state = 10;
  138. google.protobuf.Timestamp create_time = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
  139. google.protobuf.Timestamp update_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
  140. }
  141. message ListUsersRequest {}
  142. message ListUsersResponse {
  143. repeated User users = 1;
  144. }
  145. message GetUserRequest {
  146. // The name of the user.
  147. string name = 1;
  148. }
  149. message GetUserByUsernameRequest {
  150. // The username of the user.
  151. string username = 1;
  152. }
  153. message GetUserAvatarBinaryRequest {
  154. // The name of the user.
  155. string name = 1;
  156. // The raw HTTP body is bound to this field.
  157. google.api.HttpBody http_body = 2;
  158. }
  159. message CreateUserRequest {
  160. User user = 1;
  161. }
  162. message UpdateUserRequest {
  163. User user = 1 [(google.api.field_behavior) = REQUIRED];
  164. google.protobuf.FieldMask update_mask = 2;
  165. }
  166. message DeleteUserRequest {
  167. // The name of the user.
  168. string name = 1;
  169. }
  170. message UserStats {
  171. // The name of the user.
  172. string name = 1;
  173. // The timestamps when the memos were displayed.
  174. // We should return raw data to the client, and let the client format the data with the user's timezone.
  175. repeated google.protobuf.Timestamp memo_display_timestamps = 2;
  176. // The stats of memo types.
  177. MemoTypeStats memo_type_stats = 3;
  178. // The count of tags.
  179. // Format: "tag1": 1, "tag2": 2
  180. map<string, int32> tag_count = 4;
  181. message MemoTypeStats {
  182. int32 link_count = 1;
  183. int32 code_count = 2;
  184. int32 todo_count = 3;
  185. int32 undo_count = 4;
  186. }
  187. }
  188. message ListAllUserStatsRequest {}
  189. message ListAllUserStatsResponse {
  190. repeated UserStats user_stats = 1;
  191. }
  192. message GetUserStatsRequest {
  193. // The name of the user.
  194. string name = 1;
  195. }
  196. message UserSetting {
  197. // The name of the user.
  198. string name = 1;
  199. // The preferred locale of the user.
  200. string locale = 2;
  201. // The preferred appearance of the user.
  202. string appearance = 3;
  203. // The default visibility of the memo.
  204. string memo_visibility = 4;
  205. }
  206. message GetUserSettingRequest {
  207. // The name of the user.
  208. string name = 1;
  209. }
  210. message UpdateUserSettingRequest {
  211. UserSetting setting = 1 [(google.api.field_behavior) = REQUIRED];
  212. google.protobuf.FieldMask update_mask = 2;
  213. }
  214. message UserAccessToken {
  215. string access_token = 1;
  216. string description = 2;
  217. google.protobuf.Timestamp issued_at = 3;
  218. google.protobuf.Timestamp expires_at = 4;
  219. }
  220. message ListUserAccessTokensRequest {
  221. // The name of the user.
  222. string name = 1;
  223. }
  224. message ListUserAccessTokensResponse {
  225. repeated UserAccessToken access_tokens = 1;
  226. }
  227. message CreateUserAccessTokenRequest {
  228. // The name of the user.
  229. string name = 1;
  230. string description = 2;
  231. optional google.protobuf.Timestamp expires_at = 3;
  232. }
  233. message DeleteUserAccessTokenRequest {
  234. // The name of the user.
  235. string name = 1;
  236. // access_token is the access token to delete.
  237. string access_token = 2;
  238. }
  239. message Shortcut {
  240. string id = 1;
  241. string title = 2;
  242. string filter = 3;
  243. }
  244. message ListShortcutsRequest {
  245. // The name of the user.
  246. string parent = 1;
  247. }
  248. message ListShortcutsResponse {
  249. repeated Shortcut shortcuts = 1;
  250. }
  251. message CreateShortcutRequest {
  252. // The name of the user.
  253. string parent = 1;
  254. Shortcut shortcut = 2;
  255. bool validate_only = 3;
  256. }
  257. message UpdateShortcutRequest {
  258. // The name of the user.
  259. string parent = 1;
  260. Shortcut shortcut = 2;
  261. google.protobuf.FieldMask update_mask = 3;
  262. }
  263. message DeleteShortcutRequest {
  264. // The name of the user.
  265. string parent = 1;
  266. // The id of the shortcut.
  267. string id = 2;
  268. }