serverctl/services/entry/pkg/api/routers/auth.go

29 lines
785 B
Go

package routers
import (
"github.com/gin-gonic/gin"
"net/http"
"serverctl/pkg/infrastructure/dependencies"
)
func authRouter(router *gin.Engine, d *dependencies.Dependencies) {
router.POST("/auth/register", func(c *gin.Context) {
type RegisterUser struct {
Email string `json:"email" binding:"required"`
Password string `json:"password" binding:"required"`
}
var registerUser RegisterUser
if err := c.BindJSON(&registerUser); err != nil {
return
}
createUser, err := d.UsersService.Create(registerUser.Email, registerUser.Password)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"message": "you have provided invalid input"})
return
}
c.JSON(http.StatusCreated, gin.H{"message": "user has been registered", "userId": createUser})
})
}