From e4ff1f3c528e5f657a6d533afcba9d95d967d00d Mon Sep 17 00:00:00 2001 From: baimamboukar Date: Tue, 26 Dec 2023 14:18:51 +0100 Subject: [PATCH] refactor: refactor routes and controllers --- src/routes/companies.go | 43 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/routes/companies.go b/src/routes/companies.go index 14ce191..f13ac96 100644 --- a/src/routes/companies.go +++ b/src/routes/companies.go @@ -3,44 +3,17 @@ package routes import ( "github.com/gin-gonic/gin" - service "github.com/baimamboukar/go-gin-docker-k8s/src/services" + "github.com/baimamboukar/go-gin-docker-k8s/src/controllers" ) +// controller := &CompaniesController{} func companiesGroupRouter(baseRouter *gin.RouterGroup) { companies := baseRouter.Group("/companies") - companies.GET("/all", GetAllCompanies) - companies.GET("/:id", GetCompanyByID) - companies.POST("/create", CreateCompany) - companies.PATCH("/update", UpdateCompany) - companies.PUT("/update", UpdateCompany) - companies.DELETE("/:id", DeleteCompany) -} - -func GetAllCompanies(c *gin.Context) { - companies := service.GetAllCompanies() - - c.JSON(200, gin.H{"status": "success", "message": "Get companies success", "data": companies}) -} - -func GetCompanyByID(c *gin.Context) { - // Implement logic to get a company by ID - companyID := c.Param("id") - c.JSON(200, gin.H{"message": "Get company by ID", "id": companyID}) -} - -func CreateCompany(c *gin.Context) { - // Implement logic to create a new company - c.JSON(200, gin.H{"message": "Create a new company"}) -} - -func UpdateCompany(c *gin.Context) { - // Implement logic to update a company - c.JSON(200, gin.H{"message": "Update a company"}) -} - -func DeleteCompany(c *gin.Context) { - // Implement logic to delete a company by ID - companyID := c.Param("id") - c.JSON(200, gin.H{"message": "Delete company by ID", "id": companyID}) + companies.GET("/all", controllers.GetAllCompanies) + companies.GET("/:id", controllers.GetCompanyByID) + companies.POST("/create", controllers.CreateCompany) + companies.PATCH("/update", controllers.UpdateCompany) + companies.PUT("/update", controllers.UpdateCompany) + companies.DELETE("/:id", controllers.DeleteCompany) }