Skip to content

Commit

Permalink
Update post struct to include more user info
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhut committed Jul 28, 2020
1 parent a8f610c commit 790049b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"encoding/json"
"fmt"
"strconv"
"time"
)

Expand Down Expand Up @@ -78,11 +79,16 @@ func setupRouter(postdb models.PostDatabase, authservice services.AuthService) *
}
img_url := c.PostForm("img_url")
post_caption := c.PostForm("post_caption")
verified, _ := strconv.ParseBool(user_data["verified"].(string))

new_post := &models.Post{

Postid: primitive.NewObjectIDFromTimestamp(time.Now()),
Uid: user_data["uid"].(string),
Username: user_data["username"].(string),
Screenname: user_data["screenname"].(string),
Avatarurl: user_data["avatarurl"].(string),
Verified: verified,
Imageurl: img_url,
Caption: post_caption,
Likecount: 0,
Expand Down
4 changes: 3 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func TestCreatePost(t *testing.T) {

now := time.Now()
token := "852a37a34b727c0e0b331806-7af4bdfdcc60990d427f383efecc8529289d040dd67e0753b9e2ee5a1e938402186f28324df23f6faa4e2bbf43f584ae228c55b00143866215d6e92805d470a1cc2a096dcca4d43527598122313be412e17fbefdcdab2fae02e06a405791d936862d4fba688b3c7fd784d4"
user_data := "{\"uid\": \"1\", \"email\": \"[email protected]\", \"role\": \"standard\", \"created\": \"" + now.Format("2006-01-02T15:04:05") + "\"}"
user_data := "{\"uid\": \"1\", \"email\": \"[email protected]\", \"role\": \"standard\", \"created\": \"" +
now.Format("2006-01-02T15:04:05") +
"\", \"username\": \"test_email\", \"screenname\": \"test_email\", \"avatarurl\": \"http://localhost/img.png\", \"verified\": \"False\" }"
image_url := "http://localhost/img.png"
caption := "test caption"

Expand Down
4 changes: 4 additions & 0 deletions models/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type postDatabase struct {
type Post struct {
Postid primitive.ObjectID `bson:"_id, omitempty"`
Uid string
Username string
Screenname string
Avatarurl string
Verified bool
Imageurl string
Caption string
Likecount int
Expand Down

0 comments on commit 790049b

Please sign in to comment.