Implement first db-test using go-txdb
This commit is contained in:
@ -84,11 +84,13 @@ func (h *Handler) loginPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, struct {
|
||||
Token string
|
||||
User postgres.User
|
||||
Budgets []postgres.Budget
|
||||
}{t, user, budgets})
|
||||
c.JSON(http.StatusOK, LoginResponse{t, user, budgets})
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
Token string
|
||||
User postgres.User
|
||||
Budgets []postgres.Budget
|
||||
}
|
||||
|
||||
type registerInformation struct {
|
||||
@ -108,13 +110,13 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
|
||||
_, err := h.Service.GetUserByUsername(c.Request.Context(), register.Email)
|
||||
if err == nil {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("email is already taken"))
|
||||
return
|
||||
}
|
||||
|
||||
hash, err := h.CredentialsVerifier.Hash(register.Password)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -140,9 +142,5 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, struct {
|
||||
Token string
|
||||
User postgres.User
|
||||
Budgets []postgres.Budget
|
||||
}{t, user, budgets})
|
||||
c.JSON(http.StatusOK, LoginResponse{t, user, budgets})
|
||||
}
|
||||
|
Reference in New Issue
Block a user