diff --git a/backend/internal/core/domain/entity/company.go b/backend/internal/core/domain/entity/company.go index 8a8413b..bee56d4 100644 --- a/backend/internal/core/domain/entity/company.go +++ b/backend/internal/core/domain/entity/company.go @@ -6,6 +6,7 @@ import "time" type Company struct { ID string `json:"id"` Name string `json:"name"` + Type string `json:"type"` // "COMPANY", "CANDIDATE_WORKSPACE" Document *string `json:"document,omitempty"` // CNPJ, EIN, VAT Contact *string `json:"contact,omitempty"` Status string `json:"status"` // "ACTIVE", "INACTIVE" @@ -18,6 +19,7 @@ func NewCompany(id, name string, document, contact *string) *Company { return &Company{ ID: id, Name: name, + Type: "COMPANY", Document: document, Contact: contact, Status: "ACTIVE", diff --git a/backend/internal/core/usecases/auth/register_candidate.go b/backend/internal/core/usecases/auth/register_candidate.go index f215d7d..bfc2b21 100644 --- a/backend/internal/core/usecases/auth/register_candidate.go +++ b/backend/internal/core/usecases/auth/register_candidate.go @@ -51,6 +51,7 @@ func (uc *RegisterCandidateUseCase) Execute(ctx context.Context, input dto.Regis nil, // No document for candidates nil, // No contact - will use user's contact info ) + candidateCompany.Type = "CANDIDATE_WORKSPACE" savedCompany, err := uc.companyRepo.Save(ctx, candidateCompany) if err != nil { diff --git a/backend/internal/infrastructure/persistence/postgres/company_repository.go b/backend/internal/infrastructure/persistence/postgres/company_repository.go index 8937142..5d393ab 100644 --- a/backend/internal/infrastructure/persistence/postgres/company_repository.go +++ b/backend/internal/infrastructure/persistence/postgres/company_repository.go @@ -25,12 +25,17 @@ func (r *CompanyRepository) Save(ctx context.Context, company *entity.Company) ( RETURNING id ` + var compType = company.Type + if compType == "" { + compType = "company" + } + slug := company.Name // TODO: slugify function var id string err := r.db.QueryRowContext(ctx, query, company.Name, slug, - "company", + compType, company.Document, company.Contact, // mapped to email "{}", // description as JSON @@ -94,7 +99,8 @@ func (r *CompanyRepository) FindAll(ctx context.Context) ([]*entity.Company, err query := `SELECT id, name, document, email, CASE WHEN active THEN 'ACTIVE' ELSE 'INACTIVE' END as status, created_at, updated_at - FROM companies` + FROM companies + WHERE type = 'company' OR type = 'COMPANY'` rows, err := r.db.QueryContext(ctx, query) if err != nil { return nil, err diff --git a/backend/internal/services/admin_service.go b/backend/internal/services/admin_service.go index fb1f56d..c4559fd 100644 --- a/backend/internal/services/admin_service.go +++ b/backend/internal/services/admin_service.go @@ -25,10 +25,10 @@ func (s *AdminService) ListCompanies(ctx context.Context, verified *bool, page, offset := (page - 1) * limit // Count Total - countQuery := `SELECT COUNT(*) FROM companies` + countQuery := `SELECT COUNT(*) FROM companies WHERE (type = 'company' OR type = 'COMPANY' OR type IS NULL)` var countArgs []interface{} if verified != nil { - countQuery += " WHERE verified = $1" + countQuery += " AND verified = $1" countArgs = append(countArgs, *verified) } var total int @@ -40,11 +40,12 @@ func (s *AdminService) ListCompanies(ctx context.Context, verified *bool, page, baseQuery := ` SELECT id, name, slug, type, document, address, region_id, city_id, phone, email, website, logo_url, description, active, verified, created_at, updated_at FROM companies + WHERE (type = 'company' OR type = 'COMPANY' OR type IS NULL) ` var args []interface{} if verified != nil { - baseQuery += " WHERE verified = $1" + baseQuery += " AND verified = $1" args = append(args, *verified) }