Refactor customer domain structure and implement core entities, services, and handlers
- Introduced a flat structure for the customer domain, consolidating entities, aggregates, repositories, services, forms, and handlers into a single package. - Added core entities: Customer and CustomerAggregate. - Implemented request/response forms for customer authentication (Register, Login, Refresh Token, Change Password). - Created CustomerService to handle business logic and data access through the Repository interface. - Established CustomerHandler for HTTP request handling related to customer authentication. - Removed previous domain structure artifacts to streamline the codebase.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package customer
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type CustomerAggregate struct {
|
||||
ID uuid.UUID `json:"_id"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Mobile string `json:"mobile"`
|
||||
Email string `json:"email"`
|
||||
IsActive bool `json:"is_active"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
LastLoginAt *int64 `json:"last_login_at,omitempty"` // Unix timestamp
|
||||
CreatedAt int64 `json:"created_at"` // Unix timestamp
|
||||
UpdatedAt int64 `json:"updated_at"` // Unix timestamp
|
||||
}
|
||||
|
||||
func NewCustomerAggregate(c Customer) CustomerAggregate {
|
||||
customer := CustomerAggregate{
|
||||
ID: c.ID,
|
||||
FirstName: c.FirstName,
|
||||
LastName: c.LastName,
|
||||
Mobile: c.Mobile,
|
||||
Email: c.Email,
|
||||
IsActive: c.IsActive,
|
||||
IsVerified: c.IsVerified,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
}
|
||||
|
||||
if c.LastLoginAt != nil {
|
||||
customer.LastLoginAt = c.LastLoginAt
|
||||
}
|
||||
|
||||
return customer
|
||||
}
|
||||
|
||||
// AuthResponse defines authentication response (kept for backward compatibility)
|
||||
type AuthorizationResponse struct {
|
||||
Customer CustomerAggregate `json:"customer"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
Reference in New Issue
Block a user