diff --git a/internal/company/form.go b/internal/company/form.go index 41d730a..579e8f0 100644 --- a/internal/company/form.go +++ b/internal/company/form.go @@ -7,9 +7,9 @@ type ( CompanyForm struct { Name string `json:"name" valid:"required,length(2|200)" example:"Opplens"` Type string `json:"type" valid:"required,in(private|public|government|ngo|startup)" example:"private"` - RegistrationNumber string `json:"registration_number" valid:"required,length(5|50)" example:"1234567890"` - TaxID string `json:"tax_id" valid:"required,length(5|50)" example:"1234567890"` - Industry string `json:"industry" valid:"required,length(2|100)" example:"Technology"` + RegistrationNumber string `json:"registration_number" valid:"optional,length(5|50)" example:"1234567890"` + TaxID string `json:"tax_id" valid:"optional,length(5|50)" example:"1234567890"` + Industry string `json:"industry" valid:"optional,length(2|100)" example:"Technology"` Description *string `json:"description,omitempty" valid:"optional,length(10|1000)" example:"Opplens is a technology company"` Website *string `json:"website,omitempty" valid:"optional,url" example:"https://opplens.com"` diff --git a/internal/company/service.go b/internal/company/service.go index db99f42..6ed8685 100644 --- a/internal/company/service.go +++ b/internal/company/service.go @@ -103,16 +103,18 @@ func (s *companyService) Create(ctx context.Context, form *CompanyForm) (*Compan return nil, errors.New("company with this name already exists") } - // Check if registration number already exists - existingCompany, _ = s.repository.GetByRegistrationNumber(ctx, form.RegistrationNumber) - if existingCompany != nil { - return nil, errors.New("company with this registration number already exists") + if form.RegistrationNumber != "" { + existingCompany, _ = s.repository.GetByRegistrationNumber(ctx, form.RegistrationNumber) + if existingCompany != nil { + return nil, errors.New("company with this registration number already exists") + } } - // Check if tax ID already exists - existingCompany, _ = s.repository.GetByTaxID(ctx, form.TaxID) - if existingCompany != nil { - return nil, errors.New("company with this tax ID already exists") + if form.TaxID != "" { + existingCompany, _ = s.repository.GetByTaxID(ctx, form.TaxID) + if existingCompany != nil { + return nil, errors.New("company with this tax ID already exists") + } } // Create company