Commit ec4afd1a authored by Rafael's avatar Rafael

bugfix return nil post if not found

parent a03ee03a
Pipeline #25355612 passed with stage
in 4 minutes and 50 seconds
......@@ -171,7 +171,7 @@ func GetPost(slug string) map[string]interface{} {
}
defer rows.Close()
postsIDArray := make([]string, 0, 4)
postsIDArray := make([]string, 0, 1)
for rows.Next() {
var p post
if err := rows.Scan(&p.id, &p.slug, &p.title, &p.content, &p.publishedAt, &p.categorySlug,
......@@ -203,6 +203,9 @@ func GetPost(slug string) map[string]interface{} {
"err": err,
}).Error("rows.Err()")
}
if len(postsIDArray) == 0 {
return nil
}
// One-to-many queries
comments := getComments(db, postsIDArray)
......
......@@ -35,6 +35,9 @@ func (r *Resolver) Notifications() *NotificationResolver {
func (r *Resolver) Post(args struct{ Slug string }) *Post {
startingTime := time.Now()
p := generic.GetPost(args.Slug)
if p == nil {
return nil
}
comments := make([]Comment, 0, 2)
if p["comments"] != nil {
for _, c := range p["comments"].([]map[string]string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment