[hw-8] add: comment service

This commit is contained in:
3ybacTuK
2025-07-26 23:47:18 +03:00
parent 6420eaf3d7
commit 6e0d90a6d5
29 changed files with 1249 additions and 725 deletions

View File

@@ -1,6 +1,7 @@
syntax = "proto3";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "validate/validate.proto";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
@@ -24,27 +25,28 @@ message Comment {
int64 user_id = 2 [(validate.rules).int64 = {gt: 0}];
int64 sku = 3 [(validate.rules).int64 = {gt: 0}];
string text = 4 [(validate.rules).string = {min_len:1, max_len:255}];
string created_at = 5; // RFC3339 with ms
google.protobuf.Timestamp created_at = 5;
}
message CreateCommentRequest {
int64 user_id = 1 [(validate.rules).int64 = {gt: 0}];
int64 sku = 2 [(validate.rules).int64 = {gt: 0}];
string text = 3 [(validate.rules).string = {min_len:1, max_len:255}];
int64 user_id = 1 [(validate.rules).int64 = {gt: 0}];
int64 sku = 2 [(validate.rules).int64 = {gt: 0}];
string comment = 3 [(validate.rules).string = {min_len:1, max_len:255}];
}
message CreateCommentResponse {
int64 id = 1;
}
message CreateCommentResponse { Comment comment = 1; }
message GetCommentRequest {
int64 id = 1 [(validate.rules).int64 = {gt:0}];
}
message GetCommentResponse { Comment comment = 1; }
message UpdateCommentRequest {
int64 id = 1 [(validate.rules).int64 = {gt:0}];
int64 user_id = 2 [(validate.rules).int64 = {gt: 0}];
string text = 3 [(validate.rules).string = {min_len:1, max_len:255}];
message EditCommentRequest {
int64 user_id = 1 [(validate.rules).int64 = {gt:0}];
int64 comment_id = 2 [(validate.rules).int64 = {gt: 0}];
string new_comment = 3 [(validate.rules).string = {min_len:1, max_len:255}];
}
message UpdateCommentResponse { Comment comment = 1; }
message ListBySkuRequest {
int64 sku = 1 [(validate.rules).int64 = {gt:0}];
@@ -65,35 +67,35 @@ service Comments {
}
};
rpc Add(CreateCommentRequest) returns (CreateCommentResponse) {
rpc CommentAdd(CreateCommentRequest) returns (CreateCommentResponse) {
option (google.api.http) = {
post: "/comment/add"
body: "*"
};
}
rpc GetById(GetCommentRequest) returns (GetCommentResponse) {
rpc CommentGetByID(GetCommentRequest) returns (GetCommentResponse) {
option (google.api.http) = {
post: "/comment/get-by-id"
body: "*"
};
}
rpc Edit(UpdateCommentRequest) returns (UpdateCommentResponse) {
rpc CommentEdit(EditCommentRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/comment/edit"
body: "*"
};
}
rpc ListBySku(ListBySkuRequest) returns (ListBySkuResponse) {
rpc CommentListBySKU(ListBySkuRequest) returns (ListBySkuResponse) {
option (google.api.http) = {
post: "/comment/list-by-sku"
body: "*"
};
}
rpc ListByUser(ListByUserRequest) returns (ListByUserResponse) {
rpc CommentListByUser(ListByUserRequest) returns (ListByUserResponse) {
option (google.api.http) = {
post: "/comment/list-by-user"
body: "*"

View File

@@ -27,7 +27,7 @@
"paths": {
"/comment/add": {
"post": {
"operationId": "Comments_Add",
"operationId": "Comments_CommentAdd",
"responses": {
"200": {
"description": "A successful response.",
@@ -59,12 +59,13 @@
},
"/comment/edit": {
"post": {
"operationId": "Comments_Edit",
"operationId": "Comments_CommentEdit",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UpdateCommentResponse"
"type": "object",
"properties": {}
}
},
"default": {
@@ -80,7 +81,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateCommentRequest"
"$ref": "#/definitions/EditCommentRequest"
}
}
],
@@ -91,7 +92,7 @@
},
"/comment/get-by-id": {
"post": {
"operationId": "Comments_GetById",
"operationId": "Comments_CommentGetByID",
"responses": {
"200": {
"description": "A successful response.",
@@ -123,7 +124,7 @@
},
"/comment/list-by-sku": {
"post": {
"operationId": "Comments_ListBySku",
"operationId": "Comments_CommentListBySKU",
"responses": {
"200": {
"description": "A successful response.",
@@ -155,7 +156,7 @@
},
"/comment/list-by-user": {
"post": {
"operationId": "Comments_ListByUser",
"operationId": "Comments_CommentListByUser",
"responses": {
"200": {
"description": "A successful response.",
@@ -207,7 +208,7 @@
},
"createdAt": {
"type": "string",
"title": "RFC3339 with ms"
"format": "date-time"
}
}
},
@@ -222,7 +223,7 @@
"type": "string",
"format": "int64"
},
"text": {
"comment": {
"type": "string"
}
}
@@ -230,8 +231,25 @@
"CreateCommentResponse": {
"type": "object",
"properties": {
"comment": {
"$ref": "#/definitions/Comment"
"id": {
"type": "string",
"format": "int64"
}
}
},
"EditCommentRequest": {
"type": "object",
"properties": {
"userId": {
"type": "string",
"format": "int64"
},
"commentId": {
"type": "string",
"format": "int64"
},
"newComment": {
"type": "string"
}
}
},
@@ -294,30 +312,6 @@
}
}
},
"UpdateCommentRequest": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "int64"
},
"userId": {
"type": "string",
"format": "int64"
},
"text": {
"type": "string"
}
}
},
"UpdateCommentResponse": {
"type": "object",
"properties": {
"comment": {
"$ref": "#/definitions/Comment"
}
}
},
"protobufAny": {
"type": "object",
"properties": {