basic account creation flow created

This commit is contained in:
2026-01-24 16:45:38 -07:00
parent 7d37fae332
commit 1c305cd494
14 changed files with 649 additions and 37 deletions
+11 -8
View File
@@ -2,10 +2,10 @@ package accounts
import (
"errors"
"fmt"
"strconv"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"ruben/inventory2/internal/consts"
"ruben/inventory2/internal/domains/accounts"
@@ -31,6 +31,8 @@ func Routes(
accts: accts,
}
r.POST("", response.Handler(as.createAccount))
syncGroups := r.Group("/:acctID/inventory/sync-groups")
syncGroups.POST("", response.Handler(as.saveNewSyncGroup))
@@ -41,19 +43,17 @@ func Routes(
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
}
// TODO: test this endpoint again, to make it work.
// POST /
func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, error) {
r := c.Request
ctx := r.Context()
email := r.FormValue("email")
if email == "" {
return nil, response.BadRequest().Msg("no email provided")
}
// TODO: get email from the user's account profile (how?) - will need to flesh out the account creation process later on
email := uuid.NewString() + "@example.com"
userID := auth.GetIdentity(ctx).User.UserID
acct, err := s.accts.CreateAccount(ctx, userID, email)
_, err := s.accts.CreateAccount(ctx, userID, email)
if err != nil {
if errors.Is(err, consts.ErrConflict) {
return nil, response.Conflict().
@@ -62,7 +62,10 @@ func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, err
return nil, response.Errorf("failed to create account: %w", err)
}
return response.SeeOther(fmt.Sprintf("/ui/accounts/%d", acct.AccountID)), nil
return response.StatusCreated().
// force a reload to ensure an sse connection is made.
// user should automatically be redirected to the appropriate page based on their current location and/or login/account statuses.
HXRefresh("true"), nil
}
// POST /:acctID/inventory/sync-groups/draft/listings