add postgres and refactor code
This commit is contained in:
@@ -129,7 +129,7 @@ func (h *Handler) DeleteUser(c echo.Context) (err error) {
|
||||
}
|
||||
|
||||
func (h *Handler) CreateUser(c echo.Context) (err error) {
|
||||
var user = new(model.User)
|
||||
user := new(model.APIUser)
|
||||
|
||||
if err = c.Bind(user); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
@@ -137,13 +137,17 @@ func (h *Handler) CreateUser(c echo.Context) (err error) {
|
||||
|
||||
user.Password = fmt.Sprintf("%x", sha256.Sum256([]byte(user.Password)))
|
||||
|
||||
tx := h.DB.Create(user)
|
||||
newUser, err := utils.TypeConverter[model.User](&user)
|
||||
|
||||
tx := h.DB.Create(&newUser)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
user.Password = ""
|
||||
newUser.Password = ""
|
||||
|
||||
return c.JSON(http.StatusCreated, user)
|
||||
h.DB.Find(&newUser.Position, newUser.PositionID)
|
||||
|
||||
return c.JSON(http.StatusCreated, newUser)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user