改进 删除 Post 逻辑
This commit is contained in:
parent
3e1c44839b
commit
933399efb3
@ -59,7 +59,23 @@ func (s *Service) CreatePost(c context.Context, applicationEntity *entity.Applic
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) DeletePost(c context.Context, post *entity.Post) error {
|
func (s *Service) DeletePost(c context.Context, post *entity.Post) error {
|
||||||
_, err := s.dao.WithContext(c).Post.Delete(post)
|
// 删除所有关联的标签
|
||||||
|
_, err := s.dao.UserLike.Where(s.dao.UserLike.PostId.Eq(post.Id.Uint())).Delete()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.dao.PostTag.Where(s.dao.PostTag.PostId.Eq(post.Id.Uint())).Delete()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.RemovePostEmbedding(c, post)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.dao.WithContext(c).Post.Delete(post)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package post
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
entity2 "github.com/milvus-io/milvus-sdk-go/v2/entity"
|
entity2 "github.com/milvus-io/milvus-sdk-go/v2/entity"
|
||||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||||
)
|
)
|
||||||
@ -142,3 +143,10 @@ func (s *Service) SavePostEmbedding(c context.Context, post *entity.Post) error
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) RemovePostEmbedding(c context.Context, post *entity.Post) error {
|
||||||
|
var filter = fmt.Sprintf(`psot_id == %d`, post.Id)
|
||||||
|
errDelete := s.milvus.Delete(c, s.config.Milvus.PostCollection, "", filter)
|
||||||
|
|
||||||
|
return errDelete
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user