Skip to content

Commit

Permalink
#Added Post and endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JonyBepary committed Nov 8, 2023
1 parent 99e92fb commit b3c77e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,15 @@ func saveComment(c *gin.Context) {
c.JSON(500, gin.H{"error": err.Error()})
return
}
p.Likes, err = strconv.ParseInt(c.Query("Likes"), 10, 64)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}

// PRINT instance OBJECT TO CONSOLE INTENDED FOR DEBUGGING
spew.Config.Indent = "\t"
spew.Dump(p)
// spew.Config.Indent = "\t"
// spew.Dump(&p)

// getting array of string from QueryArray
p.Replies = c.QueryArray("Replies")
Expand All @@ -770,6 +776,13 @@ func saveComment(c *gin.Context) {
return
}

shard := pkg.StringToShard(p.PostId)
err = p.SavetoSQL(shard)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}

c.JSON(200, &p)
}

Expand All @@ -794,6 +807,20 @@ func getComment(c *gin.Context) {

c.JSON(200, &p)
}
func getCommentsByPost(c *gin.Context) {

var p []model.Comment
PostId := c.Query("pid")
//! println("pid: " + pid)
// err := p.GetCommunity(Iid)
err := model.GetFromByPost(&p, PostId)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}

c.JSON(200, &p)
}

func delComment(c *gin.Context) {
var comment model.Comment
Expand Down
1 change: 1 addition & 0 deletions awazz.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
r.DELETE("/instance", delInstance)
r.POST("/comments", saveComment)
r.GET("/comments", getComment)
r.GET("/commentsbypost", getCommentsByPost)
r.DELETE("/comments", delComment)
r.POST("/message", saveMessage)
r.GET("/message", getMessage)
Expand Down

0 comments on commit b3c77e3

Please sign in to comment.