package domainservice import ( "bbs-backend/common/errcode" "bbs-backend/dal/dao" "bbs-backend/dal/model" "errors" "gorm.io/gorm" ) func CreatePostDomainService(post *model.Post) error { // 验证帖子内容 if post.Title == "" { return errcode.ErrInvalidTitle } if post.Content == "" { return errcode.ErrInvalidContent } err := dao.CreatePost(post) if err != nil { return errcode.ErrInternalServerError } return nil } func GetPostDomainService(postID uint) (*model.Post, error) { post, err := dao.GetPostByID(postID) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return nil, errcode.ErrPostNotFound } return nil, errcode.ErrInternalServerError } return post, nil } func GetPostsDomainService() ([]*model.Post, error) { posts, err := dao.GetAllPosts() if err != nil { return nil, errcode.ErrInternalServerError } return posts, nil }