// file name: post_domain_service.go package domainservice import ( "bbs-backend/api/request" "bbs-backend/common/errcode" "bbs-backend/dal/dao" "bbs-backend/dal/model" ) 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 { return nil, errcode.ErrInternalServerError } return post, nil } func GetPostsDomainService(req request.GetPostsRequest) ([]*model.Post, error) { posts, err := dao.GetPosts(req) if err != nil { return nil, errcode.ErrInternalServerError } return posts, nil }