Skip to content

Commit

Permalink
feat: 合并collection、post、moment
Browse files Browse the repository at this point in the history
  • Loading branch information
foliet authored and fuqihao.foliet committed Aug 5, 2023
1 parent 4a95e77 commit e5b1b82
Show file tree
Hide file tree
Showing 33 changed files with 2,039 additions and 630 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
REGISTRY: docker.io
USERNAME: xhpolaris
# github.repository as <account>/<repo>
IMAGE_NAME: xhpolaris/meowchat-collection
IMAGE_NAME: xhpolaris/meowchat-content

jobs:
build:
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ jobs:
target:
- linux-amd64-fmt
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "stable"
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: go test
run: go test ./...
version: latest
85 changes: 69 additions & 16 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,104 @@ package adaptor

import (
"context"
"github.com/xh-polaris/service-idl-gen-go/kitex_gen/meowchat/content"

"github.com/xh-polaris/meowchat-collection/biz/application/service"
"github.com/xh-polaris/meowchat-collection/biz/infrastructure/config"

"github.com/xh-polaris/service-idl-gen-go/kitex_gen/meowchat/collection"
"github.com/xh-polaris/meowchat-content/biz/application/service"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/config"
)

type CollectionServerImpl struct {
type ContentServerImpl struct {
*config.Config
CatService service.CatService
ImageService service.ImageService
CatService service.ICatService
ImageService service.IImageService
MomentService service.IMomentService
PostService service.IPostService
}

func (s *CollectionServerImpl) SearchCat(ctx context.Context, req *collection.SearchCatReq) (res *collection.SearchCatResp, err error) {
func (s *ContentServerImpl) SearchCat(ctx context.Context, req *content.SearchCatReq) (res *content.SearchCatResp, err error) {
return s.CatService.SearchCat(ctx, req)
}

func (s *CollectionServerImpl) ListCat(ctx context.Context, req *collection.ListCatReq) (res *collection.ListCatResp, err error) {
func (s *ContentServerImpl) ListCat(ctx context.Context, req *content.ListCatReq) (res *content.ListCatResp, err error) {
return s.CatService.ListCat(ctx, req)
}

func (s *CollectionServerImpl) RetrieveCat(ctx context.Context, req *collection.RetrieveCatReq) (res *collection.RetrieveCatResp, err error) {
func (s *ContentServerImpl) RetrieveCat(ctx context.Context, req *content.RetrieveCatReq) (res *content.RetrieveCatResp, err error) {
return s.CatService.RetrieveCat(ctx, req)
}

func (s *CollectionServerImpl) CreateCat(ctx context.Context, req *collection.CreateCatReq) (res *collection.CreateCatResp, err error) {
func (s *ContentServerImpl) CreateCat(ctx context.Context, req *content.CreateCatReq) (res *content.CreateCatResp, err error) {
return s.CatService.CreateCat(ctx, req)
}

func (s *CollectionServerImpl) UpdateCat(ctx context.Context, req *collection.UpdateCatReq) (res *collection.UpdateCatResp, err error) {
func (s *ContentServerImpl) UpdateCat(ctx context.Context, req *content.UpdateCatReq) (res *content.UpdateCatResp, err error) {
return s.CatService.UpdateCat(ctx, req)
}

func (s *CollectionServerImpl) DeleteCat(ctx context.Context, req *collection.DeleteCatReq) (res *collection.DeleteCatResp, err error) {
func (s *ContentServerImpl) DeleteCat(ctx context.Context, req *content.DeleteCatReq) (res *content.DeleteCatResp, err error) {
return s.CatService.DeleteCat(ctx, req)
}

func (s *CollectionServerImpl) CreateImage(ctx context.Context, req *collection.CreateImageReq) (res *collection.CreateImageResp, err error) {
func (s *ContentServerImpl) CreateImage(ctx context.Context, req *content.CreateImageReq) (res *content.CreateImageResp, err error) {
return s.ImageService.CreateImage(ctx, req)
}

func (s *CollectionServerImpl) DeleteImage(ctx context.Context, req *collection.DeleteImageReq) (res *collection.DeleteImageResp, err error) {
func (s *ContentServerImpl) DeleteImage(ctx context.Context, req *content.DeleteImageReq) (res *content.DeleteImageResp, err error) {
return s.ImageService.DeleteImage(ctx, req)
}

func (s *CollectionServerImpl) ListImage(ctx context.Context, req *collection.ListImageReq) (res *collection.ListImageResp, err error) {
func (s *ContentServerImpl) ListImage(ctx context.Context, req *content.ListImageReq) (res *content.ListImageResp, err error) {
return s.ImageService.ListImage(ctx, req)
}

func (s *ContentServerImpl) ListMoment(ctx context.Context, req *content.ListMomentReq) (res *content.ListMomentResp, err error) {
return s.MomentService.ListMoment(ctx, req)
}

func (s *ContentServerImpl) CountMoment(ctx context.Context, req *content.CountMomentReq) (res *content.CountMomentResp, err error) {
return s.MomentService.CountMoment(ctx, req)
}

func (s *ContentServerImpl) RetrieveMoment(ctx context.Context, req *content.RetrieveMomentReq) (res *content.RetrieveMomentResp, err error) {
return s.MomentService.RetrieveMoment(ctx, req)
}

func (s *ContentServerImpl) CreateMoment(ctx context.Context, req *content.CreateMomentReq) (res *content.CreateMomentResp, err error) {
return s.MomentService.CreateMoment(ctx, req)
}

func (s *ContentServerImpl) UpdateMoment(ctx context.Context, req *content.UpdateMomentReq) (res *content.UpdateMomentResp, err error) {
return s.MomentService.UpdateMoment(ctx, req)
}

func (s *ContentServerImpl) DeleteMoment(ctx context.Context, req *content.DeleteMomentReq) (res *content.DeleteMomentResp, err error) {
return s.MomentService.DeleteMoment(ctx, req)
}

func (s *ContentServerImpl) CreatePost(ctx context.Context, req *content.CreatePostReq) (res *content.CreatePostResp, err error) {
return s.PostService.CreatePost(ctx, req)
}

func (s *ContentServerImpl) RetrievePost(ctx context.Context, req *content.RetrievePostReq) (res *content.RetrievePostResp, err error) {
return s.PostService.RetrievePost(ctx, req)
}

func (s *ContentServerImpl) UpdatePost(ctx context.Context, req *content.UpdatePostReq) (res *content.UpdatePostResp, err error) {
return s.PostService.UpdatePost(ctx, req)
}

func (s *ContentServerImpl) DeletePost(ctx context.Context, req *content.DeletePostReq) (res *content.DeletePostResp, err error) {
return s.PostService.DeletePost(ctx, req)
}

func (s *ContentServerImpl) ListPost(ctx context.Context, req *content.ListPostReq) (res *content.ListPostResp, err error) {
return s.PostService.ListPost(ctx, req)
}

func (s *ContentServerImpl) CountPost(ctx context.Context, req *content.CountPostReq) (res *content.CountPostResp, err error) {
return s.PostService.CountPost(ctx, req)
}

func (s *ContentServerImpl) SetOfficial(ctx context.Context, req *content.SetOfficialReq) (res *content.SetOfficialResp, err error) {
return s.PostService.SetOfficial(ctx, req)
}
82 changes: 41 additions & 41 deletions biz/application/service/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@ package service
import (
"context"

"github.com/xh-polaris/meowchat-collection/biz/infrastructure/consts"
"github.com/xh-polaris/meowchat-collection/biz/infrastructure/data/db"
"github.com/xh-polaris/meowchat-collection/biz/infrastructure/mapper"
"github.com/xh-polaris/service-idl-gen-go/kitex_gen/meowchat/collection"
"github.com/xh-polaris/meowchat-content/biz/infrastructure/consts"
catmapper "github.com/xh-polaris/meowchat-content/biz/infrastructure/mapper/cat"

"github.com/google/wire"
"github.com/jinzhu/copier"
"github.com/xh-polaris/service-idl-gen-go/kitex_gen/meowchat/content"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type CatService interface {
SearchCat(ctx context.Context, req *collection.SearchCatReq) (res *collection.SearchCatResp, err error)
ListCat(ctx context.Context, req *collection.ListCatReq) (res *collection.ListCatResp, err error)
RetrieveCat(ctx context.Context, req *collection.RetrieveCatReq) (res *collection.RetrieveCatResp, err error)
CreateCat(ctx context.Context, req *collection.CreateCatReq) (res *collection.CreateCatResp, err error)
UpdateCat(ctx context.Context, req *collection.UpdateCatReq) (res *collection.UpdateCatResp, err error)
DeleteCat(ctx context.Context, req *collection.DeleteCatReq) (res *collection.DeleteCatResp, err error)
type ICatService interface {
SearchCat(ctx context.Context, req *content.SearchCatReq) (res *content.SearchCatResp, err error)
ListCat(ctx context.Context, req *content.ListCatReq) (res *content.ListCatResp, err error)
RetrieveCat(ctx context.Context, req *content.RetrieveCatReq) (res *content.RetrieveCatResp, err error)
CreateCat(ctx context.Context, req *content.CreateCatReq) (res *content.CreateCatResp, err error)
UpdateCat(ctx context.Context, req *content.UpdateCatReq) (res *content.UpdateCatResp, err error)
DeleteCat(ctx context.Context, req *content.DeleteCatReq) (res *content.DeleteCatResp, err error)
}

type CatServiceImpl struct {
CatModel mapper.CatModel
type CatService struct {
CatMongoMapper catmapper.IMongoMapper
CatEsMapper catmapper.IEsMapper
}

var CatSet = wire.NewSet(
wire.Struct(new(CatServiceImpl), "*"),
wire.Bind(new(CatService), new(*CatServiceImpl)),
wire.Struct(new(CatService), "*"),
wire.Bind(new(ICatService), new(*CatService)),
)

func (s *CatServiceImpl) SearchCat(ctx context.Context, req *collection.SearchCatReq) (res *collection.SearchCatResp, err error) {
data, total, err := s.CatModel.Search(ctx, req.CommunityId, req.Keyword, req.Skip, req.Count)
func (s *CatService) SearchCat(ctx context.Context, req *content.SearchCatReq) (res *content.SearchCatResp, err error) {
data, total, err := s.CatEsMapper.Search(ctx, req.CommunityId, req.Keyword, int(req.Skip), int(req.Count))
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
var cats []*collection.Cat
var cats []*content.Cat
for _, val := range data {
cat := &collection.Cat{}
cat := &content.Cat{}
err = copier.Copy(cat, val)
if err != nil {
return nil, err
Expand All @@ -50,17 +50,17 @@ func (s *CatServiceImpl) SearchCat(ctx context.Context, req *collection.SearchCa
cat.CreateAt = val.CreateAt.Unix()
cats = append(cats, cat)
}
return &collection.SearchCatResp{Cats: cats, Total: total}, nil
return &content.SearchCatResp{Cats: cats, Total: total}, nil
}

func (s *CatServiceImpl) ListCat(ctx context.Context, req *collection.ListCatReq) (res *collection.ListCatResp, err error) {
data, total, err := s.CatModel.FindManyByCommunityId(ctx, req.CommunityId, req.Skip, req.Count)
func (s *CatService) ListCat(ctx context.Context, req *content.ListCatReq) (res *content.ListCatResp, err error) {
data, total, err := s.CatMongoMapper.FindManyByCommunityId(ctx, req.CommunityId, req.Skip, req.Count)
if err != nil {
return nil, err
}
var cats []*collection.Cat
var cats []*content.Cat
for _, val := range data {
cat := &collection.Cat{}
cat := &content.Cat{}
err = copier.Copy(cat, val)
if err != nil {
return nil, err
Expand All @@ -69,43 +69,43 @@ func (s *CatServiceImpl) ListCat(ctx context.Context, req *collection.ListCatReq
cat.CreateAt = val.CreateAt.Unix()
cats = append(cats, cat)
}
return &collection.ListCatResp{Cats: cats, Total: total}, nil
return &content.ListCatResp{Cats: cats, Total: total}, nil
}

func (s *CatServiceImpl) RetrieveCat(ctx context.Context, req *collection.RetrieveCatReq) (res *collection.RetrieveCatResp, err error) {
data, err := s.CatModel.FindOne(ctx, req.CatId)
func (s *CatService) RetrieveCat(ctx context.Context, req *content.RetrieveCatReq) (res *content.RetrieveCatResp, err error) {
data, err := s.CatMongoMapper.FindOne(ctx, req.CatId)
switch err {
case nil:
case mapper.ErrNotFound:
case consts.ErrNotFound:
return nil, consts.ErrNoSuchCat
default:
return nil, err
}
cat := &collection.Cat{}
cat := &content.Cat{}
err = copier.Copy(cat, data)
if err != nil {
return nil, err
}
cat.Id = data.ID.Hex()
cat.CreateAt = data.CreateAt.Unix()
return &collection.RetrieveCatResp{Cat: cat}, nil
return &content.RetrieveCatResp{Cat: cat}, nil
}

func (s *CatServiceImpl) CreateCat(ctx context.Context, req *collection.CreateCatReq) (res *collection.CreateCatResp, err error) {
cat := &db.Cat{}
func (s *CatService) CreateCat(ctx context.Context, req *content.CreateCatReq) (res *content.CreateCatResp, err error) {
cat := &catmapper.Cat{}
err = copier.Copy(cat, req.Cat)
if err != nil {
return nil, err
}
err = s.CatModel.Insert(ctx, cat)
err = s.CatMongoMapper.Insert(ctx, cat)
if err != nil {
return nil, err
}
return &collection.CreateCatResp{CatId: cat.ID.Hex()}, nil
return &content.CreateCatResp{CatId: cat.ID.Hex()}, nil
}

func (s *CatServiceImpl) UpdateCat(ctx context.Context, req *collection.UpdateCatReq) (res *collection.UpdateCatResp, err error) {
cat := &db.Cat{}
func (s *CatService) UpdateCat(ctx context.Context, req *content.UpdateCatReq) (res *content.UpdateCatResp, err error) {
cat := &catmapper.Cat{}
err = copier.Copy(cat, req.Cat)
if err != nil {
return nil, err
Expand All @@ -114,17 +114,17 @@ func (s *CatServiceImpl) UpdateCat(ctx context.Context, req *collection.UpdateCa
if err != nil {
return nil, consts.ErrInvalidId
}
err = s.CatModel.Update(ctx, cat)
err = s.CatMongoMapper.Update(ctx, cat)
if err != nil {
return nil, err
}
return &collection.UpdateCatResp{}, nil
return &content.UpdateCatResp{}, nil
}

func (s *CatServiceImpl) DeleteCat(ctx context.Context, req *collection.DeleteCatReq) (res *collection.DeleteCatResp, err error) {
err = s.CatModel.Delete(ctx, req.CatId)
func (s *CatService) DeleteCat(ctx context.Context, req *content.DeleteCatReq) (res *content.DeleteCatResp, err error) {
err = s.CatMongoMapper.Delete(ctx, req.CatId)
if err != nil {
return nil, err
}
return &collection.DeleteCatResp{}, nil
return &content.DeleteCatResp{}, nil
}
Loading

0 comments on commit e5b1b82

Please sign in to comment.