mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-04 00:06:22 +00:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"github.com/snowykami/neo-blog/internal/ctxutils"
|
|
"github.com/snowykami/neo-blog/internal/dto"
|
|
"github.com/snowykami/neo-blog/internal/model"
|
|
"github.com/snowykami/neo-blog/internal/repo"
|
|
"github.com/snowykami/neo-blog/pkg/errs"
|
|
"net/http"
|
|
)
|
|
|
|
type PostService struct{}
|
|
|
|
func NewPostService() *PostService {
|
|
return &PostService{}
|
|
}
|
|
|
|
func (p *PostService) CreatePost(ctx context.Context, req *dto.CreateOrUpdatePostReq) error {
|
|
currentUser := ctxutils.GetCurrentUser(ctx)
|
|
if currentUser == nil {
|
|
return errs.ErrUnauthorized
|
|
}
|
|
|
|
post := &model.Post{
|
|
Title: req.Title,
|
|
Content: req.Content,
|
|
UserID: currentUser.ID,
|
|
Labels: req.Labels,
|
|
IsPrivate: req.IsPrivate,
|
|
}
|
|
|
|
if err := repo.Post.CreatePost(post); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *PostService) DeletePost(ctx context.Context, id string) error {
|
|
}
|
|
|
|
func (p *PostService) GetPost(ctx context.Context, id string) (*model.Post, error) {}
|
|
|
|
func (p *PostService) UpdatePost(req *dto.CreateOrUpdatePostReq) error {}
|
|
|
|
func (p *PostService) ListPosts() {}
|