Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions handlers/auth_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +82,6 @@ func LoginHandler(c *gin.Context) {
}

c.IndentedJSON(http.StatusOK, tokenString)
return
}

// ProtectedHandler
Expand Down
5 changes: 3 additions & 2 deletions handlers/comment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions handlers/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions routers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
Loading