Update API documentation to reflect customer authorization changes
- Changed tags from "Customers-Mobile" to "Customers-Authorization" in Swagger documentation for customer logout and profile retrieval endpoints. - Updated the Company entity to replace CustomerID with OwnerCustomerID to better represent ownership. - Removed obsolete customer assignment methods and related forms from the company domain, streamlining the codebase. - Adjusted customer forms to include CompanyID instead of CompanyName for better consistency in customer management. - Enhanced Swagger documentation to accurately reflect the new structure and authorization details for customer-related endpoints.
This commit is contained in:
@@ -24,11 +24,11 @@ const (
|
||||
)
|
||||
|
||||
// Customer represents a customer in the tender management system
|
||||
// A customer can have an associated company for login purposes
|
||||
type Customer struct {
|
||||
mongo.Model
|
||||
Type CustomerType `bson:"type" json:"type"`
|
||||
Status CustomerStatus `bson:"status" json:"status"`
|
||||
CompanyID *string `bson:"company_id,omitempty" json:"company_id,omitempty"`
|
||||
Type CustomerType `bson:"type" json:"type"`
|
||||
Status CustomerStatus `bson:"status" json:"status"`
|
||||
|
||||
// Individual customer fields
|
||||
FirstName *string `bson:"first_name,omitempty" json:"first_name,omitempty"`
|
||||
@@ -40,8 +40,8 @@ type Customer struct {
|
||||
Phone *string `bson:"phone,omitempty" json:"phone,omitempty"`
|
||||
Mobile *string `bson:"mobile,omitempty" json:"mobile,omitempty"`
|
||||
|
||||
// Company customer fields
|
||||
CompanyName *string `bson:"company_name,omitempty" json:"company_name,omitempty"`
|
||||
// Company customer fields (for when customer represents a company)
|
||||
CompanyID *string `bson:"company_id,omitempty" json:"company_id,omitempty"`
|
||||
RegistrationNumber *string `bson:"registration_number,omitempty" json:"registration_number,omitempty"`
|
||||
TaxID *string `bson:"tax_id,omitempty" json:"tax_id,omitempty"`
|
||||
Industry *string `bson:"industry,omitempty" json:"industry,omitempty"`
|
||||
@@ -63,7 +63,7 @@ type Customer struct {
|
||||
IsCompliant bool `bson:"is_compliant" json:"is_compliant"`
|
||||
ComplianceNotes *string `bson:"compliance_notes,omitempty" json:"compliance_notes,omitempty"`
|
||||
|
||||
// Preferences and settings
|
||||
// Settings
|
||||
Language string `bson:"language" json:"language"` // Default: "en"
|
||||
Currency string `bson:"currency" json:"currency"` // Default: "USD"
|
||||
Timezone string `bson:"timezone" json:"timezone"` // Default: "UTC"
|
||||
@@ -131,14 +131,13 @@ type CustomerResponse struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
CompanyID *string `json:"company_id,omitempty"`
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
FullName *string `json:"full_name,omitempty"`
|
||||
Email string `json:"email"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
Mobile *string `json:"mobile,omitempty"`
|
||||
CompanyName *string `json:"company_name,omitempty"`
|
||||
CompanyID *string `json:"company_id,omitempty"`
|
||||
RegistrationNumber *string `json:"registration_number,omitempty"`
|
||||
TaxID *string `json:"tax_id,omitempty"`
|
||||
Industry *string `json:"industry,omitempty"`
|
||||
@@ -167,7 +166,6 @@ func (c *Customer) ToResponse() *CustomerResponse {
|
||||
ID: c.ID,
|
||||
Type: string(c.Type),
|
||||
Status: string(c.Status),
|
||||
CompanyID: c.CompanyID,
|
||||
FirstName: c.FirstName,
|
||||
LastName: c.LastName,
|
||||
FullName: c.FullName,
|
||||
@@ -175,7 +173,7 @@ func (c *Customer) ToResponse() *CustomerResponse {
|
||||
Email: c.Email,
|
||||
Phone: c.Phone,
|
||||
Mobile: c.Mobile,
|
||||
CompanyName: c.CompanyName,
|
||||
CompanyID: c.CompanyID,
|
||||
RegistrationNumber: c.RegistrationNumber,
|
||||
TaxID: c.TaxID,
|
||||
Industry: c.Industry,
|
||||
|
||||
+18
-18
@@ -145,27 +145,27 @@ type CustomerListResponse struct {
|
||||
|
||||
// Mobile-specific forms (simplified for mobile app)
|
||||
type CreateCustomerMobileForm struct {
|
||||
Type string `json:"type" valid:"required,in(individual|company)"`
|
||||
FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
|
||||
LastName *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
||||
Username string `json:"username" valid:"required,alphanum,length(3|30)"`
|
||||
Email string `json:"email" valid:"required,email"`
|
||||
Password string `json:"password" valid:"required,length(8|128)"`
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
||||
Mobile *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
|
||||
CompanyName *string `json:"company_name,omitempty" valid:"optional,length(2|200)"`
|
||||
Industry *string `json:"industry,omitempty" valid:"optional,length(2|100)"`
|
||||
Type string `json:"type" valid:"required,in(individual|company)"`
|
||||
FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
|
||||
LastName *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
||||
Username string `json:"username" valid:"required,alphanum,length(3|30)"`
|
||||
Email string `json:"email" valid:"required,email"`
|
||||
Password string `json:"password" valid:"required,length(8|128)"`
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
||||
Mobile *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
|
||||
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid"`
|
||||
Industry *string `json:"industry,omitempty" valid:"optional,length(2|100)"`
|
||||
}
|
||||
|
||||
type UpdateCustomerMobileForm struct {
|
||||
FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
|
||||
LastName *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
||||
Mobile *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
|
||||
CompanyName *string `json:"company_name,omitempty" valid:"optional,length(2|200)"`
|
||||
Industry *string `json:"industry,omitempty" valid:"optional,length(2|100)"`
|
||||
FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
|
||||
LastName *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
||||
Mobile *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
|
||||
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid"`
|
||||
Industry *string `json:"industry,omitempty" valid:"optional,length(2|100)"`
|
||||
}
|
||||
|
||||
// Customer Authentication DTOs
|
||||
|
||||
@@ -672,7 +672,7 @@ func (h *Handler) RefreshToken(c echo.Context) error {
|
||||
// GetProfile retrieves customer profile information (Mobile)
|
||||
// @Summary Get customer profile
|
||||
// @Description Retrieve current customer profile information
|
||||
// @Tags Customers-Mobile
|
||||
// @Tags Customers-Authorization
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
@@ -702,7 +702,7 @@ func (h *Handler) GetProfile(c echo.Context) error {
|
||||
// Logout handles customer logout (Mobile)
|
||||
// @Summary Customer logout
|
||||
// @Description Logout customer and invalidate access token
|
||||
// @Tags Customers-Mobile
|
||||
// @Tags Customers-Authorization
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
|
||||
@@ -123,7 +123,6 @@ func (s *customerService) CreateCustomer(ctx context.Context, form *CreateCustom
|
||||
Password: string(hashedPassword),
|
||||
Phone: form.Phone,
|
||||
Mobile: form.Mobile,
|
||||
CompanyName: form.CompanyName,
|
||||
RegistrationNumber: form.RegistrationNumber,
|
||||
TaxID: form.TaxID,
|
||||
Industry: form.Industry,
|
||||
@@ -211,15 +210,6 @@ func (s *customerService) UpdateCustomer(ctx context.Context, id string, form *U
|
||||
customer.Username = *form.Username
|
||||
}
|
||||
|
||||
// Check if company name already exists (if changing company name)
|
||||
if form.CompanyName != nil && *form.CompanyName != *customer.CompanyName {
|
||||
existingCustomer, _ := s.repository.GetByCompanyName(ctx, *form.CompanyName)
|
||||
if existingCustomer != nil {
|
||||
return nil, errors.New("company with this name already exists")
|
||||
}
|
||||
customer.CompanyName = form.CompanyName
|
||||
}
|
||||
|
||||
// Check if registration number already exists (if changing)
|
||||
if form.RegistrationNumber != nil && *form.RegistrationNumber != *customer.RegistrationNumber {
|
||||
existingCustomer, _ := s.repository.GetByRegistrationNumber(ctx, *form.RegistrationNumber)
|
||||
@@ -576,7 +566,7 @@ func (s *customerService) CreateCustomerMobile(ctx context.Context, form *Create
|
||||
Password: "", // Will be set after hashing
|
||||
Phone: form.Phone,
|
||||
Mobile: form.Mobile,
|
||||
CompanyName: form.CompanyName,
|
||||
CompanyID: form.CompanyID,
|
||||
Industry: form.Industry,
|
||||
IsVerified: false,
|
||||
IsCompliant: false,
|
||||
@@ -647,8 +637,8 @@ func (s *customerService) UpdateCustomerMobile(ctx context.Context, id string, f
|
||||
customer.Mobile = form.Mobile
|
||||
}
|
||||
|
||||
if form.CompanyName != nil {
|
||||
customer.CompanyName = form.CompanyName
|
||||
if form.CompanyID != nil {
|
||||
customer.CompanyID = form.CompanyID
|
||||
}
|
||||
|
||||
if form.Industry != nil {
|
||||
|
||||
Reference in New Issue
Block a user