Files
tm_back/cmd/web/router/routes.go
T
n.nakhostin 96c21b8b78 Implement TED Scraper and Configuration Management
- Introduced a new TED scraper in `cmd/scraper` to handle downloading and parsing TED XML files.
- Added configuration management for the scraper, including a new `Config` struct and YAML configuration file.
- Created necessary handler, service, and repository layers for tender management, adhering to Clean Architecture principles.
- Implemented comprehensive logging and error handling throughout the scraper functionality.
- Updated API routes to include tender management operations, enhancing the overall system capabilities.
2025-08-13 16:52:24 +03:30

138 lines
5.5 KiB
Go

package router
import (
"tm/internal/company"
"tm/internal/customer"
"tm/internal/tender"
"tm/internal/user"
"github.com/labstack/echo/v4"
)
func RegisterAdminRoutes(e *echo.Echo, userHandler *user.Handler, companyHandler *company.Handler, customerHandler *customer.Handler, tenderHandler *tender.TenderHandler) {
adminV1 := e.Group("/admin/v1")
// Admin Users Routes
adminUsersGP := adminV1.Group("/users")
{
adminUsersGP.Use(userHandler.AuthMiddleware())
adminUsersGP.POST("", userHandler.CreateUser)
adminUsersGP.GET("", userHandler.ListUsers)
adminUsersGP.GET("/:id", userHandler.GetUserByID)
adminUsersGP.PUT("/:id", userHandler.UpdateUser)
adminUsersGP.DELETE("/:id", userHandler.DeleteUser)
adminUsersGP.PUT("/:id/status", userHandler.UpdateUserStatus)
adminUsersGP.PUT("/:id/role", userHandler.UpdateUserRole)
adminUsersGP.GET("/company/:company_id", userHandler.GetUsersByCompanyID)
adminUsersGP.GET("/role/:role", userHandler.GetUsersByRole)
}
// Admin user profile
profileGP := adminV1.Group("/profile")
{
userAuthorizationGP := profileGP.Group("")
userAuthorizationGP.POST("/login", userHandler.Login)
userAuthorizationGP.POST("/refresh-token", userHandler.RefreshToken)
userAuthorizationGP.POST("/reset-password", userHandler.ResetPassword)
userProfileGP := profileGP.Group("")
userProfileGP.Use(userHandler.AuthMiddleware())
userProfileGP.GET("", userHandler.GetProfile)
userProfileGP.PUT("", userHandler.UpdateProfile)
userProfileGP.PUT("/change-password", userHandler.ChangePassword)
userProfileGP.DELETE("/logout", userHandler.Logout)
}
// Admin Companies Routes
companiesGP := adminV1.Group("/companies")
{
companiesGP.Use(userHandler.AuthMiddleware())
companiesGP.POST("", companyHandler.CreateCompany)
companiesGP.GET("", companyHandler.ListCompanies)
companiesGP.GET("/:id", companyHandler.GetCompany)
companiesGP.PUT("/:id", companyHandler.UpdateCompany)
companiesGP.DELETE("/:id", companyHandler.DeleteCompany)
companiesGP.GET("/search", companyHandler.SearchCompanies)
companiesGP.PATCH("/:id/status", companyHandler.UpdateCompanyStatus)
companiesGP.PATCH("/:id/verification", companyHandler.UpdateCompanyVerification)
companiesGP.PUT("/:id/tags", companyHandler.UpdateCompanyTags)
companiesGP.POST("/:id/tags/add", companyHandler.AddTags)
companiesGP.POST("/:id/tags/remove", companyHandler.RemoveTags)
companiesGP.POST("/:id/verify", companyHandler.VerifyCompany)
companiesGP.POST("/:id/suspend", companyHandler.SuspendCompany)
companiesGP.POST("/:id/activate", companyHandler.ActivateCompany)
companiesGP.GET("/stats", companyHandler.GetCompanyStats)
companiesGP.GET("/type/:type", companyHandler.GetCompaniesByType)
companiesGP.GET("/status/:status", companyHandler.GetCompaniesByStatus)
companiesGP.GET("/industry/:industry", companyHandler.GetCompaniesByIndustry)
}
// Admin Customers Routes
customersGP := adminV1.Group("/customers")
{
customersGP.Use(userHandler.AuthMiddleware())
customersGP.POST("", customerHandler.CreateCustomer)
customersGP.GET("", customerHandler.ListCustomers)
customersGP.GET("/:id", customerHandler.GetCustomerByID)
customersGP.PUT("/:id", customerHandler.UpdateCustomer)
customersGP.DELETE("/:id", customerHandler.DeleteCustomer)
customersGP.PATCH("/:id/status", customerHandler.UpdateCustomerStatus)
customersGP.PATCH("/:id/verification", customerHandler.UpdateCustomerVerification)
customersGP.POST("/:id/verify", customerHandler.VerifyCustomer)
customersGP.POST("/:id/suspend", customerHandler.SuspendCustomer)
customersGP.POST("/:id/activate", customerHandler.ActivateCustomer)
customersGP.GET("/company/:companyId", customerHandler.GetCustomersByCompanyID)
customersGP.GET("/type/:type", customerHandler.GetCustomersByType)
customersGP.GET("/status/:status", customerHandler.GetCustomersByStatus)
customersGP.POST("/:id/companies/assign", customerHandler.AssignCompaniesToCustomer)
customersGP.POST("/:id/companies/remove", customerHandler.RemoveCompaniesFromCustomer)
}
// Admin Tenders Routes
tendersGP := adminV1.Group("/tenders")
{
tendersGP.Use(userHandler.AuthMiddleware())
tendersGP.POST("", tenderHandler.CreateTender)
tendersGP.GET("", tenderHandler.ListTenders)
tendersGP.GET("/:id", tenderHandler.GetTender)
tendersGP.PUT("/:id", tenderHandler.UpdateTender)
tendersGP.DELETE("/:id", tenderHandler.DeleteTender)
tendersGP.POST("/search", tenderHandler.SearchTenders)
tendersGP.GET("/statistics", tenderHandler.GetTenderStatistics)
tendersGP.GET("/dashboard", tenderHandler.GetDashboard)
}
// Admin Scraping Routes
scrapingGP := adminV1.Group("/scraping")
{
scrapingGP.Use(userHandler.AuthMiddleware())
scrapingGP.POST("/jobs", tenderHandler.StartScrapingJob)
scrapingGP.GET("/jobs", tenderHandler.ListScrapingJobs)
scrapingGP.GET("/jobs/:id", tenderHandler.GetScrapingJob)
scrapingGP.POST("/jobs/:id/cancel", tenderHandler.CancelScrapingJob)
}
}
func RegisterPublicRoutes(e *echo.Echo, customerHandler *customer.Handler, tenderHandler *tender.TenderHandler) {
v1 := e.Group("/api/v1")
customerGP := v1.Group("/profile")
{
customerGP.POST("/login", customerHandler.Login)
customerGP.POST("/refresh-token", customerHandler.RefreshToken)
profileGP := customerGP.Group("")
profileGP.Use(customerHandler.AuthMiddleware())
profileGP.GET("", customerHandler.GetProfile)
profileGP.DELETE("/logout", customerHandler.Logout)
}
// Public Tenders Routes
tendersGP := v1.Group("/tenders")
{
tendersGP.GET("", tenderHandler.GetPublicTenders)
tendersGP.GET("/:id", tenderHandler.GetPublicTenderDetails)
}
}