syntax = "proto3"; package tweeting; option go_package = "./tweeting"; // ========== 基本回應 =========== message OKResp {} // 空的請求 message NoneReq {} // 分頁信息 message Pager { int64 total = 1; // 總數量 int64 size = 2; // 每頁數量 int64 index = 3; // 當前頁碼 } // ========== 貼文區 =========== // ------ NewPost 新增貼文-------- message NewPostReq { string uid = 1; // 發佈貼文的用戶ID string content = 2; // 貼文內容 repeated string tags = 3; // 貼文相關標籤 repeated Media media = 4; // 這筆文章的所有 Media URL bool is_ad = 5; // 是否為廣告 } message Media { string type = 1; string url = 2; } // 貼文回應 message PostResp { string post_id = 1; // 創建成功的貼文ID } // ------ DeletePost 刪除貼文 ------ // 刪除貼文的請求 message DeletePostsReq { repeated string post_id = 1; // 貼文ID } // ------ UpdatePost 更新貼文 ------ // 更新貼文的請求 message UpdatePostReq { string post_id = 1; // 貼文ID repeated string tags = 2; // 新的標籤列表 repeated Media media = 3; // 這筆文章的所有 Media URL optional string content = 4; // 新的貼文內容 optional int64 like_count = 5; // 喜歡數量 optional int64 dislike_count = 6; // 不喜歡數量 } // ------ListPosts 查詢貼文 ------ // 查詢貼文的請求 message QueryPostsReq { repeated string uid = 1; // 可選:根據用戶ID篩選貼文 repeated string post_id = 2; // 可選:根據貼文ID篩選貼文 optional int32 only_ads = 3; // 可選:是否只顯示廣告 0 不篩選 1 只顯示廣告 2 不顯示廣告 int32 page_index = 4; // 分頁的頁碼 int32 page_size = 5; // 每頁顯示的數量 } // 貼文詳情 message PostDetailItem { string post_id = 1; // 貼文ID string uid = 2; // 發佈用戶ID string content = 3; // 貼文內容 repeated string tags = 4; // 標籤 repeated Media media = 5; // 圖片URL bool is_ad = 6; // 是否為廣告 int64 created_at = 7; // 發佈時間 int64 update_at = 8; // 更新時間 int64 like_count = 9; // 讚數 int64 dislike_count = 10; // 不喜歡數量 } // 貼文列表回應 message ListPostsResp { repeated PostDetailItem posts = 1; // 貼文列表 Pager page = 2; } message ModifyLikeDislikeCountReq { string post_id = 1; // 貼文的 ID int64 reaction_type = 2; // 用戶的反應類型,可能是讚或不讚 bool is_increment = 3; // 表示是否增加(true 表示增加,false 表示減少) int64 count = 4; // 異動數量 } // ========== 定義貼文服務(最基本單位,不要把邏輯放進來,也考慮是否要做快取) ========== service PostService { // CreatePost 新增貼文 rpc CreatePost(NewPostReq) returns (PostResp); // DeletePost 刪除貼文 rpc DeletePost(DeletePostsReq) returns (OKResp); // UpdatePost 更新貼文 rpc UpdatePost(UpdatePostReq) returns (OKResp); // ListPosts 查詢貼文 rpc ListPosts(QueryPostsReq) returns (ListPostsResp); } // ================================================================================================= // ------------ 評論貼文的請求 ------------ message CommentPostReq { string post_id = 1; // 貼文ID string uid = 2; // 評論者ID string content = 3; // 評論內容 } message CommentPostResp { string comment_id = 1; // 回應ID } // ------------ 查詢評論的請求 ------------ message GetCommentsReq { string post_id = 1; // 貼文ID int32 page_index = 2; // 分頁頁碼 int32 page_size = 3; // 每頁顯示數量 } // 評論詳情 message CommentDetail { string comment_id = 1; // 評論ID string uid = 2; // 評論者ID string content = 3; // 評論內容 int64 created_at = 4; // 創建時間 int64 like_count = 5; // 讚數 int64 dislike_count = 6; // 不喜歡數量 } // 評論列表回應 message GetCommentsResp { repeated CommentDetail comments = 1; // 評論列表 Pager page = 2; } // ------------ 刪除評論請求 ------------ message DeleteCommentReq { repeated string comment_id = 1; // 評論ID } // 更新評論請求 message UpdateCommentReq { string comment_id = 1; // 評論ID string content = 2; // 更新後的評論內容 optional int64 like_count = 3; // 讚數 optional int64 dislike_count = 4; // 不喜歡數量 } // 定義評論服務 service CommentService { // NewComment 發表評論 rpc NewComment(CommentPostReq) returns (CommentPostResp); // GetComments 查詢評論 rpc GetComments(GetCommentsReq) returns (GetCommentsResp); // DeleteComment 刪除評論 rpc DeleteComment(DeleteCommentReq) returns (OKResp); // UpdateComment 更新評論 rpc UpdateComment(UpdateCommentReq) returns (OKResp); } // ========== TimeLineService (個人動態時報) ========== message GetTimelineReq { string uid = 1; // 用户ID int32 pageIndex = 2; // 頁碼 int32 pageSize = 3; // 每一頁大小 } message GetTimelineResp { repeated PostDetailItem posts = 1; // 貼文列表 Pager page = 2; // 分頁訊息 } message AddPostToTimelineReq { string uid = 1; // key repeated PostDetailItem posts = 2; } // TimelineService 業務邏輯在外面組合 service TimelineService { // AddPostToTimeline 加入貼文,只管一股腦全塞,這裡會自動判斷 // 誰要砍誰不砍,處理排序,上限是 1000 筆(超過1000 請他回資料庫拿) // 只存活躍用戶的,不活躍不浪費快取的空間 rpc AddPostToTimeline(GetTimelineReq) returns (OKResp); // GetTimeline 取得這個人的動態時報 rpc GetTimeline(GetTimelineReq) returns (GetTimelineResp); }