feature/fanout #3
			
				
			
		
		
		
	|  | @ -117,6 +117,14 @@ issues: | ||||||
|         - gocognit |         - gocognit | ||||||
|         - contextcheck |         - contextcheck | ||||||
| 
 | 
 | ||||||
|  |   exclude-dirs: | ||||||
|  |     - internal/model | ||||||
|  | 
 | ||||||
|  |   exclude-files: | ||||||
|  |     - .*_test.go | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| linters-settings: | linters-settings: | ||||||
|   gci: |   gci: | ||||||
|     sections: |     sections: | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										1
									
								
								Makefile
								
								
								
								
							|  | @ -18,6 +18,7 @@ test: # 進行測試 | ||||||
| fmt: # 格式優化
 | fmt: # 格式優化
 | ||||||
| 	$(GOFMT) -w $(GOFILES) | 	$(GOFMT) -w $(GOFILES) | ||||||
| 	goimports -w  ./ | 	goimports -w  ./ | ||||||
|  | 	golangci-lint run | ||||||
| 
 | 
 | ||||||
| .PHONY: gen-rpc | .PHONY: gen-rpc | ||||||
| gen-rpc: # 建立 rpc code
 | gen-rpc: # 建立 rpc code
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package domain | package domain | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" |  | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | @ -51,9 +50,7 @@ const ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func CommentError(ec ErrorCode, s ...string) *ers.LibError { | func CommentError(ec ErrorCode, s ...string) *ers.LibError { | ||||||
| 	return ers.NewError(code.CloudEPTweeting, code.DBError, | 	return ers.NewError(code.CloudEPTweeting, code.DBError, ec.ToUint32(), strings.Join(s, " ")) | ||||||
| 		ec.ToUint32(), |  | ||||||
| 		fmt.Sprintf("%s", strings.Join(s, " "))) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func CommentErrorL(ec ErrorCode, | func CommentErrorL(ec ErrorCode, | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ func NewNeo4J(conf *Config, opts ...Option) *Client { | ||||||
| // Conn initiates connection to the database and returns a Neo4j driver instance.
 | // Conn initiates connection to the database and returns a Neo4j driver instance.
 | ||||||
| func (c *Client) Conn() (neo4j.DriverWithContext, error) { | func (c *Client) Conn() (neo4j.DriverWithContext, error) { | ||||||
| 	auth := neo4j.BasicAuth(c.serviceConf.Username, c.serviceConf.Password, "") | 	auth := neo4j.BasicAuth(c.serviceConf.Username, c.serviceConf.Password, "") | ||||||
| 	driver, err := neo4j.NewDriverWithContext(c.serviceConf.URI, auth, func(c *n4Cfg.Config) {}) | 	driver, err := neo4j.NewDriverWithContext(c.serviceConf.URI, auth, func(_ *n4Cfg.Config) {}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("neo4j driver initialization error: %w", err) | 		return nil, fmt.Errorf("neo4j driver initialization error: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -37,6 +37,7 @@ func (l *DeleteCommentLogic) DeleteComment(in *tweeting.DeleteCommentReq) (*twee | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to del comment").Wrap(err) | 			"failed to del comment").Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -41,8 +41,8 @@ func convertToCommentDetailItem(item *model.Comment) *tweeting.CommentDetail { | ||||||
| 		Uid:          item.UID, | 		Uid:          item.UID, | ||||||
| 		Content:      item.Content, | 		Content:      item.Content, | ||||||
| 		CreatedAt:    item.CreateAt, | 		CreatedAt:    item.CreateAt, | ||||||
| 		LikeCount:    int64(item.LikeCount), | 		LikeCount:    item.LikeCount, | ||||||
| 		DislikeCount: int64(item.DisLikeCount), | 		DislikeCount: item.DisLikeCount, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -82,6 +82,7 @@ func (l *GetCommentsLogic) GetComments(in *tweeting.GetCommentsReq) (*tweeting.G | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to find comment").Wrap(err) | 			"failed to find comment").Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,16 +27,16 @@ func NewUpdateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type checkCommentId struct { | type checkCommentID struct { | ||||||
| 	CommentId string `validate:"required"` | 	CommentID string `validate:"required"` | ||||||
| 	Content   string `json:"content,omitempty" validate:"lte=500"` | 	Content   string `json:"content,omitempty" validate:"lte=500"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // UpdateComment 更新評論
 | // UpdateComment 更新評論
 | ||||||
| func (l *UpdateCommentLogic) UpdateComment(in *tweeting.UpdateCommentReq) (*tweeting.OKResp, error) { | func (l *UpdateCommentLogic) UpdateComment(in *tweeting.UpdateCommentReq) (*tweeting.OKResp, error) { | ||||||
| 	// 驗證資料
 | 	// 驗證資料
 | ||||||
| 	if err := l.svcCtx.Validate.ValidateAll(&checkCommentId{ | 	if err := l.svcCtx.Validate.ValidateAll(&checkCommentID{ | ||||||
| 		CommentId: in.GetCommentId(), | 		CommentID: in.GetCommentId(), | ||||||
| 		Content:   in.GetContent(), | 		Content:   in.GetContent(), | ||||||
| 	}); err != nil { | 	}); err != nil { | ||||||
| 		// 錯誤代碼 05-011-00
 | 		// 錯誤代碼 05-011-00
 | ||||||
|  | @ -75,6 +75,7 @@ func (l *UpdateCommentLogic) UpdateComment(in *tweeting.UpdateCommentReq) (*twee | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to update comment:", in.CommentId).Wrap(err) | 			"failed to update comment:", in.CommentId).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ type newTweetingReq struct { | ||||||
| 	UID      string   `json:"uid" validate:"required"` | 	UID      string   `json:"uid" validate:"required"` | ||||||
| 	Content  string   `json:"content" validate:"required,lte=500"` // 貼文限制 500 字內
 | 	Content  string   `json:"content" validate:"required,lte=500"` // 貼文限制 500 字內
 | ||||||
| 	Tags     []string `json:"tags"` | 	Tags     []string `json:"tags"` | ||||||
| 	MediaUrl []string `json:"media_url"` | 	MediaURL []string `json:"media_url"` | ||||||
| 	IsAd     bool     `json:"is_ad"` // default false
 | 	IsAd     bool     `json:"is_ad"` // default false
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -85,6 +85,7 @@ func (l *CreatePostLogic) CreatePost(in *tweeting.NewPostReq) (*tweeting.PostRes | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to add new post").Wrap(err) | 			"failed to add new post").Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -37,6 +37,7 @@ func (l *DeletePostLogic) DeletePost(in *tweeting.DeletePostsReq) (*tweeting.OKR | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to del post").Wrap(err) | 			"failed to del post").Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,8 +54,8 @@ func convertToPostDetailItem(item *model.Post) *tweeting.PostDetailItem { | ||||||
| 		IsAd:         item.IsAd, | 		IsAd:         item.IsAd, | ||||||
| 		CreatedAt:    item.CreateAt, | 		CreatedAt:    item.CreateAt, | ||||||
| 		UpdateAt:     item.UpdateAt, | 		UpdateAt:     item.UpdateAt, | ||||||
| 		LikeCount:    int64(item.Like), | 		LikeCount:    item.Like, | ||||||
| 		DislikeCount: int64(item.DisLike), | 		DislikeCount: item.DisLike, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -102,6 +102,7 @@ func (l *ListPostsLogic) ListPosts(in *tweeting.QueryPostsReq) (*tweeting.ListPo | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to find posts").Wrap(err) | 			"failed to find posts").Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ func NewUpdatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type checkPostId struct { | type checkPostID struct { | ||||||
| 	PostID  string `validate:"required"` | 	PostID  string `validate:"required"` | ||||||
| 	Content string `json:"content,omitempty" validate:"lte=500"` | 	Content string `json:"content,omitempty" validate:"lte=500"` | ||||||
| } | } | ||||||
|  | @ -36,7 +36,7 @@ type checkPostId struct { | ||||||
| // UpdatePost 更新貼文
 | // UpdatePost 更新貼文
 | ||||||
| func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKResp, error) { | func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKResp, error) { | ||||||
| 	// 驗證資料
 | 	// 驗證資料
 | ||||||
| 	if err := l.svcCtx.Validate.ValidateAll(&checkPostId{ | 	if err := l.svcCtx.Validate.ValidateAll(&checkPostID{ | ||||||
| 		PostID:  in.GetPostId(), | 		PostID:  in.GetPostId(), | ||||||
| 		Content: in.GetContent(), | 		Content: in.GetContent(), | ||||||
| 	}); err != nil { | 	}); err != nil { | ||||||
|  | @ -53,7 +53,7 @@ func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKRe | ||||||
| 	update.ID = oid | 	update.ID = oid | ||||||
| 	update.Tags = in.GetTags() | 	update.Tags = in.GetTags() | ||||||
| 	// 將 Media 存入
 | 	// 將 Media 存入
 | ||||||
| 	var media []model.Media | 	media := make([]model.Media, 0, len(in.GetMedia())) | ||||||
| 	for _, item := range in.GetMedia() { | 	for _, item := range in.GetMedia() { | ||||||
| 		media = append(media, model.Media{ | 		media = append(media, model.Media{ | ||||||
| 			Links: item.Url, | 			Links: item.Url, | ||||||
|  | @ -88,6 +88,7 @@ func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKRe | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to update post", in.PostId).Wrap(err) | 			"failed to update post", in.PostId).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,9 +2,10 @@ package socialnetworkservicelogic | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,9 +3,10 @@ package socialnetworkservicelogic | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	"app-cloudep-tweeting-service/internal/domain/repository" | 	"app-cloudep-tweeting-service/internal/domain/repository" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,9 +2,10 @@ package socialnetworkservicelogic | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,9 +3,10 @@ package socialnetworkservicelogic | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	"app-cloudep-tweeting-service/internal/domain/repository" | 	"app-cloudep-tweeting-service/internal/domain/repository" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,9 +2,10 @@ package socialnetworkservicelogic | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,9 +2,10 @@ package socialnetworkservicelogic | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/domain" | 	"app-cloudep-tweeting-service/internal/domain" | ||||||
| 	ers "code.30cm.net/digimon/library-go/errs" |  | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
|  | 	ers "code.30cm.net/digimon/library-go/errs" | ||||||
|  | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -69,6 +69,7 @@ func (l *AddPostLogic) AddPost(in *tweeting.AddPostToTimelineReq) (*tweeting.OKR | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to insert timeline repo :", in.GetUid()).Wrap(err) | 			"failed to insert timeline repo :", in.GetUid()).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -52,6 +52,7 @@ func (l *ClearNoMoreDataFlagLogic) ClearNoMoreDataFlag(in *tweeting.DoNoMoreData | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to clear no more data flag timeline repo :", in.GetUid()).Wrap(err) | 			"failed to clear no more data flag timeline repo :", in.GetUid()).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -61,6 +61,7 @@ func (l *FetchTimelineLogic) FetchTimeline(in *tweeting.GetTimelineReq) (*tweeti | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to fetch timeline repo :", in.GetUid()).Wrap(err) | 			"failed to fetch timeline repo :", in.GetUid()).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -52,6 +52,7 @@ func (l *HasNoMoreDataLogic) HasNoMoreData(in *tweeting.DoNoMoreDataReq) (*tweet | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to get no more data flag:", in.GetUid()).Wrap(err) | 			"failed to get no more data flag:", in.GetUid()).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -52,6 +52,7 @@ func (l *SetNoMoreDataFlagLogic) SetNoMoreDataFlag(in *tweeting.DoNoMoreDataReq) | ||||||
| 				{Key: "err", Value: err}, | 				{Key: "err", Value: err}, | ||||||
| 			}, | 			}, | ||||||
| 			"failed to set no more data flag:", in.GetUid()).Wrap(err) | 			"failed to set no more data flag:", in.GetUid()).Wrap(err) | ||||||
|  | 
 | ||||||
| 		return nil, e | 		return nil, e | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,9 @@ import ( | ||||||
| 	client4J "app-cloudep-tweeting-service/internal/lib/neo4j" | 	client4J "app-cloudep-tweeting-service/internal/lib/neo4j" | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | 
 | ||||||
| 	"github.com/neo4j/neo4j-go-driver/v5/neo4j" | 	"github.com/neo4j/neo4j-go-driver/v5/neo4j" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -27,6 +30,7 @@ func MustSocialNetworkRepository(param SocialNetworkParam) repository.SocialNetw | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error { | func (s *SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|  | @ -53,6 +57,7 @@ func (s *SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) MarkFollowerRelation(ctx context.Context, fromUID, toUID string) error { | func (s *SocialNetworkRepository) MarkFollowerRelation(ctx context.Context, fromUID, toUID string) error { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|  | @ -88,6 +93,7 @@ func (s *SocialNetworkRepository) MarkFollowerRelation(ctx context.Context, from | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { | func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return repository.FollowResp{}, err | 		return repository.FollowResp{}, err | ||||||
|  | @ -113,11 +119,17 @@ func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repositor | ||||||
| 		return repository.FollowResp{}, err | 		return repository.FollowResp{}, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var uids []string | 	var uidList []string | ||||||
| 	for run.Next(ctx) { | 	for run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if uid, ok := record.Get("uid"); ok { | 		uid, ok := record.Get("uid") | ||||||
| 			uids = append(uids, uid.(string)) | 		if ok { | ||||||
|  | 			if uidStr, ok := uid.(string); ok { | ||||||
|  | 				uidList = append(uidList, uidStr) | ||||||
|  | 			} else { | ||||||
|  | 				// TODO 可以印 log
 | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -127,12 +139,13 @@ func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repositor | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return repository.FollowResp{ | 	return repository.FollowResp{ | ||||||
| 		UIDs:  uids, | 		UIDs:  uidList, | ||||||
| 		Total: total, | 		Total: total, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { | func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return repository.FollowResp{}, err | 		return repository.FollowResp{}, err | ||||||
|  | @ -158,11 +171,17 @@ func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repositor | ||||||
| 		return repository.FollowResp{}, err | 		return repository.FollowResp{}, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var uids []string | 	var uidList []string | ||||||
| 	for run.Next(ctx) { | 	for run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if uid, ok := record.Get("uid"); ok { | 		uid, ok := record.Get("uid") | ||||||
| 			uids = append(uids, uid.(string)) | 		if ok { | ||||||
|  | 			if uidStr, ok := uid.(string); ok { | ||||||
|  | 				uidList = append(uidList, uidStr) | ||||||
|  | 			} else { | ||||||
|  | 				// 可以印 log
 | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -172,12 +191,13 @@ func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repositor | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return repository.FollowResp{ | 	return repository.FollowResp{ | ||||||
| 		UIDs:  uids, | 		UIDs:  uidList, | ||||||
| 		Total: total, | 		Total: total, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid string) (int64, error) { | func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid string) (int64, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|  | @ -204,7 +224,11 @@ func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid stri | ||||||
| 	if run.Next(ctx) { | 	if run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if followerCount, ok := record.Get("followerCount"); ok { | 		if followerCount, ok := record.Get("followerCount"); ok { | ||||||
| 			count = followerCount.(int64) | 			if dc, ok := followerCount.(int64); ok { | ||||||
|  | 				count = dc | ||||||
|  | 			} else { | ||||||
|  | 				logx.Info("followerCount error") | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -212,6 +236,7 @@ func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid stri | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid string) (int64, error) { | func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid string) (int64, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|  | @ -238,7 +263,11 @@ func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid stri | ||||||
| 	if run.Next(ctx) { | 	if run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if followeeCount, ok := record.Get("followeeCount"); ok { | 		if followeeCount, ok := record.Get("followeeCount"); ok { | ||||||
| 			count = followeeCount.(int64) | 			if dc, ok := followeeCount.(int64); ok { | ||||||
|  | 				count = dc | ||||||
|  | 			} else { | ||||||
|  | 				logx.Info("followeeCount error") | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -246,6 +275,7 @@ func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid stri | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) RemoveFollowerRelation(ctx context.Context, fromUID, toUID string) error { | func (s *SocialNetworkRepository) RemoveFollowerRelation(ctx context.Context, fromUID, toUID string) error { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|  | @ -274,6 +304,7 @@ func (s *SocialNetworkRepository) RemoveFollowerRelation(ctx context.Context, fr | ||||||
| 
 | 
 | ||||||
| // GetDegreeBetweenUsers 取得這兩個點之間的度數 (最短路徑長度)
 | // GetDegreeBetweenUsers 取得這兩個點之間的度數 (最短路徑長度)
 | ||||||
| func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid1, uid2 string) (int64, error) { | func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid1, uid2 string) (int64, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|  | @ -302,7 +333,11 @@ func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid | ||||||
| 	if run.Next(ctx) { | 	if run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if deg, ok := record.Get("degree"); ok { | 		if deg, ok := record.Get("degree"); ok { | ||||||
| 			degree = deg.(int64) | 			if degreeValue, ok := deg.(int64); ok { | ||||||
|  | 				degree = degreeValue | ||||||
|  | 			} else { | ||||||
|  | 				logx.Info("degree error") | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -311,6 +346,7 @@ func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid | ||||||
| 
 | 
 | ||||||
| // GetUIDsWithinNDegrees 取得某個節點在 n 度內關係所有 UID
 | // GetUIDsWithinNDegrees 取得某個節點在 n 度內關係所有 UID
 | ||||||
| func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid string, degrees, pageSize, pageIndex int64) ([]string, int64, error) { | func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid string, degrees, pageSize, pageIndex int64) ([]string, int64, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, 0, err | 		return nil, 0, err | ||||||
|  | @ -339,11 +375,17 @@ func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid | ||||||
| 		return nil, 0, fmt.Errorf("failed to get uids within %d degrees of user: %w", degrees, err) | 		return nil, 0, fmt.Errorf("failed to get uids within %d degrees of user: %w", degrees, err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var uids []string | 	var uidList []string | ||||||
| 	for run.Next(ctx) { | 	for run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if uid, ok := record.Get("uid"); ok { | 		uid, ok := record.Get("uid") | ||||||
| 			uids = append(uids, uid.(string)) | 		if ok { | ||||||
|  | 			if uidStr, ok := uid.(string); ok { | ||||||
|  | 				uidList = append(uidList, uidStr) | ||||||
|  | 			} else { | ||||||
|  | 				// 可以印 log
 | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -353,10 +395,11 @@ func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid | ||||||
| 		return nil, 0, err | 		return nil, 0, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return uids, totalCount, nil | 	return uidList, totalCount, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SocialNetworkRepository) getTotalUIDsWithinNDegrees(ctx context.Context, uid string, degrees int64) (int64, error) { | func (s *SocialNetworkRepository) getTotalUIDsWithinNDegrees(ctx context.Context, uid string, degrees int64) (int64, error) { | ||||||
|  | 	//nolint:contextcheck
 | ||||||
| 	session, err := s.neo4jClient.Conn() | 	session, err := s.neo4jClient.Conn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|  | @ -384,7 +427,11 @@ func (s *SocialNetworkRepository) getTotalUIDsWithinNDegrees(ctx context.Context | ||||||
| 	if run.Next(ctx) { | 	if run.Next(ctx) { | ||||||
| 		record := run.Record() | 		record := run.Record() | ||||||
| 		if count, ok := record.Get("totalCount"); ok { | 		if count, ok := record.Get("totalCount"); ok { | ||||||
| 			totalCount = count.(int64) | 			if countV, ok := count.(int64); ok { | ||||||
|  | 				totalCount = countV | ||||||
|  | 			} else { | ||||||
|  | 				logx.Info("totalCount error") | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -139,5 +139,6 @@ func (t *TimelineRepository) ClearNoMoreDataFlag(ctx context.Context, uid string | ||||||
| 	key := domain.TimelineRedisKey.With(uid).ToString() | 	key := domain.TimelineRedisKey.With(uid).ToString() | ||||||
| 	// 移除 "NoMoreData" 標誌
 | 	// 移除 "NoMoreData" 標誌
 | ||||||
| 	_, err := t.redis.ZremCtx(ctx, key, domain.LastOfTimelineFlag) | 	_, err := t.redis.ZremCtx(ctx, key, domain.LastOfTimelineFlag) | ||||||
|  | 
 | ||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/logic/commentservice" | 	commentservicelogic "app-cloudep-tweeting-service/internal/logic/commentservice" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/logic/postservice" | 	postservicelogic "app-cloudep-tweeting-service/internal/logic/postservice" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/logic/socialnetworkservice" | 	socialnetworkservicelogic "app-cloudep-tweeting-service/internal/logic/socialnetworkservice" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/logic/timelineservice" | 	timelineservicelogic "app-cloudep-tweeting-service/internal/logic/timelineservice" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func mustMongoConnectUrl(c config.Config) string { | func mustMongoConnectURL(c config.Config) string { | ||||||
| 	return fmt.Sprintf("%s://%s:%s", | 	return fmt.Sprintf("%s://%s:%s", | ||||||
| 		c.Mongo.Schema, | 		c.Mongo.Schema, | ||||||
| 		c.Mongo.Host, | 		c.Mongo.Host, | ||||||
|  | @ -18,10 +18,12 @@ func mustMongoConnectUrl(c config.Config) string { | ||||||
| 
 | 
 | ||||||
| func MustPostModel(c config.Config) model.PostModel { | func MustPostModel(c config.Config) model.PostModel { | ||||||
| 	postCollection := model.Post{} | 	postCollection := model.Post{} | ||||||
| 	return model.NewPostModel(mustMongoConnectUrl(c), c.Mongo.Database, postCollection.CollectionName()) | 
 | ||||||
|  | 	return model.NewPostModel(mustMongoConnectURL(c), c.Mongo.Database, postCollection.CollectionName()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func MustCommentModel(c config.Config) model.CommentModel { | func MustCommentModel(c config.Config) model.CommentModel { | ||||||
| 	m := model.Comment{} | 	m := model.Comment{} | ||||||
| 	return model.NewCommentModel(mustMongoConnectUrl(c), c.Mongo.Database, m.CollectionName()) | 
 | ||||||
|  | 	return model.NewCommentModel(mustMongoConnectURL(c), c.Mongo.Database, m.CollectionName()) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ import ( | ||||||
| 	"app-cloudep-tweeting-service/internal/lib/neo4j" | 	"app-cloudep-tweeting-service/internal/lib/neo4j" | ||||||
| 	model "app-cloudep-tweeting-service/internal/model/mongo" | 	model "app-cloudep-tweeting-service/internal/model/mongo" | ||||||
| 	"app-cloudep-tweeting-service/internal/repository" | 	"app-cloudep-tweeting-service/internal/repository" | ||||||
|  | 
 | ||||||
| 	"github.com/zeromicro/go-zero/core/stores/redis" | 	"github.com/zeromicro/go-zero/core/stores/redis" | ||||||
| 
 | 
 | ||||||
| 	vi "code.30cm.net/digimon/library-go/validator" | 	vi "code.30cm.net/digimon/library-go/validator" | ||||||
|  |  | ||||||
|  | @ -1,9 +1,6 @@ | ||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"flag" |  | ||||||
| 	"fmt" |  | ||||||
| 
 |  | ||||||
| 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | 	"app-cloudep-tweeting-service/gen_result/pb/tweeting" | ||||||
| 	"app-cloudep-tweeting-service/internal/config" | 	"app-cloudep-tweeting-service/internal/config" | ||||||
| 	commentserviceServer "app-cloudep-tweeting-service/internal/server/commentservice" | 	commentserviceServer "app-cloudep-tweeting-service/internal/server/commentservice" | ||||||
|  | @ -11,6 +8,8 @@ import ( | ||||||
| 	socialnetworkserviceServer "app-cloudep-tweeting-service/internal/server/socialnetworkservice" | 	socialnetworkserviceServer "app-cloudep-tweeting-service/internal/server/socialnetworkservice" | ||||||
| 	timelineserviceServer "app-cloudep-tweeting-service/internal/server/timelineservice" | 	timelineserviceServer "app-cloudep-tweeting-service/internal/server/timelineservice" | ||||||
| 	"app-cloudep-tweeting-service/internal/svc" | 	"app-cloudep-tweeting-service/internal/svc" | ||||||
|  | 	"flag" | ||||||
|  | 	"log" | ||||||
| 
 | 
 | ||||||
| 	"github.com/zeromicro/go-zero/core/conf" | 	"github.com/zeromicro/go-zero/core/conf" | ||||||
| 	"github.com/zeromicro/go-zero/core/service" | 	"github.com/zeromicro/go-zero/core/service" | ||||||
|  | @ -40,6 +39,6 @@ func main() { | ||||||
| 	}) | 	}) | ||||||
| 	defer s.Stop() | 	defer s.Stop() | ||||||
| 
 | 
 | ||||||
| 	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) | 	log.Printf("Starting rpc server at %s...\n", c.ListenOn) | ||||||
| 	s.Start() | 	s.Start() | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue