Skip to content

feature(micro): fix bookmar and favorite comment rpc #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bff/apollo-gateway/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bff/apollo-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@apollo/server": "^4.11.0",
"@checkpicks/checkpicks-rpc-ts": "^1.5.0",
"@checkpicks/checkpicks-rpc-ts": "^1.5.4",
"@grpc/grpc-js": "^1.11.1",
"@grpc/proto-loader": "^0.7.13",
"@nestjs/apollo": "^12.2.0",
Expand Down
2 changes: 1 addition & 1 deletion micro-service/bookmark-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.4.0 // indirect
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.5 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions micro-service/bookmark-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.3.5 h
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.3.5/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.4.0 h1:VDP3Xl0URY+MdkYmwfWAOZc+Fx/JKYtC8+lb8YsEUr8=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.4.0/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.1 h1:lmCR6iAQfJll4/oKkPK73bKiaNWuNBrGkdUEJCgbI2I=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.1/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.2 h1:uIXOXcY8fs7yMhIlA1+q3t0MqpH5NVpXA+ncFszDR/0=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.2/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.4 h1:cM8CwWKqI4EldKhrERGoJ1yI7RSV9GdL5aS1eaUqg24=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.4/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.5 h1:g9f8ZQpdpyaEfoJ+GjE0dDxGlFqw4j+IwXVdlNM0xLI=
github.com/YukiOnishi1129/checkpicks-protocol-buffers/checkpicks-rpc-go v1.5.5/go.mod h1:rvek3M1fmYjn8RZ4CGWf/2DVwbghLinAn4F9IPP9enQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package externaladapter

type PageInfoDTO struct {
EndCursor string
HasNextPage bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

type ContentExternalAdapter interface {
CreateUploadArticle(ctx context.Context, dto *cpb.CreateUploadArticleRequest) (*cpb.CreateArticleResponse, error)
GetUserSavedArticle(ctx context.Context, dto *GetUserSavedArticleInputDTO) (*GetUserSavedArticleOutputDTO, error)
GetOrCreateUploadArticle(ctx context.Context, dto *GetOrCreateUploadArticleInputDTO) (*GetOrCreateUploadArticleOutputDTO, error)
}

type contentExternalAdapter struct {
Expand All @@ -21,10 +22,158 @@ func NewContentExternalAdapter(ce external.ContentExternal) ContentExternalAdapt
}
}

func (cea *contentExternalAdapter) CreateUploadArticle(ctx context.Context, dto *cpb.CreateUploadArticleRequest) (*cpb.CreateArticleResponse, error) {
res, err := cea.contentExternal.CreateUploadArticle(ctx, dto)
func (cea *contentExternalAdapter) GetUserSavedArticle(ctx context.Context, dto *GetUserSavedArticleInputDTO) (*GetUserSavedArticleOutputDTO, error) {
req := &cpb.GetUserSavedArticleRequest{
ArticleId: dto.ArticleID,
UserId: dto.UserID,
}
res, err := cea.contentExternal.GetUserSavedArticle(ctx, req)
if err != nil {
return nil, err
}
return &GetUserSavedArticleOutputDTO{
Article: cea.convertArticleDTO(res.Article),
}, nil
}

func (cea *contentExternalAdapter) GetOrCreateUploadArticle(ctx context.Context, dto *GetOrCreateUploadArticleInputDTO) (*GetOrCreateUploadArticleOutputDTO, error) {
req := &cpb.CreateUploadArticleRequest{
UserId: dto.UserID,
Title: dto.Title,
Description: dto.Description,
ArticleUrl: dto.ArticleURL,
ThumbnailUrl: dto.ThumbnailURL,
PlatformName: dto.PlatformName,
PlatformUrl: dto.PlatformURL,
PlatformFaviconUrl: dto.PlatformFaviconURL,
}

res, err := cea.contentExternal.CreateUploadArticle(ctx, req)
if err != nil {
return nil, err
}
return res, nil
return &GetOrCreateUploadArticleOutputDTO{
Article: cea.convertArticleDTO(res.Article),
}, nil
}

func (cea *contentExternalAdapter) convertArticleDTO(a *cpb.Article) *ArticleDTO {
res := &ArticleDTO{
ID: a.GetId(),
Platform: cea.convertPlatformDTO(a.GetPlatform()),
ArticleComment: cea.convertArticleCommentDTO(a.GetComment()),
Title: a.GetTitle(),
Description: a.GetDescription(),
ArticleURL: a.GetArticleUrl(),
PublishedAt: a.GetPublishedAt(),
ThumbnailURL: a.GetThumbnailUrl(),
IsEng: a.GetIsEng(),
IsPrivate: a.GetIsPrivate(),
IsBookmarked: a.GetIsBookmarked(),
IsFollowing: a.GetIsFollowing(),
FavoriteArticleFolderIDs: a.GetFavoriteArticleFolderIds(),
LikeCount: a.GetLikeCount(),
IsTrend: a.GetIsTrend(),
CreatedAt: a.GetCreatedAt(),
UpdatedAt: a.GetUpdatedAt(),
}
if a.GetAuthorName() != nil {
authorName := a.GetAuthorName().GetValue()
res.AuthorName = &authorName
}
if a.GetTags() != nil {
tags := a.GetTags().GetValue()
res.Tags = &tags
}
if a.GetBookmarkId() != nil {
bookmarkID := a.GetBookmarkId().GetValue()
res.BookmarkID = &bookmarkID
}
if a.GetFeeds() != nil && len(a.GetFeeds()) > 0 {
redFeeds := make([]*FeedDTO, len(a.GetFeeds()))
for i, f := range a.GetFeeds() {
redFeeds[i] = cea.convertDTOFeed(f)
}
}
return res
}

func (cea *contentExternalAdapter) convertPlatformDTO(p *cpb.Platform) *PlatformDTO {
if p == nil {
return nil
}
return &PlatformDTO{
ID: p.GetId(),
Name: p.GetName(),
SiteURL: p.GetSiteUrl(),
PlatformSiteType: p.GetPlatformSiteType(),
FaviconURL: p.GetFaviconUrl(),
IsEng: p.GetIsEng(),
CreatedAt: p.GetCreatedAt(),
UpdatedAt: p.GetUpdatedAt(),
DeletedAt: p.GetDeletedAt(),
}
}

func (cea *contentExternalAdapter) convertDTOFeed(f *cpb.Feed) *FeedDTO {
if f == nil {
return nil
}
res := &FeedDTO{
ID: f.GetId(),
Platform: cea.convertPlatformDTO(f.GetPlatform()),
Category: cea.convertCategoryDTO(f.GetCategory()),
MyFeedIds: f.GetMyFeedIds(),
Name: f.GetName(),
Description: f.GetDescription(),
RssURL: f.GetRssUrl(),
SiteURL: f.GetSiteUrl(),
ThumbnailURL: f.GetThumbnailUrl(),
TrendPlatformType: f.GetTrendPlatformType(),
CreatedAt: f.GetCreatedAt(),
UpdatedAt: f.GetUpdatedAt(),
}

if f.GetApiQueryParam() != nil {
apiParam := f.GetApiQueryParam().GetValue()
res.APIQueryParam = &apiParam
}
if f.GetDeletedAt() != nil {
res.DeleteAt = f.GetDeletedAt()
}

return res
}

func (cea *contentExternalAdapter) convertCategoryDTO(c *cpb.Category) *CategoryDTO {
if c == nil {
return nil
}
res := &CategoryDTO{
ID: c.GetId(),
Name: c.GetName(),
Type: c.GetType(),
CreatedAt: c.GetCreatedAt(),
UpdatedAt: c.GetUpdatedAt(),
}
if c.GetDeletedAt() != nil {
res.DeleteAt = c.GetDeletedAt()
}

return res
}

func (cea *contentExternalAdapter) convertArticleCommentDTO(ac *cpb.ArticleComment) *ArticleCommentDTO {
if ac == nil {
return nil
}
res := &ArticleCommentDTO{
ID: ac.GetId(),
UserID: ac.GetUserId(),
ArticleID: ac.GetArticleId(),
Comment: ac.GetComment(),
CreatedAt: ac.GetCreatedAt(),
UpdatedAt: ac.GetUpdatedAt(),
}
return res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package externaladapter

import (
"google.golang.org/protobuf/types/known/timestamppb"
)

type GetUserSavedArticleInputDTO struct {
ArticleID string
UserID string
}

type GetUserSavedArticleOutputDTO struct {
Article *ArticleDTO
}

type GetOrCreateUploadArticleInputDTO struct {
UserID string
Title string
Description string
ArticleURL string
ThumbnailURL string
PlatformName string
PlatformURL string
PlatformFaviconURL string
}

type GetOrCreateUploadArticleOutputDTO struct {
Article *ArticleDTO
}

type ArticleDTO struct {
ID string
Platform *PlatformDTO
Feeds []*FeedDTO
ArticleComment *ArticleCommentDTO
Title string
Description string
ArticleURL string
PublishedAt *timestamppb.Timestamp
AuthorName *string
Tags *string
ThumbnailURL string
IsEng bool
IsPrivate bool
BookmarkID *string
IsBookmarked bool
IsFollowing bool
FavoriteArticleFolderIDs []string
LikeCount int64
IsTrend bool
CreatedAt *timestamppb.Timestamp
UpdatedAt *timestamppb.Timestamp
}

type ArticleCommentDTO struct {
ID string
UserID string
ArticleID string
Comment string
CreatedAt *timestamppb.Timestamp
UpdatedAt *timestamppb.Timestamp
}

type FeedDTO struct {
ID string
Platform *PlatformDTO
Category *CategoryDTO
MyFeedIds []string
Name string
Description string
RssURL string
SiteURL string
ThumbnailURL string
TrendPlatformType int64
APIQueryParam *string
CreatedAt *timestamppb.Timestamp
UpdatedAt *timestamppb.Timestamp
DeleteAt *timestamppb.Timestamp
}

type CategoryDTO struct {
ID string
Name string
Type int64
CreatedAt *timestamppb.Timestamp
UpdatedAt *timestamppb.Timestamp
DeleteAt *timestamppb.Timestamp
}

type PlatformDTO struct {
ID string
Name string
SiteURL string
PlatformSiteType int64
FaviconURL string
IsEng bool
CreatedAt *timestamppb.Timestamp
UpdatedAt *timestamppb.Timestamp
DeletedAt *timestamppb.Timestamp
}
Loading
Loading