holiday-api/api/routes.go

40 lines
1.6 KiB
Go
Raw Normal View History

package api
import (
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
"holiday-api/domain/holiday"
)
func RegisterRoutes(server *gin.Engine, db *sqlx.DB) {
holidayService := holiday.HolidayService{DB: db}
countryService := holiday.CountryService{DB: db}
yearService := holiday.YearService{DB: db}
server.GET("/", GetIndex(holidayService, countryService, yearService))
server.GET("/documentation", GetDocumentation(countryService, yearService))
server.GET("/api/v1/holidays", GetHolidays(holidayService))
auth := Auth()
adminGroup := server.Group("/admin", auth)
adminGroup.GET("/", GetAdminHome(holidayService, countryService, yearService))
adminGroup.POST("/holidays", CreateOrUpdateHoliday(holidayService))
adminGroup.POST("/holidays/copy", CopyYear(holidayService))
adminGroup.POST("/holidays/:id/delete", DeleteHoliday(holidayService))
adminGroup.GET("countries", GetCountries(countryService))
adminGroup.POST("countries", CreateOrUpdateCountry(countryService))
adminGroup.POST("countries/:id/delete", DeleteCountry(countryService))
dialogGroup := server.Group("/admin/dialogs", auth)
dialogGroup.GET("/add-country", AddCountryDialog())
dialogGroup.GET("/edit-country", EditCountryDialog(countryService))
dialogGroup.GET("/delete-country", DeleteCountryDialog(countryService))
dialogGroup.GET("/add-holiday", AddHolidayDialog(countryService))
dialogGroup.GET("/edit-holiday", EditHolidayDialog(holidayService, countryService))
dialogGroup.GET("/delete-holiday", DeleteHolidayDialog(holidayService))
dialogGroup.GET("/copy-year", CopyYearDialog())
}