38 lines
683 B
Go
38 lines
683 B
Go
|
|
package posts
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"lmika.dev/lmika/weiro/models"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (s *Service) ListPosts(ctx context.Context) ([]*models.Post, error) {
|
||
|
|
site, ok := models.GetSite(ctx)
|
||
|
|
if !ok {
|
||
|
|
return nil, models.SiteRequiredError
|
||
|
|
}
|
||
|
|
|
||
|
|
posts, err := s.db.SelectPostsOfSite(ctx, site.ID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return posts, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *Service) GetPost(ctx context.Context, pid int64) (*models.Post, error) {
|
||
|
|
site, ok := models.GetSite(ctx)
|
||
|
|
if !ok {
|
||
|
|
return nil, models.SiteRequiredError
|
||
|
|
}
|
||
|
|
|
||
|
|
post, err := s.db.SelectPost(ctx, pid)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
} else if post.SiteID != site.ID {
|
||
|
|
return nil, models.NotFoundError
|
||
|
|
}
|
||
|
|
|
||
|
|
return post, nil
|
||
|
|
}
|