fix(qa): ISSUE-003 — reject posts without a title
createPost stored whatever it was given, so pressing Upload on the empty admin Post form published a blank post to the feed. Refuse a blank title, as createPage already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -8,6 +8,7 @@ package graph
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"adam-french.co.uk/backend/graph/model"
|
"adam-french.co.uk/backend/graph/model"
|
||||||
"adam-french.co.uk/backend/models"
|
"adam-french.co.uk/backend/models"
|
||||||
@@ -23,6 +24,12 @@ func (r *mutationResolver) CreatePost(ctx context.Context, input model.CreatePos
|
|||||||
return nil, fmt.Errorf("unauthorized")
|
return nil, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The admin form submits whatever is in its fields, so an accidental click
|
||||||
|
// on an empty form would otherwise publish a blank post to the feed.
|
||||||
|
if strings.TrimSpace(input.Title) == "" {
|
||||||
|
return nil, fmt.Errorf("a post needs a title")
|
||||||
|
}
|
||||||
|
|
||||||
post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID}
|
post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID}
|
||||||
if err := r.Store.DB.Create(&post).Error; err != nil {
|
if err := r.Store.DB.Create(&post).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user