Skip to content

Commit

Permalink
add internal endpoint to bulk create testing post
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhut committed Aug 8, 2020
1 parent 8e5b05f commit a5c2ee3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,49 @@ func setupRouter(postdb models.PostDatabase, authservice services.AuthService) *

})

// Internal post endpoint

router.POST("internal/post", func(c *gin.Context) {

span := tracer.StartSpan("internal create post")

img_url := c.PostForm("img_url")
post_caption := c.PostForm("post_caption")
uid := c.PostForm("uid")
username := c.PostForm("username")
screenname := c.PostForm("screenname")
avatarurl := c.PostForm("avatarurl")

new_post := &models.Post{

Postid: primitive.NewObjectIDFromTimestamp(time.Now()),
Uid: uid,
Username: username,
Screenname: screenname,
Avatarurl: avatarurl,
Verified: false,
Imageurl: img_url,
Caption: post_caption,
Likecount: 0,
Private: false,
Commentcount: 0,
Viewcount: 0,
Created: time.Now(),
Tag: make([]string, 1),
}

_, create_error := postdb.Create(new_post)
if create_error == nil {
c.String(200, "ok")
span.Finish()
} else {
c.String(503, "error")
span.Finish()
panic("failed create post")
}

})

return router

}
Expand Down

0 comments on commit a5c2ee3

Please sign in to comment.