Started styling the app and have got editing posts working.
This commit is contained in:
parent
7ef6725bdb
commit
bf5d6cbe52
20 changed files with 511 additions and 41 deletions
|
|
@ -31,17 +31,51 @@ func (s *Service) ListPostOfSite(ctx context.Context, site models.Site) ([]model
|
|||
return s.db.ListPostsOfSite(ctx, site.ID)
|
||||
}
|
||||
|
||||
func (s *Service) Create(ctx context.Context, site models.Site, body string) (models.Post, error) {
|
||||
post := models.Post{
|
||||
SiteID: site.ID,
|
||||
Body: body,
|
||||
State: models.PostStatePublished,
|
||||
PostDate: time.Now(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
if err := s.db.InsertPost(ctx, &post); err != nil {
|
||||
func (s *Service) GetPost(ctx context.Context, id int) (models.Post, error) {
|
||||
post, err := s.db.GetPost(ctx, int64(id))
|
||||
if err != nil {
|
||||
return models.Post{}, err
|
||||
}
|
||||
|
||||
return post, s.jobs.Queue(ctx, s.sb.WritePost(site, post))
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (s *Service) Create(ctx context.Context, site models.Site, req NewPost) (models.Post, error) {
|
||||
post := models.Post{
|
||||
SiteID: site.ID,
|
||||
Title: req.Title,
|
||||
Body: req.Body,
|
||||
State: models.PostStatePublished,
|
||||
PostDate: time.Now(),
|
||||
}
|
||||
|
||||
if err := s.Save(ctx, site, &post); err != nil {
|
||||
return models.Post{}, err
|
||||
}
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (s *Service) Save(ctx context.Context, site models.Site, post *models.Post) error {
|
||||
post.SiteID = site.ID
|
||||
|
||||
if post.ID == 0 {
|
||||
post.CreatedAt = time.Now()
|
||||
post.UpdatedAt = time.Now()
|
||||
if err := s.db.InsertPost(ctx, post); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
post.UpdatedAt = time.Now()
|
||||
if err := s.db.UpdatePost(ctx, post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return s.jobs.Queue(ctx, s.sb.WritePost(site, *post))
|
||||
}
|
||||
|
||||
type NewPost struct {
|
||||
Title string
|
||||
Body string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue