feature/post_v2 #2

Merged
daniel.w merged 5 commits from feature/post_v2 into main 2024-08-30 07:08:46 +00:00
7 changed files with 21 additions and 89 deletions
Showing only changes of commit 3bf7909c62 - Show all commits

View File

@ -6,10 +6,11 @@ import (
"app-cloudep-tweeting-service/internal/svc"
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.uber.org/mock/gomock"
"testing"
mocklib "app-cloudep-tweeting-service/internal/mock/lib"
mockmodel "app-cloudep-tweeting-service/internal/mock/model"

View File

@ -6,10 +6,11 @@ import (
"app-cloudep-tweeting-service/internal/svc"
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.uber.org/mock/gomock"
"testing"
mocklib "app-cloudep-tweeting-service/internal/mock/lib"
mockmodel "app-cloudep-tweeting-service/internal/mock/model"

View File

@ -7,12 +7,13 @@ import (
"app-cloudep-tweeting-service/internal/svc"
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.uber.org/mock/gomock"
"google.golang.org/protobuf/proto"
"testing"
)
func TestUpdateComment(t *testing.T) {

View File

@ -4,14 +4,9 @@ import (
"app-cloudep-tweeting-service/internal/domain"
model "app-cloudep-tweeting-service/internal/model/mongo"
"code.30cm.net/digimon/library-go/errs/code"
"context"
"fmt"
"strings"
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
"app-cloudep-tweeting-service/internal/svc"
"context"
ers "code.30cm.net/digimon/library-go/errs"
"github.com/zeromicro/go-zero/core/logx"
@ -41,23 +36,6 @@ type newTweetingReq struct {
IsAd bool `json:"is_ad"` // default false
}
// 定義 Error
// CreatePostError 0502102 資料庫錯誤
func CreatePostError(s ...string) *ers.LibError {
return ers.NewError(code.CloudEPTweeting, code.DBError,
domain.CreatePostError.ToUint32(),
fmt.Sprintf("%s", strings.Join(s, " ")))
}
// CreatePostErrorL logs error message and returns Error
func CreatePostErrorL(l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError {
e := CreatePostError(s...)
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
return e
}
// CreatePost 新增貼文
func (l *CreatePostLogic) CreatePost(in *tweeting.NewPostReq) (*tweeting.PostResp, error) {
// 驗證資料
@ -97,7 +75,9 @@ func (l *CreatePostLogic) CreatePost(in *tweeting.NewPostReq) (*tweeting.PostRes
// ============ insert ============
err := l.svcCtx.PostModel.Insert(l.ctx, tweet)
if err != nil {
e := CreatePostErrorL(
// 錯誤代碼 05-021-02
e := domain.CommentErrorL(
domain.CreatePostError,
logx.WithContext(l.ctx),
[]logx.LogField{
{Key: "req", Value: in},

View File

@ -1,16 +1,10 @@
package postservicelogic
import (
"app-cloudep-tweeting-service/internal/domain"
"context"
"fmt"
"strings"
ers "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
"app-cloudep-tweeting-service/internal/domain"
"app-cloudep-tweeting-service/internal/svc"
"context"
"github.com/zeromicro/go-zero/core/logx"
)
@ -29,26 +23,13 @@ func NewDeletePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
}
}
// DeletePostError 0502103 資料庫錯誤
func DeletePostError(s ...string) *ers.LibError {
return ers.NewError(code.CloudEPTweeting, code.DBError,
domain.DelPostError.ToUint32(),
fmt.Sprintf("%s", strings.Join(s, " ")))
}
// DeletePostErrorL logs error message and returns Error
func DeletePostErrorL(l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError {
e := DeletePostError(s...)
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
return e
}
// DeletePost 刪除貼文
func (l *DeletePostLogic) DeletePost(in *tweeting.DeletePostsReq) (*tweeting.OKResp, error) {
_, err := l.svcCtx.PostModel.DeleteMany(l.ctx, in.GetPostId()...)
if err != nil {
e := DeletePostErrorL(
// 錯誤代碼 05-021-03
e := domain.CommentErrorL(
domain.DelPostError,
logx.WithContext(l.ctx),
[]logx.LogField{
{Key: "req", Value: in},

View File

@ -4,11 +4,8 @@ import (
"app-cloudep-tweeting-service/internal/domain"
model "app-cloudep-tweeting-service/internal/model/mongo"
"context"
"fmt"
"strings"
ers "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"google.golang.org/protobuf/proto"
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
@ -38,21 +35,6 @@ type listReq struct {
PageIndex int64 `json:"page_index" validate:"required"`
}
// ListPostError 0502105 資料庫錯誤
func ListPostError(s ...string) *ers.LibError {
return ers.NewError(code.CloudEPTweeting, code.DBError,
domain.ListPostError.ToUint32(),
fmt.Sprintf("%s", strings.Join(s, " ")))
}
// ListPostErrorL logs error message and returns Error
func ListPostErrorL(l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError {
e := ListPostError(s...)
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
return e
}
// 將單個 Post 轉換為 PostDetailItem
func convertToPostDetailItem(item *model.Post) *tweeting.PostDetailItem {
media := make([]*tweeting.Media, 0, len(item.MediaURL))
@ -110,7 +92,9 @@ func (l *ListPostsLogic) ListPosts(in *tweeting.QueryPostsReq) (*tweeting.ListPo
// 執行查詢
find, count, err := l.svcCtx.PostModel.Find(l.ctx, query)
if err != nil {
e := ListPostErrorL(
// 錯誤代碼 05-021-05
e := domain.CommentErrorL(
domain.ListPostError,
logx.WithContext(l.ctx),
[]logx.LogField{
{Key: "query", Value: query},

View File

@ -4,11 +4,8 @@ import (
"app-cloudep-tweeting-service/internal/domain"
model "app-cloudep-tweeting-service/internal/model/mongo"
"context"
"fmt"
"strings"
ers "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"go.mongodb.org/mongo-driver/bson/primitive"
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
@ -36,21 +33,6 @@ type checkPostId struct {
Content string `json:"content,omitempty" validate:"lte=500"`
}
// UpdatePostError 0502104 資料庫錯誤
func UpdatePostError(s ...string) *ers.LibError {
return ers.NewError(code.CloudEPTweeting, code.DBError,
domain.UpdatePostError.ToUint32(),
fmt.Sprintf("%s", strings.Join(s, " ")))
}
// UpdatePostErrorL logs error message and returns Error
func UpdatePostErrorL(l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError {
e := UpdatePostError(s...)
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
return e
}
// UpdatePost 更新貼文
func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKResp, error) {
// 驗證資料
@ -96,7 +78,9 @@ func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKRe
_, err = l.svcCtx.PostModel.UpdateOptional(l.ctx, &update)
if err != nil {
e := UpdatePostErrorL(
// 錯誤代碼 05-021-04
e := domain.CommentErrorL(
domain.UpdatePostError,
logx.WithContext(l.ctx),
[]logx.LogField{
{Key: "req", Value: in},