Refactor customer domain to use string IDs and integrate MongoDB ORM
- Updated Customer entity to embed MongoDB model and replace uuid.UUID with string for ID fields. - Modified repository methods to accept string IDs instead of uuid.UUID, enhancing compatibility with MongoDB. - Refactored service and handler methods to align with the new ID type, ensuring consistent usage across customer management functionality. - Improved response handling in CustomerResponse to directly use string IDs. - Streamlined index creation in the customer repository using the MongoDB ORM for better maintainability. - Added new forms for customer suspension and updated validation rules. - Enhanced Swagger documentation for customer-related endpoints to reflect changes in ID handling and request structures.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
"tm/pkg/response"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@@ -44,13 +43,7 @@ func (h *Handler) AuthMiddleware() echo.MiddlewareFunc {
|
||||
}
|
||||
|
||||
// Extract customer information from token
|
||||
customerID, err := uuid.Parse(validationResult.Claims.UserID)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to parse customer ID from token", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return response.Unauthorized(c, "Invalid token format")
|
||||
}
|
||||
customerID := validationResult.Claims.UserID
|
||||
|
||||
// Store customer information in context for handlers to use
|
||||
c.Set("customer_id", customerID)
|
||||
@@ -66,10 +59,10 @@ func (h *Handler) AuthMiddleware() echo.MiddlewareFunc {
|
||||
}
|
||||
|
||||
// GetCustomerIDFromContext extracts customer ID from Echo context
|
||||
func GetCustomerIDFromContext(c echo.Context) (uuid.UUID, error) {
|
||||
customerID, ok := c.Get("customer_id").(uuid.UUID)
|
||||
func GetCustomerIDFromContext(c echo.Context) (string, error) {
|
||||
customerID, ok := c.Get("customer_id").(string)
|
||||
if !ok {
|
||||
return uuid.Nil, echo.NewHTTPError(http.StatusUnauthorized, "Customer ID not found in context")
|
||||
return "", echo.NewHTTPError(http.StatusUnauthorized, "Customer ID not found in context")
|
||||
}
|
||||
return customerID, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user