From 9d8714974fb7322b6d82086bd860d8ac3dd711b1 Mon Sep 17 00:00:00 2001 From: Sep Date: Fri, 11 Apr 2025 15:25:47 +0330 Subject: [PATCH] minor update on routes.go file --- handlers/auth_handler.go | 6 +++--- handlers/comment_handler.go | 5 +++-- handlers/user_handler.go | 8 ++++---- routers/routes.go | 11 ++++++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/handlers/auth_handler.go b/handlers/auth_handler.go index 1256b00..274ed5f 100644 --- a/handlers/auth_handler.go +++ b/handlers/auth_handler.go @@ -5,10 +5,11 @@ import ( "Learning/error" "Learning/models" "Learning/token" - "github.com/gin-gonic/gin" - "golang.org/x/crypto/bcrypt" "net/http" "strings" + + "github.com/gin-gonic/gin" + "golang.org/x/crypto/bcrypt" ) // RegisterHandler @@ -81,7 +82,6 @@ func LoginHandler(c *gin.Context) { } c.IndentedJSON(http.StatusOK, tokenString) - return } // ProtectedHandler diff --git a/handlers/comment_handler.go b/handlers/comment_handler.go index 3ccd0e6..f64991e 100644 --- a/handlers/comment_handler.go +++ b/handlers/comment_handler.go @@ -4,9 +4,10 @@ import ( "Learning/database" "Learning/error" "Learning/models" - "github.com/gin-gonic/gin" "net/http" "regexp" + + "github.com/gin-gonic/gin" ) // DeleteComment @@ -75,7 +76,7 @@ func AddComment(c *gin.Context) { c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "error checking description"}) return } - if matchString == true { + if matchString { c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Description containing bad characters"}) return } diff --git a/handlers/user_handler.go b/handlers/user_handler.go index d72caa9..48a623f 100644 --- a/handlers/user_handler.go +++ b/handlers/user_handler.go @@ -19,13 +19,13 @@ import ( func AddUser(c *gin.Context) { var user models.User if err := c.ShouldBindJSON(&user); err != nil { - c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid JSON format", "error": err.Error()}) + c.IndentedJSON(http.StatusBadRequest, gin.H{"message": error.InvalidJson}) return } result := database.DB.Create(&user) if result.Error != nil { - c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Error creating user", "error": result.Error.Error()}) + c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Error creating user"}) return } @@ -42,13 +42,13 @@ func AddUser(c *gin.Context) { func DeleteUser(c *gin.Context) { var user models.User if err := c.ShouldBindJSON(&user); err != nil { - c.IndentedJSON(http.StatusBadRequest, gin.H{"message": error.InvalidJson, "error": err.Error()}) + c.IndentedJSON(http.StatusBadRequest, gin.H{"message": error.InvalidJson}) return } result := database.DB.Delete(&user) if result.Error != nil { - c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Error deleting user", "error": result.Error.Error()}) + c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Error deleting user"}) return } c.IndentedJSON(http.StatusAccepted, user) diff --git a/routers/routes.go b/routers/routes.go index 7e31c78..569ccfc 100644 --- a/routers/routes.go +++ b/routers/routes.go @@ -5,6 +5,7 @@ import ( "Learning/handlers/answer_handler" "Learning/handlers/question_handler" "Learning/middleware" + "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" @@ -27,15 +28,15 @@ func SetupRouter() *gin.Engine { protected.GET("/questions/all", question_handler.FetchQuestions) protected.POST("/questions/add", question_handler.PostQuestion) protected.GET("/questions/my", question_handler.FetchMyQuestions) - protected.GET("/questions/voteUp/:id}", question_handler.VoteUpQuestion) - protected.GET("/questions/voteDown/:id}", question_handler.VoteDownQuestion) + protected.GET("/questions/voteUp/:id", question_handler.VoteUpQuestion) + protected.GET("/questions/voteDown/:id", question_handler.VoteDownQuestion) // Answer routes protected.POST("/answer_handler/add", answer_handler.AddAnswer) protected.GET("/answer_handler/correctAnswer/:id", answer_handler.CorrectAnswer) - protected.GET("/answer_handler/voteUp/:id}", answer_handler.VoteUpAnswer) - protected.GET("/answer_handler/voteDown/:id}", answer_handler.VoteDownAnswer) - protected.GET("/answer_handler/delete", answer_handler.DeleteAnswer) + protected.GET("/answer_handler/voteUp/:id", answer_handler.VoteUpAnswer) + protected.GET("/answer_handler/voteDown/:id", answer_handler.VoteDownAnswer) + protected.DELETE("/answer_handler/delete", answer_handler.DeleteAnswer) //comment routes protected.POST("/comment/add", handlers.AddComment)