Skip to content

Commit 206f370

Browse files
author
maks2134
committed
create and generate proto files to GRPC
1 parent 35e3ee6 commit 206f370

File tree

11 files changed

+4232
-0
lines changed

11 files changed

+4232
-0
lines changed

proto/common.proto

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
syntax = "proto3";
2+
3+
package common;
4+
5+
option go_package = "mpb/proto/common";
6+
7+
message Error {
8+
string message = 1;
9+
string code = 2;
10+
}
11+
12+
message Empty {}
13+
14+
message Pagination {
15+
int32 page = 1;
16+
int32 page_size = 2;
17+
}
18+

proto/common/common.pb.go

Lines changed: 229 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/posts.proto

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
syntax = "proto3";
2+
3+
package posts;
4+
5+
option go_package = "mpb/proto/posts";
6+
7+
import "common.proto";
8+
9+
service PostsService {
10+
rpc CreatePost(CreatePostRequest) returns (PostResponse);
11+
rpc GetPost(GetPostRequest) returns (PostResponse);
12+
rpc ListPosts(ListPostsRequest) returns (ListPostsResponse);
13+
rpc UpdatePost(UpdatePostRequest) returns (PostResponse);
14+
rpc DeletePost(DeletePostRequest) returns (common.Empty);
15+
rpc LikePost(LikePostRequest) returns (LikePostResponse);
16+
rpc ViewPost(ViewPostRequest) returns (common.Empty);
17+
rpc GetPostMetrics(GetPostMetricsRequest) returns (PostMetricsResponse);
18+
}
19+
20+
service CommentsService {
21+
rpc CreateComment(CreateCommentRequest) returns (CommentResponse);
22+
rpc GetComment(GetCommentRequest) returns (CommentResponse);
23+
rpc ListComments(ListCommentsRequest) returns (ListCommentsResponse);
24+
rpc UpdateComment(UpdateCommentRequest) returns (CommentResponse);
25+
rpc DeleteComment(DeleteCommentRequest) returns (common.Empty);
26+
}
27+
28+
message Post {
29+
int32 id = 1;
30+
int32 user_id = 2;
31+
string title = 3;
32+
string description = 4;
33+
string tag = 5;
34+
int32 likes = 6;
35+
int32 views = 7;
36+
bool is_active = 8;
37+
string created_at = 9;
38+
string updated_at = 10;
39+
}
40+
41+
message CreatePostRequest {
42+
int32 user_id = 1;
43+
string title = 2;
44+
string description = 3;
45+
string tag = 4;
46+
}
47+
48+
message GetPostRequest {
49+
int32 post_id = 1;
50+
}
51+
52+
message ListPostsRequest {
53+
optional int32 user_id = 1;
54+
optional string tag = 2;
55+
bool only_active = 3;
56+
common.Pagination pagination = 4;
57+
}
58+
59+
message UpdatePostRequest {
60+
int32 post_id = 1;
61+
int32 user_id = 2;
62+
optional string title = 3;
63+
optional string description = 4;
64+
optional string tag = 5;
65+
}
66+
67+
message DeletePostRequest {
68+
int32 post_id = 1;
69+
int32 user_id = 2;
70+
}
71+
72+
message LikePostRequest {
73+
int32 post_id = 1;
74+
int32 user_id = 2;
75+
}
76+
77+
message LikePostResponse {
78+
bool liked = 1;
79+
int32 total_likes = 2;
80+
}
81+
82+
message ViewPostRequest {
83+
int32 post_id = 1;
84+
}
85+
86+
message GetPostMetricsRequest {
87+
int32 post_id = 1;
88+
}
89+
90+
message PostMetricsResponse {
91+
int32 likes = 1;
92+
int32 views = 2;
93+
}
94+
95+
message PostResponse {
96+
Post post = 1;
97+
}
98+
99+
message ListPostsResponse {
100+
repeated Post posts = 1;
101+
int32 total = 2;
102+
}
103+
104+
// Comment messages
105+
message Comment {
106+
int32 id = 1;
107+
int32 post_id = 2;
108+
int32 user_id = 3;
109+
string content = 4;
110+
string created_at = 5;
111+
string updated_at = 6;
112+
}
113+
114+
message CreateCommentRequest {
115+
int32 post_id = 1;
116+
int32 user_id = 2;
117+
string content = 3;
118+
}
119+
120+
message GetCommentRequest {
121+
int32 comment_id = 1;
122+
}
123+
124+
message ListCommentsRequest {
125+
int32 post_id = 1;
126+
common.Pagination pagination = 2;
127+
}
128+
129+
message UpdateCommentRequest {
130+
int32 comment_id = 1;
131+
int32 user_id = 2;
132+
string content = 3;
133+
}
134+
135+
message DeleteCommentRequest {
136+
int32 comment_id = 1;
137+
int32 user_id = 2;
138+
}
139+
140+
message CommentResponse {
141+
Comment comment = 1;
142+
}
143+
144+
message ListCommentsResponse {
145+
repeated Comment comments = 1;
146+
int32 total = 2;
147+
}
148+

0 commit comments

Comments
 (0)