Allow to get a blog post's content by slug
This commit is contained in:
parent
af691bee1c
commit
f1fa5e8b91
|
@ -74,11 +74,22 @@ func BlogPostsContentGET(md common.MethodData) common.CodeMessager {
|
||||||
if _, present := md.C.GetQuery("html"); present {
|
if _, present := md.C.GetQuery("html"); present {
|
||||||
field = "html"
|
field = "html"
|
||||||
}
|
}
|
||||||
if md.C.Query("id") == "" {
|
var (
|
||||||
return ErrMissingField("id")
|
by string
|
||||||
|
val string
|
||||||
|
)
|
||||||
|
switch {
|
||||||
|
case md.C.Query("slug") != "":
|
||||||
|
by = "slug"
|
||||||
|
val = md.C.Query("slug")
|
||||||
|
case md.C.Query("id") != "":
|
||||||
|
by = "id"
|
||||||
|
val = md.C.Query("id")
|
||||||
|
default:
|
||||||
|
return ErrMissingField("id|slug")
|
||||||
}
|
}
|
||||||
var r blogPostContent
|
var r blogPostContent
|
||||||
err := md.DB.QueryRow("SELECT "+field+" FROM anchor_posts WHERE id = ? AND status = 'published'", md.C.Query("id")).Scan(&r.Content)
|
err := md.DB.QueryRow("SELECT "+field+" FROM anchor_posts WHERE "+by+" = ? AND status = 'published'", val).Scan(&r.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.SimpleResponse(404, "no blog post found")
|
return common.SimpleResponse(404, "no blog post found")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user