feat: 迁移plant
This commit is contained in:
@@ -3,10 +3,12 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"sundynix-micro-go/app/plant/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DeletePostLogic struct {
|
||||
@@ -23,8 +25,23 @@ func NewDeletePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
||||
}
|
||||
}
|
||||
|
||||
// 删除帖子 (级联删除评论/点赞/图片关联)
|
||||
func (l *DeletePostLogic) DeletePost(in *plant.IdsReq) (*plant.CommonResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &plant.CommonResp{}, nil
|
||||
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
|
||||
tx.Exec("DELETE FROM sundynix_post_oss WHERE post_id IN ?", in.Ids)
|
||||
if err := tx.Unscoped().Where("post_id IN ?", in.Ids).Delete(&plantModel.PostLike{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Unscoped().Where("post_id IN ?", in.Ids).Delete(&plantModel.PostComment{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Unscoped().Where("id IN ?", in.Ids).Delete(&plantModel.Post{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user