Implement first db-test using go-txdb

This commit is contained in:
2022-02-09 22:25:51 +00:00
parent c3db535e10
commit 6ab8a96888
4 changed files with 60 additions and 29 deletions

View File

@ -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})
}