adding rest-api
This commit is contained in:
28
rest-api/routes/users.go
Normal file
28
rest-api/routes/users.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"example.com/rest-api/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func signup(context *gin.Context) {
|
||||
var user models.User
|
||||
|
||||
err := context.ShouldBindJSON(&user)
|
||||
|
||||
if err != nil {
|
||||
context.JSON(http.StatusBadRequest, gin.H{"message": "Could not parse request data."})
|
||||
return
|
||||
}
|
||||
|
||||
err = user.Save()
|
||||
|
||||
if err != nil {
|
||||
context.JSON(http.StatusInternalServerError, gin.H{"message": "Could not save user."})
|
||||
return
|
||||
}
|
||||
|
||||
context.JSON(http.StatusCreated, gin.H{"message": "User created successfully"})
|
||||
}
|
||||
Reference in New Issue
Block a user