feat: new proto
This commit is contained in:
		
							parent
							
								
									efff638ab5
								
							
						
					
					
						commit
						35b850d53d
					
				| 
						 | 
				
			
			@ -14,6 +14,7 @@ type Comments struct {
 | 
			
		|||
	ParentCommentID string             `bson:"parent_comment_id"` // 父留言 id,沒有就空白
 | 
			
		||||
	Message         string             `bson:"message"`           // 留言內容
 | 
			
		||||
	Level           comment.Level      `bson:"level"`             // 等級,數字較小的為上層
 | 
			
		||||
	IsVisitable     bool               `bson:"is_visitable"`      // 是否隱藏
 | 
			
		||||
	UpdatedAt       int64              `bson:"updated_at"`        // 更新時間
 | 
			
		||||
	CreatedAt       int64              `bson:"created_at"`        // 建立時間
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,7 @@ import (
 | 
			
		|||
type CommentRepository interface {
 | 
			
		||||
	CreateComment(ctx context.Context, comment *entity.Comments) error                           // 新增留言 	// 根據 ID 獲取單條留言
 | 
			
		||||
	DeleteCommentByID(ctx context.Context, id string) error                                      // 根據 ID 刪除留言 	// 刪除某留言的所有子留言
 | 
			
		||||
	UpdateCommentMessage(ctx context.Context, id string, message string) error                   // 更新留言內容
 | 
			
		||||
	UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error // 更新留言內容
 | 
			
		||||
	ListComments(ctx context.Context, req ListCommentRequest) ([]*entity.Comments, int64, error) // 分頁列出留言
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,4 +20,5 @@ type ListCommentRequest struct {
 | 
			
		|||
	ReferenceID *string
 | 
			
		||||
	ParentID    *string
 | 
			
		||||
	Level       comment.Level
 | 
			
		||||
	IsVisitable *bool
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ type CommentUseCase interface {
 | 
			
		|||
	// RemoveCommentItem 移除 CommentItem 列表
 | 
			
		||||
	RemoveCommentItem(ctx context.Context, id string) error
 | 
			
		||||
	// UpdateCommentMessage 更新
 | 
			
		||||
	UpdateCommentMessage(ctx context.Context, id string, message string) error
 | 
			
		||||
	UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CreateCommentDocs struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ type CreateCommentDocs struct {
 | 
			
		|||
	ReferenceID     string `bson:"reference_id"`      // 參考的 id  ex product_id or product_item_id 之類的
 | 
			
		||||
	ParentCommentID string `bson:"parent_comment_id"` // 父留言 id 沒有就空白
 | 
			
		||||
	Message         string `bson:"message"`           // 留言內容
 | 
			
		||||
	IsVisitable     bool   `bson:"is_visitable"`      // 是否可見
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CommentDocs struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -41,4 +42,5 @@ type ListCommentRequest struct {
 | 
			
		|||
	ReferenceID *string
 | 
			
		||||
	ParentID    *string
 | 
			
		||||
	IsSub       bool
 | 
			
		||||
	IsVisitable *bool
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,7 @@ func (repo *CommentRepository) DeleteCommentByID(ctx context.Context, id string)
 | 
			
		|||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (repo *CommentRepository) UpdateCommentMessage(ctx context.Context, id string, message string) error {
 | 
			
		||||
func (repo *CommentRepository) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error {
 | 
			
		||||
	// 驗證 ObjectID 是否有效
 | 
			
		||||
	oid, err := primitive.ObjectIDFromHex(id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -81,8 +81,9 @@ func (repo *CommentRepository) UpdateCommentMessage(ctx context.Context, id stri
 | 
			
		|||
 | 
			
		||||
	// 初始化更新字段
 | 
			
		||||
	updates := bson.M{
 | 
			
		||||
		"message":    message,                     // 更新留言內容
 | 
			
		||||
		"updated_at": time.Now().UTC().UnixNano(), // 更新時間
 | 
			
		||||
		"message":      message, // 更新留言內容
 | 
			
		||||
		"is_visitable": isVisitable,
 | 
			
		||||
		"updated_at":   time.Now().UTC().UnixNano(), // 更新時間
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 查詢條件:根據 _id 查詢
 | 
			
		||||
| 
						 | 
				
			
			@ -120,6 +121,10 @@ func (repo *CommentRepository) ListComments(ctx context.Context, req repository.
 | 
			
		|||
		filter["reference_id"] = req.ReferenceID
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if req.IsVisitable != nil {
 | 
			
		||||
		filter["is_visitable"] = req.IsVisitable
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 設置排序選項
 | 
			
		||||
	opts := options.Find().SetSkip((req.PageIndex - 1) * req.PageSize).SetLimit(req.PageSize)
 | 
			
		||||
	opts.SetSort(bson.D{{Key: "created_at", Value: -1}})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,7 @@ func (use *CommentUseCase) CreateCommentItem(ctx context.Context, info usecase.C
 | 
			
		|||
		UID:         info.UID,
 | 
			
		||||
		ReferenceID: info.ReferenceID,
 | 
			
		||||
		Level:       comment.TopLevelComment,
 | 
			
		||||
		IsVisitable: true,
 | 
			
		||||
	}
 | 
			
		||||
	snappyContent := snappy.Encode(nil, []byte(info.Message))
 | 
			
		||||
	insert.Message = base64.StdEncoding.EncodeToString(snappyContent)
 | 
			
		||||
| 
						 | 
				
			
			@ -97,8 +98,8 @@ func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usec
 | 
			
		|||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (use *CommentUseCase) UpdateCommentMessage(ctx context.Context, id string, message string) error {
 | 
			
		||||
	err := use.Comment.UpdateCommentMessage(ctx, id, message)
 | 
			
		||||
func (use *CommentUseCase) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error {
 | 
			
		||||
	err := use.Comment.UpdateCommentMessage(ctx, id, message, isVisitable)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errs.DatabaseErrorWithScopeL(
 | 
			
		||||
			code.CloudEPComment,
 | 
			
		||||
| 
						 | 
				
			
			@ -141,6 +142,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm
 | 
			
		|||
		PageSize:    req.PageSize,
 | 
			
		||||
		PageIndex:   req.PageIndex,
 | 
			
		||||
		ReferenceID: req.ReferenceID,
 | 
			
		||||
		IsVisitable: req.IsVisitable,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, 0, errs.DatabaseErrorWithScopeL(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue