Refactor customer domain by removing obsolete files and updating main application structure

- Deleted customer domain files including entities, services, handlers, and forms to streamline the codebase.
- Removed customer-related routes and service initializations from the main application.
- Updated Swagger documentation to reflect the removal of customer endpoints and definitions.
- Cleaned up the project structure to enhance maintainability and focus on user management functionality.
This commit is contained in:
n.nakhostin
2025-08-10 19:05:46 +03:30
parent c89041812a
commit dbcc2d1d4a
13 changed files with 60 additions and 5283 deletions
+53 -43
View File
@@ -31,40 +31,34 @@ func NewUserHandler(service Service, logger logger.Logger, validator ValidationS
// RegisterRoutes registers user routes
func (h *Handler) RegisterRoutes(e *echo.Echo) {
v1 := e.Group("/api/v1")
v1 := e.Group("/admin/v1")
userGroup := v1.Group("/users")
{
// Public routes
userGroup.POST("/login", h.Login)
userGroup.POST("/refresh-token", h.RefreshToken)
userGroup.POST("/reset-password", h.ResetPassword)
// Public routes (no authentication required)
authorizationGP := v1.Group("")
authorizationGP.POST("/login", h.Login)
authorizationGP.POST("/refresh-token", h.RefreshToken)
authorizationGP.POST("/reset-password", h.ResetPassword)
// Protected routes (require authentication)
authGroup := userGroup.Group("")
// authGroup.Use(h.AuthMiddleware())
{
authGroup.GET("/profile", h.GetProfile)
authGroup.PUT("/profile", h.UpdateProfile)
authGroup.PUT("/change-password", h.ChangePassword)
authGroup.POST("/logout", h.Logout)
// Protected routes (require authentication)
profileGP := v1.Group("")
profileGP.Use(h.AuthMiddleware())
profileGP.GET("/profile", h.GetProfile)
profileGP.PUT("/profile", h.UpdateProfile)
profileGP.PUT("/change-password", h.ChangePassword)
profileGP.DELETE("/logout", h.Logout)
// Admin routes
adminGroup := authGroup.Group("/admin")
// adminGroup.Use(h.AdminMiddleware())
{
adminGroup.POST("", h.CreateUser)
adminGroup.GET("", h.ListUsers)
adminGroup.GET("/:id", h.GetUserByID)
adminGroup.PUT("/:id", h.UpdateUser)
adminGroup.DELETE("/:id", h.DeleteUser)
adminGroup.PUT("/:id/status", h.UpdateUserStatus)
adminGroup.PUT("/:id/role", h.UpdateUserRole)
adminGroup.GET("/company/:company_id", h.GetUsersByCompanyID)
adminGroup.GET("/role/:role", h.GetUsersByRole)
}
}
}
// Admin routes (require admin role)
adminGroup := v1.Group("/users")
adminGroup.Use(h.AuthMiddleware(), h.AdminMiddleware())
adminGroup.POST("", h.CreateUser)
adminGroup.GET("", h.ListUsers)
adminGroup.GET("/:id", h.GetUserByID)
adminGroup.PUT("/:id", h.UpdateUser)
adminGroup.DELETE("/:id", h.DeleteUser)
adminGroup.PUT("/:id/status", h.UpdateUserStatus)
adminGroup.PUT("/:id/role", h.UpdateUserRole)
adminGroup.GET("/company/:company_id", h.GetUsersByCompanyID)
adminGroup.GET("/role/:role", h.GetUsersByRole)
}
// Login handles user login
@@ -188,8 +182,11 @@ func (h *Handler) GetProfile(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/profile [put]
func (h *Handler) UpdateProfile(c echo.Context) error {
// TODO: Extract user ID from JWT token
userID := uuid.New() // Placeholder - should be extracted from JWT
// Extract user ID from JWT token context
userID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
form, err := response.Parse[UpdateUserForm](c)
if err != nil {
@@ -218,8 +215,10 @@ func (h *Handler) UpdateProfile(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/change-password [put]
func (h *Handler) ChangePassword(c echo.Context) error {
// TODO: Extract user ID from JWT token
userID := uuid.New() // Placeholder - should be extracted from JWT
userID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
form, err := response.Parse[ChangePasswordForm](c)
if err != nil {
@@ -397,8 +396,11 @@ func (h *Handler) GetUserByID(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/admin/{id} [put]
func (h *Handler) UpdateUser(c echo.Context) error {
// TODO: Get current user ID from JWT token
currentUserID := uuid.New() // Placeholder
// Extract user ID from JWT token context
currentUserID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
idStr := c.Param("id")
userID, err := uuid.Parse(idStr)
@@ -441,8 +443,11 @@ func (h *Handler) UpdateUser(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/admin/{id} [delete]
func (h *Handler) DeleteUser(c echo.Context) error {
// TODO: Get current user ID from JWT token
currentUserID := uuid.New() // Placeholder
// Extract user ID from JWT token context
currentUserID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
idStr := c.Param("id")
userID, err := uuid.Parse(idStr)
@@ -477,8 +482,10 @@ func (h *Handler) DeleteUser(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/admin/{id}/status [put]
func (h *Handler) UpdateUserStatus(c echo.Context) error {
// TODO: Get current user ID from JWT token
currentUserID := uuid.New() // Placeholder
currentUserID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
idStr := c.Param("id")
userID, err := uuid.Parse(idStr)
@@ -524,8 +531,11 @@ func (h *Handler) UpdateUserStatus(c echo.Context) error {
// @Failure 500 {object} response.APIResponse
// @Router /users/admin/{id}/role [put]
func (h *Handler) UpdateUserRole(c echo.Context) error {
// TODO: Get current user ID from JWT token
currentUserID := uuid.New() // Placeholder
// Extract user ID from JWT token context
currentUserID, err := GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
idStr := c.Param("id")
userID, err := uuid.Parse(idStr)