refactor: remove google/uuid from register_candidate.go
- IDs are now auto-generated by DB SERIAL columns - No need to generate UUID in application code - Let repository handle ID assignment from DB response - Removed unused import
This commit is contained in:
parent
568b4ebb88
commit
7310627bee
1 changed files with 6 additions and 7 deletions
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/rede5/gohorsejobs/backend/internal/core/domain/entity"
|
"github.com/rede5/gohorsejobs/backend/internal/core/domain/entity"
|
||||||
"github.com/rede5/gohorsejobs/backend/internal/core/dto"
|
"github.com/rede5/gohorsejobs/backend/internal/core/dto"
|
||||||
"github.com/rede5/gohorsejobs/backend/internal/core/ports"
|
"github.com/rede5/gohorsejobs/backend/internal/core/ports"
|
||||||
|
|
@ -39,21 +38,21 @@ func (uc *RegisterCandidateUseCase) Execute(ctx context.Context, input dto.Regis
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Create Candidate's Personal Tenant/Workspace
|
// 3. Create Candidate's Personal Tenant/Workspace
|
||||||
candidateTenantID := uuid.New().String()
|
// NOTE: ID is empty - will be auto-generated by DB (SERIAL)
|
||||||
candidateCompany := entity.NewCompany(
|
candidateCompany := entity.NewCompany(
|
||||||
candidateTenantID,
|
"", // DB generates SERIAL id
|
||||||
fmt.Sprintf("Candidate - %s", input.Name),
|
fmt.Sprintf("Candidate - %s", input.Name),
|
||||||
nil, // No document for candidates
|
nil, // No document for candidates
|
||||||
nil, // No contact - will use user's contact info
|
nil, // No contact - will use user's contact info
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err = uc.companyRepo.Save(ctx, candidateCompany)
|
savedCompany, err := uc.companyRepo.Save(ctx, candidateCompany)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create candidate workspace: %w", err)
|
return nil, fmt.Errorf("failed to create candidate workspace: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Create User Entity
|
// 4. Create User Entity - ID is auto-generated by DB
|
||||||
user := entity.NewUser(uuid.New().String(), candidateTenantID, input.Name, input.Email)
|
user := entity.NewUser("", savedCompany.ID, input.Name, input.Email)
|
||||||
user.PasswordHash = hashed
|
user.PasswordHash = hashed
|
||||||
|
|
||||||
// Set Metadata
|
// Set Metadata
|
||||||
|
|
@ -75,7 +74,7 @@ func (uc *RegisterCandidateUseCase) Execute(ctx context.Context, input dto.Regis
|
||||||
roles[i] = r.Name
|
roles[i] = r.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Generate Token (Auto-login)
|
// 5. Generate Token (Auto-login)
|
||||||
token, err := uc.authService.GenerateToken(saved.ID, saved.TenantID, roles)
|
token, err := uc.authService.GenerateToken(saved.ID, saved.TenantID, roles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue