40 lines
836 B
Go
40 lines
836 B
Go
package appservice
|
|
|
|
import (
|
|
"bbs-backend/api/request"
|
|
"bbs-backend/common/errcode"
|
|
"bbs-backend/dal/model"
|
|
"bbs-backend/logic/domainservice"
|
|
)
|
|
|
|
func CreatePost(req request.CreatePostRequest) (*model.Post, error) {
|
|
post := &model.Post{
|
|
Title: req.Title,
|
|
Content: req.Content,
|
|
AuthorID: 1, // 假设当前用户ID为1
|
|
}
|
|
|
|
err := domainservice.CreatePostDomainService(post)
|
|
if err != nil {
|
|
return nil, errcode.ErrInternalServerError
|
|
}
|
|
|
|
return post, nil
|
|
}
|
|
|
|
func GetPost(postID uint) (*model.Post, error) {
|
|
post, err := domainservice.GetPostDomainService(postID)
|
|
if err != nil {
|
|
return nil, errcode.ErrNotFound
|
|
}
|
|
return post, nil
|
|
}
|
|
|
|
func GetPosts() ([]*model.Post, error) {
|
|
posts, err := domainservice.GetPostsDomainService()
|
|
if err != nil {
|
|
return nil, errcode.ErrInternalServerError
|
|
}
|
|
return posts, nil
|
|
}
|