Fix issues from golangci
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"git.javil.eu/jacob1123/budgeteer"
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
|
||||
@@ -77,7 +78,7 @@ func (h *Handler) loginPost(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
}
|
||||
|
||||
go h.Service.UpdateLastLogin(context.Background(), user.ID)
|
||||
go h.UpdateLastLogin(user.ID)
|
||||
|
||||
budgets, err := h.Service.GetBudgetsForUser(c.Request.Context(), user.ID)
|
||||
if err != nil {
|
||||
@@ -101,14 +102,18 @@ type registerInformation struct {
|
||||
|
||||
func (h *Handler) registerPost(c *gin.Context) {
|
||||
var register registerInformation
|
||||
c.BindJSON(®ister)
|
||||
err := c.BindJSON(®ister)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse body: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
if register.Email == "" || register.Password == "" || register.Name == "" {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("e-mail, password and name are required"))
|
||||
return
|
||||
}
|
||||
|
||||
_, err := h.Service.GetUserByUsername(c.Request.Context(), register.Email)
|
||||
_, err = h.Service.GetUserByUsername(c.Request.Context(), register.Email)
|
||||
if err == nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("email is already taken"))
|
||||
return
|
||||
@@ -135,7 +140,7 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusUnauthorized, err)
|
||||
}
|
||||
|
||||
go h.Service.UpdateLastLogin(context.Background(), user.ID)
|
||||
go h.UpdateLastLogin(user.ID)
|
||||
|
||||
budgets, err := h.Service.GetBudgetsForUser(c.Request.Context(), user.ID)
|
||||
if err != nil {
|
||||
@@ -144,3 +149,10 @@ func (h *Handler) registerPost(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, LoginResponse{t, user, budgets})
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateLastLogin(userID uuid.UUID) {
|
||||
_, err := h.Service.UpdateLastLogin(context.Background(), userID)
|
||||
if err != nil {
|
||||
fmt.Printf("Error updating last login: %s", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user