Skip to content

Commit

Permalink
refactor: refactor routes and controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
baimamboukar committed Dec 26, 2023
1 parent 9919bd2 commit e4ff1f3
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions src/routes/companies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit e4ff1f3

Please sign in to comment.