bbs-backend/logic/domainservice/post_domain_service.go

46 lines
888 B
Go
Raw Normal View History

2024-11-20 00:09:17 +08:00
// file name: post_domain_service.go
2024-11-19 21:08:28 +08:00
package domainservice
import (
2024-11-20 00:09:17 +08:00
"bbs-backend/api/request"
2024-11-19 21:08:28 +08:00
"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
}
2024-11-20 00:09:17 +08:00
// 创建帖子
2024-11-19 21:08:28 +08:00
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
}
2024-11-20 00:09:17 +08:00
func GetPostsDomainService(req request.GetPostsRequest) ([]*model.Post, error) {
posts, err := dao.GetPosts(req)
2024-11-19 21:08:28 +08:00
if err != nil {
return nil, errcode.ErrInternalServerError
}
return posts, nil
}