init comment and post service

This commit is contained in:
daniel.w 2024-08-28 17:09:01 +08:00
parent 3019fa1078
commit bc506fd090
28 changed files with 1032 additions and 1 deletions

View File

@ -21,7 +21,7 @@ fmt: # 格式優化
.PHONY: gen-rpc
gen-rpc: # 建立 rpc code
$(GO_CTL_NAME) rpc protoc ./generate/protobuf/notification.proto -m --style=$(GO_ZERO_STYLE) --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=.
$(GO_CTL_NAME) rpc protoc ./generate/protobuf/feed.proto -m --style=$(GO_ZERO_STYLE) --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=.
go mod tidy
@echo "Generate core-api files successfully"
@ -46,3 +46,8 @@ build-docker:
docker buildx build -t $(DOCKER_REPO):$(VERSION) --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/ed_25519)" .
rm -rf Dockerfile
@echo "Generate core-api files successfully"
gen-mongo-model: # 建立 rpc 資料庫
# 只產生 Model 剩下的要自己撰寫,連欄位名稱也是
goctl model mongo -t AutoId --dir ./internal/model/mongo --style $(GO_ZERO_STYLE)
@echo "Generate mongo model files successfully"

41
feed.go Normal file
View File

@ -0,0 +1,41 @@
package main
import (
"flag"
"fmt"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/config"
commentserviceServer "app-cloudep-feed-service/internal/server/commentservice"
postserviceServer "app-cloudep-feed-service/internal/server/postservice"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/feed.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
feed.RegisterPostServiceServer(grpcServer, postserviceServer.NewPostServiceServer(ctx))
feed.RegisterCommentServiceServer(grpcServer, commentserviceServer.NewCommentServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

View File

@ -0,0 +1 @@
如果有需要可以把 mongo 放這邊

View File

@ -0,0 +1 @@
DROP DATABASE IF EXISTS `digimon_feed`;

View File

@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS `digimon_feed`;

View File

@ -0,0 +1,39 @@
# migrate
數據庫遷移工具
[golang-migrate](https://github.com/golang-migrate/migrate)
## 安裝 make
```shell
brew install Makefile
```
## 安裝 golang-migrate
```shell
brew install golang-migrate
```
## 執行刪除 mysql schema
```shell
migrate -source file://database/migrations/mysql -database 'mysql://account:password@tcp(127.0.0.1:3306)/esc_c2c' down
```
## 執行安裝 mysql schema
```shell
migrate -source file://database/migrations/mysql -database 'mysql://account:password@tcp(127.0.0.1:3306)/esc_c2c' up
```
## 執行刪除 mongo schema
```shell
migrate -source file://database/migrations/mongodb -database 'mongodb://127.0.0.1:27017/esc_c2c' down
```
## 執行安裝 mongo schema
```shell
migrate -source file://database/migrations/mongodb -database 'mongodb://127.0.0.1:27017/esc_c2c' up
```

View File

@ -0,0 +1,197 @@
syntax = "proto3";
package feed;
option go_package="./feed";
//
message OKResp {}
//
message NoneReq {}
//
message Pager {
int64 total =1; //
int64 size=2; //
int64 index=3; //
}
//
message NewPostReq {
int64 user_id = 1; // ID
string content = 2; //
repeated string tags = 3; //
repeated string media_url = 4; // Media URL
bool is_ad = 5; //
}
//
message PostResp {
string post_id = 1; // ID
}
//
message DeletePostsReq {
repeated string post_id = 1; // ID
}
//
message UpdatePostReq {
string post_id = 1; // ID
repeated string tags = 2; //
repeated string media_url = 3; // Media URL
optional string content = 4; //
optional int64 like_count = 5; //
optional int64 dislike_count = 6; //
}
//
message QueryPostsReq {
repeated int64 user_id = 1; // ID篩選貼文
repeated int64 id = 2; // ID篩選貼文
repeated string tags = 3; //
optional bool only_ads = 4; //
int32 page_index = 5; //
int32 page_size = 6; //
}
//
message PostDetailItem {
string post_id = 1; // ID
int64 user_id = 2; // ID
string content = 3; //
repeated string tags = 4; //
repeated string media_url = 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 LikeReq {
string target_id = 1; // IDID或評論ID
int64 user_id = 2; // ID
int64 like_type = 3; //
}
// /
message LikeItem {
string target_id = 1; // IDID或評論ID
int64 user_id = 2; // ID
int64 like_type = 3; //
}
// /
message LikeListReq {
string target_id = 1; // IDID或評論ID
int64 like_type = 2; //
int32 page_index = 3; //
int32 page_size = 4; //
}
// /
message LikeListResp {
repeated LikeItem list = 1; // /
Pager page = 2;
}
// /
message LikeCountReq {
string target_id = 1; // IDID或評論ID
int64 like_type = 2; //
}
// /
message LikeCountResp {
string count = 1; //
}
//
message CommentPostReq {
string post_id = 1; // ID
int64 user_id = 2; // ID
string content = 3; //
}
//
message GetCommentsReq {
string post_id = 1; // ID
int32 page_index = 2; //
int32 page_size = 3; //
}
//
message CommentDetail {
string comment_id = 1; // ID
int64 user_id = 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 {
string comment_id = 1; // ID
}
//
message UpdateCommentReq {
string comment_id = 1; // ID
string content = 2; //
}
//
service PostService {
// NewPost
rpc NewPost(NewPostReq) returns(PostResp);
// DeletePost
rpc DeletePost(DeletePostsReq) returns (OKResp);
// UpdatePost
rpc UpdatePost(UpdatePostReq) returns (OKResp);
// ListPosts
rpc ListPosts(QueryPostsReq) returns (ListPostsResp);
// Like /
rpc Like(LikeReq) returns (OKResp);
// GetLikeStatus /
rpc GetLikeStatus(LikeReq) returns (OKResp);
// LikeList /
rpc LikeList(LikeListReq) returns (LikeListResp);
// CountLike /
rpc CountLike(LikeCountReq) returns (LikeCountResp);
}
//
service CommentService {
// NewComment
rpc NewComment(CommentPostReq) returns (OKResp);
// GetComments
rpc GetComments(GetCommentsReq) returns (GetCommentsResp);
// DeleteComment
rpc DeleteComment(DeleteCommentReq) returns (OKResp);
// UpdateComment
rpc UpdateComment(UpdateCommentReq) returns (OKResp);
// LikeComment /
rpc LikeComment(LikeReq) returns (OKResp);
// GetLikeStatus /
rpc GetLikeStatus(LikeReq) returns (OKResp);
// LikeList /
rpc LikeList(LikeListReq) returns (LikeListResp);
// CountLike /
rpc CountLike(LikeCountReq) returns (LikeCountResp);
}

88
go.mod Normal file
View File

@ -0,0 +1,88 @@
module app-cloudep-feed-service
go 1.22.3
require (
github.com/zeromicro/go-zero v1.7.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
go.etcd.io/etcd/client/v3 v3.5.15 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/client-go v0.29.3 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

7
internal/config/config.go Executable file
View File

@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CountLikeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCountLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CountLikeLogic {
return &CountLikeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CountLike 取得讚/不讚評論數量
func (l *CountLikeLogic) CountLike(in *feed.LikeCountReq) (*feed.LikeCountResp, error) {
// todo: add your logic here and delete this line
return &feed.LikeCountResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteCommentLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCommentLogic {
return &DeleteCommentLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeleteComment 刪除評論
func (l *DeleteCommentLogic) DeleteComment(in *feed.DeleteCommentReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetCommentsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentsLogic {
return &GetCommentsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetComments 查詢評論
func (l *GetCommentsLogic) GetComments(in *feed.GetCommentsReq) (*feed.GetCommentsResp, error) {
// todo: add your logic here and delete this line
return &feed.GetCommentsResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLikeStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetLikeStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLikeStatusLogic {
return &GetLikeStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetLikeStatus 取得讚/不讚評論狀態
func (l *GetLikeStatusLogic) GetLikeStatus(in *feed.LikeReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeCommentLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewLikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeCommentLogic {
return &LikeCommentLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// LikeComment 點讚/取消讚 評論
func (l *LikeCommentLogic) LikeComment(in *feed.LikeReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeListLogic {
return &LikeListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// LikeList 取得讚/不讚評論列表
func (l *LikeListLogic) LikeList(in *feed.LikeListReq) (*feed.LikeListResp, error) {
// todo: add your logic here and delete this line
return &feed.LikeListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type NewCommentLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewNewCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewCommentLogic {
return &NewCommentLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// NewComment 發表評論
func (l *NewCommentLogic) NewComment(in *feed.CommentPostReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package commentservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateCommentLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCommentLogic {
return &UpdateCommentLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UpdateComment 更新評論
func (l *UpdateCommentLogic) UpdateComment(in *feed.UpdateCommentReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CountLikeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCountLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CountLikeLogic {
return &CountLikeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CountLike 取得讚/不讚數量
func (l *CountLikeLogic) CountLike(in *feed.LikeCountReq) (*feed.LikeCountResp, error) {
// todo: add your logic here and delete this line
return &feed.LikeCountResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeletePostLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeletePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePostLogic {
return &DeletePostLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeletePost 刪除貼文
func (l *DeletePostLogic) DeletePost(in *feed.DeletePostsReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLikeStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetLikeStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLikeStatusLogic {
return &GetLikeStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetLikeStatus 取得讚/不讚狀態
func (l *GetLikeStatusLogic) GetLikeStatus(in *feed.LikeReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeListLogic {
return &LikeListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// LikeList 取得讚/不讚列表
func (l *LikeListLogic) LikeList(in *feed.LikeListReq) (*feed.LikeListResp, error) {
// todo: add your logic here and delete this line
return &feed.LikeListResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeLogic {
return &LikeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// Like 點讚/取消讚 貼文
func (l *LikeLogic) Like(in *feed.LikeReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ListPostsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPostsLogic {
return &ListPostsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// ListPosts 查詢貼文
func (l *ListPostsLogic) ListPosts(in *feed.QueryPostsReq) (*feed.ListPostsResp, error) {
// todo: add your logic here and delete this line
return &feed.ListPostsResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type NewPostLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewNewPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewPostLogic {
return &NewPostLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// NewPost 新增貼文
func (l *NewPostLogic) NewPost(in *feed.NewPostReq) (*feed.PostResp, error) {
// todo: add your logic here and delete this line
return &feed.PostResp{}, nil
}

View File

@ -0,0 +1,31 @@
package postservicelogic
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdatePostLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePostLogic {
return &UpdatePostLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// UpdatePost 更新貼文
func (l *UpdatePostLogic) UpdatePost(in *feed.UpdatePostReq) (*feed.OKResp, error) {
// todo: add your logic here and delete this line
return &feed.OKResp{}, nil
}

View File

@ -0,0 +1,71 @@
// Code generated by goctl. DO NOT EDIT.
// Source: feed.proto
package server
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/logic/commentservice"
"app-cloudep-feed-service/internal/svc"
)
type CommentServiceServer struct {
svcCtx *svc.ServiceContext
feed.UnimplementedCommentServiceServer
}
func NewCommentServiceServer(svcCtx *svc.ServiceContext) *CommentServiceServer {
return &CommentServiceServer{
svcCtx: svcCtx,
}
}
// NewComment 發表評論
func (s *CommentServiceServer) NewComment(ctx context.Context, in *feed.CommentPostReq) (*feed.OKResp, error) {
l := commentservicelogic.NewNewCommentLogic(ctx, s.svcCtx)
return l.NewComment(in)
}
// GetComments 查詢評論
func (s *CommentServiceServer) GetComments(ctx context.Context, in *feed.GetCommentsReq) (*feed.GetCommentsResp, error) {
l := commentservicelogic.NewGetCommentsLogic(ctx, s.svcCtx)
return l.GetComments(in)
}
// DeleteComment 刪除評論
func (s *CommentServiceServer) DeleteComment(ctx context.Context, in *feed.DeleteCommentReq) (*feed.OKResp, error) {
l := commentservicelogic.NewDeleteCommentLogic(ctx, s.svcCtx)
return l.DeleteComment(in)
}
// UpdateComment 更新評論
func (s *CommentServiceServer) UpdateComment(ctx context.Context, in *feed.UpdateCommentReq) (*feed.OKResp, error) {
l := commentservicelogic.NewUpdateCommentLogic(ctx, s.svcCtx)
return l.UpdateComment(in)
}
// LikeComment 點讚/取消讚 評論
func (s *CommentServiceServer) LikeComment(ctx context.Context, in *feed.LikeReq) (*feed.OKResp, error) {
l := commentservicelogic.NewLikeCommentLogic(ctx, s.svcCtx)
return l.LikeComment(in)
}
// GetLikeStatus 取得讚/不讚評論狀態
func (s *CommentServiceServer) GetLikeStatus(ctx context.Context, in *feed.LikeReq) (*feed.OKResp, error) {
l := commentservicelogic.NewGetLikeStatusLogic(ctx, s.svcCtx)
return l.GetLikeStatus(in)
}
// LikeList 取得讚/不讚評論列表
func (s *CommentServiceServer) LikeList(ctx context.Context, in *feed.LikeListReq) (*feed.LikeListResp, error) {
l := commentservicelogic.NewLikeListLogic(ctx, s.svcCtx)
return l.LikeList(in)
}
// CountLike 取得讚/不讚評論數量
func (s *CommentServiceServer) CountLike(ctx context.Context, in *feed.LikeCountReq) (*feed.LikeCountResp, error) {
l := commentservicelogic.NewCountLikeLogic(ctx, s.svcCtx)
return l.CountLike(in)
}

View File

@ -0,0 +1,71 @@
// Code generated by goctl. DO NOT EDIT.
// Source: feed.proto
package server
import (
"context"
"app-cloudep-feed-service/gen_result/pb/feed"
"app-cloudep-feed-service/internal/logic/postservice"
"app-cloudep-feed-service/internal/svc"
)
type PostServiceServer struct {
svcCtx *svc.ServiceContext
feed.UnimplementedPostServiceServer
}
func NewPostServiceServer(svcCtx *svc.ServiceContext) *PostServiceServer {
return &PostServiceServer{
svcCtx: svcCtx,
}
}
// NewPost 新增貼文
func (s *PostServiceServer) NewPost(ctx context.Context, in *feed.NewPostReq) (*feed.PostResp, error) {
l := postservicelogic.NewNewPostLogic(ctx, s.svcCtx)
return l.NewPost(in)
}
// DeletePost 刪除貼文
func (s *PostServiceServer) DeletePost(ctx context.Context, in *feed.DeletePostsReq) (*feed.OKResp, error) {
l := postservicelogic.NewDeletePostLogic(ctx, s.svcCtx)
return l.DeletePost(in)
}
// UpdatePost 更新貼文
func (s *PostServiceServer) UpdatePost(ctx context.Context, in *feed.UpdatePostReq) (*feed.OKResp, error) {
l := postservicelogic.NewUpdatePostLogic(ctx, s.svcCtx)
return l.UpdatePost(in)
}
// ListPosts 查詢貼文
func (s *PostServiceServer) ListPosts(ctx context.Context, in *feed.QueryPostsReq) (*feed.ListPostsResp, error) {
l := postservicelogic.NewListPostsLogic(ctx, s.svcCtx)
return l.ListPosts(in)
}
// Like 點讚/取消讚 貼文
func (s *PostServiceServer) Like(ctx context.Context, in *feed.LikeReq) (*feed.OKResp, error) {
l := postservicelogic.NewLikeLogic(ctx, s.svcCtx)
return l.Like(in)
}
// GetLikeStatus 取得讚/不讚狀態
func (s *PostServiceServer) GetLikeStatus(ctx context.Context, in *feed.LikeReq) (*feed.OKResp, error) {
l := postservicelogic.NewGetLikeStatusLogic(ctx, s.svcCtx)
return l.GetLikeStatus(in)
}
// LikeList 取得讚/不讚列表
func (s *PostServiceServer) LikeList(ctx context.Context, in *feed.LikeListReq) (*feed.LikeListResp, error) {
l := postservicelogic.NewLikeListLogic(ctx, s.svcCtx)
return l.LikeList(in)
}
// CountLike 取得讚/不讚數量
func (s *PostServiceServer) CountLike(ctx context.Context, in *feed.LikeCountReq) (*feed.LikeCountResp, error) {
l := postservicelogic.NewCountLikeLogic(ctx, s.svcCtx)
return l.CountLike(in)
}

View File

@ -0,0 +1,13 @@
package svc
import "app-cloudep-feed-service/internal/config"
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}