diff --git a/generate/database/mongodb/20240829054501_post.up.js b/generate/database/mongodb/20240829054501_post.up.mongo similarity index 100% rename from generate/database/mongodb/20240829054501_post.up.js rename to generate/database/mongodb/20240829054501_post.up.mongo diff --git a/generate/database/mongodb/20240829054502_comment.up.js b/generate/database/mongodb/20240829054502_comment.up.mongo similarity index 53% rename from generate/database/mongodb/20240829054502_comment.up.js rename to generate/database/mongodb/20240829054502_comment.up.mongo index 119f0ad..33382ec 100644 --- a/generate/database/mongodb/20240829054502_comment.up.js +++ b/generate/database/mongodb/20240829054502_comment.up.mongo @@ -1,5 +1,2 @@ use digimon_tweeting; db.comment.createIndex({ "post_id": 1,"createAt":1}); - - -// TODO 看是否有要刪除過多的索引,要在測試一下 \ No newline at end of file diff --git a/generate/protobuf/tweeting.proto b/generate/protobuf/tweeting.proto index cbc1b2c..b850ac2 100644 --- a/generate/protobuf/tweeting.proto +++ b/generate/protobuf/tweeting.proto @@ -181,4 +181,35 @@ service CommentService 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); } \ No newline at end of file diff --git a/internal/logic/timelineservice/add_post_to_timeline_logic.go b/internal/logic/timelineservice/add_post_to_timeline_logic.go new file mode 100644 index 0000000..e041dc2 --- /dev/null +++ b/internal/logic/timelineservice/add_post_to_timeline_logic.go @@ -0,0 +1,31 @@ +package timelineservicelogic + +import ( + "context" + + "app-cloudep-tweeting-service/gen_result/pb/tweeting" + "app-cloudep-tweeting-service/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddPostToTimelineLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewAddPostToTimelineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPostToTimelineLogic { + return &AddPostToTimelineLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// AddPostToTimeline 加入貼文,只管一股腦全塞,這裡會自動判斷 +func (l *AddPostToTimelineLogic) AddPostToTimeline(in *tweeting.GetTimelineReq) (*tweeting.OKResp, error) { + // todo: add your logic here and delete this line + + return &tweeting.OKResp{}, nil +} diff --git a/internal/logic/timelineservice/get_timeline_logic.go b/internal/logic/timelineservice/get_timeline_logic.go new file mode 100644 index 0000000..113abc2 --- /dev/null +++ b/internal/logic/timelineservice/get_timeline_logic.go @@ -0,0 +1,31 @@ +package timelineservicelogic + +import ( + "context" + + "app-cloudep-tweeting-service/gen_result/pb/tweeting" + "app-cloudep-tweeting-service/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetTimelineLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetTimelineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTimelineLogic { + return &GetTimelineLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// GetTimeline 取得這個人的動態時報 +func (l *GetTimelineLogic) GetTimeline(in *tweeting.GetTimelineReq) (*tweeting.GetTimelineResp, error) { + // todo: add your logic here and delete this line + + return &tweeting.GetTimelineResp{}, nil +} diff --git a/internal/server/commentservice/comment_service_server.go b/internal/server/commentservice/comment_service_server.go index 9fed63f..f434bad 100644 --- a/internal/server/commentservice/comment_service_server.go +++ b/internal/server/commentservice/comment_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - commentservicelogic "app-cloudep-tweeting-service/internal/logic/commentservice" + "app-cloudep-tweeting-service/internal/logic/commentservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/server/postservice/post_service_server.go b/internal/server/postservice/post_service_server.go index 639c1f4..07d52d3 100644 --- a/internal/server/postservice/post_service_server.go +++ b/internal/server/postservice/post_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - postservicelogic "app-cloudep-tweeting-service/internal/logic/postservice" + "app-cloudep-tweeting-service/internal/logic/postservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/server/timelineservice/timeline_service_server.go b/internal/server/timelineservice/timeline_service_server.go new file mode 100644 index 0000000..7e641f4 --- /dev/null +++ b/internal/server/timelineservice/timeline_service_server.go @@ -0,0 +1,35 @@ +// Code generated by goctl. DO NOT EDIT. +// Source: tweeting.proto + +package server + +import ( + "context" + + "app-cloudep-tweeting-service/gen_result/pb/tweeting" + "app-cloudep-tweeting-service/internal/logic/timelineservice" + "app-cloudep-tweeting-service/internal/svc" +) + +type TimelineServiceServer struct { + svcCtx *svc.ServiceContext + tweeting.UnimplementedTimelineServiceServer +} + +func NewTimelineServiceServer(svcCtx *svc.ServiceContext) *TimelineServiceServer { + return &TimelineServiceServer{ + svcCtx: svcCtx, + } +} + +// AddPostToTimeline 加入貼文,只管一股腦全塞,這裡會自動判斷 +func (s *TimelineServiceServer) AddPostToTimeline(ctx context.Context, in *tweeting.GetTimelineReq) (*tweeting.OKResp, error) { + l := timelineservicelogic.NewAddPostToTimelineLogic(ctx, s.svcCtx) + return l.AddPostToTimeline(in) +} + +// GetTimeline 取得這個人的動態時報 +func (s *TimelineServiceServer) GetTimeline(ctx context.Context, in *tweeting.GetTimelineReq) (*tweeting.GetTimelineResp, error) { + l := timelineservicelogic.NewGetTimelineLogic(ctx, s.svcCtx) + return l.GetTimeline(in) +}