Files
tm_back/internal/customer/form.go
T
n.nakhostin c06ea278c0 Update CustomerResponse JSON Tags and Fix Comment in Tender Repository
- Changed BSON tags to JSON tags in the CustomerResponse struct to ensure proper serialization in API responses.
- Updated the comment in the buildSearchFilter method to correct a typo, enhancing clarity in the codebase.
2025-09-08 14:32:57 +03:30

123 lines
4.8 KiB
Go

package customer
import "tm/pkg/response"
// CreateCustomerForm represents the form for creating a new customer
type CreateCustomerForm struct {
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"User"`
Type string `json:"type" valid:"required,in(individual|company|government)" example:"individual"`
CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"user"`
Email string `json:"email" valid:"required,email" example:"user@opplens.com"`
Password string `json:"password" valid:"required,length(8|128)" example:"User!1234"`
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"`
}
// UpdateCustomerForm represents the form for updating a customer
type UpdateCustomerForm struct {
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"User"`
Type string `json:"type" valid:"required,in(individual|company|government)" example:"individual"`
CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"user"`
Email string `json:"email" valid:"required,email" example:"user@opplens.com"`
Password string `json:"password" valid:"required,length(8|128)" example:"User!1234"`
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"`
}
// CustomerStatusForm represents the form for suspending a customer
type UpdateStatusForm struct {
Status string `json:"status" valid:"required,in(active|inactive|suspended)" example:"active"`
Reason string `json:"reason" valid:"required,length(10|500)" example:"Customer is active"`
}
// ListCustomersForm represents the form for listing customers with filters
type SearchCustomersForm struct {
Search *string `query:"q" valid:"optional"`
Type *string `query:"type" valid:"optional,in(individual|company|government)"`
Status *string `query:"status" valid:"optional,in(active|inactive|suspended)"`
CompanyID *string `query:"company_id" valid:"optional"`
}
// CompanySummary represents company summary data for customer responses
type CompanySummary struct {
ID string `json:"id"`
Name string `json:"name"`
}
// CustomerResponse represents the customer data sent in API responses
type CustomerResponse struct {
ID string `json:"id"`
FullName *string `json:"full_name"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
Status string `json:"status"`
Type string `json:"type"`
Phone *string `json:"phone"`
CompanyIDs []string `json:"company_ids"`
UpdatedAt int64 `json:"updated_at"`
CreatedAt int64 `json:"created_at"`
LastLoginAt *int64 `json:"last_login_at"`
Companies []*CompanySummary `json:"companies"`
}
// ToResponse converts Customer to CustomerResponse
func (c *Customer) ToResponse(companies []*CompanySummary) *CustomerResponse {
return &CustomerResponse{
ID: c.ID.Hex(),
FullName: c.FullName,
Username: c.Username,
Email: c.Email,
Password: c.Password,
Type: string(c.Type),
Status: string(c.Status),
Phone: c.Phone,
CompanyIDs: c.CompanyIDs,
UpdatedAt: c.UpdatedAt,
CreatedAt: c.CreatedAt,
LastLoginAt: c.LastLoginAt,
Companies: companies,
}
}
// CustomerListResponse represents the response for listing customers
type CustomerListResponse struct {
Customers []*CustomerResponse `json:"customers"`
Meta *response.Meta `json:"-"`
}
type LoginForm struct {
Username string `json:"username" valid:"required" example:"app"`
Password string `json:"password" valid:"required" example:"App!1234"`
}
type RefreshTokenForm struct {
RefreshToken string `json:"refresh_token" valid:"required"`
}
type ChangePasswordForm struct {
OldPassword string `json:"old_password" valid:"required"`
NewPassword string `json:"new_password" valid:"required,length(8|128)"`
}
type UpdateProfileForm struct {
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
Username *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)"`
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
}
type AuthResponse struct {
Customer *CustomerResponse `json:"customer"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt int64 `json:"expires_at"`
}
type AssignCompaniesForm struct {
CompanyIDs []string `json:"company_ids" valid:"required"`
}
type RemoveCompaniesForm struct {
CompanyIDs []string `json:"company_ids" valid:"required"`
}