From b3c77e3af6218c2bc2eaf88761a3e25c1f5a9fab Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Jony Date: Wed, 8 Nov 2023 16:46:32 +0600 Subject: [PATCH] #Added Post and endpoint --- api.go | 31 +++++++++++++++++++++++++++++-- awazz.go | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index a256a1a..dedaa33 100644 --- a/api.go +++ b/api.go @@ -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") @@ -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) } @@ -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 diff --git a/awazz.go b/awazz.go index 7754538..41a096b 100644 --- a/awazz.go +++ b/awazz.go @@ -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)