diff --git a/holiday/year_searvice.go b/holiday/year_searvice.go new file mode 100644 index 0000000..88882b8 --- /dev/null +++ b/holiday/year_searvice.go @@ -0,0 +1,14 @@ +package holiday + +import ( + "github.com/jmoiron/sqlx" +) + +type YearService struct { + DB *sqlx.DB +} + +func (s *YearService) Find() ([]int, error) { + var years []int + return years, s.DB.Select(&years, "SELECT distinct extract(year from date) as date FROM holiday order by date asc") +} diff --git a/main.go b/main.go index ccdd344..1f64b86 100644 --- a/main.go +++ b/main.go @@ -55,10 +55,11 @@ func main() { holidayService := holiday.HolidayService{DB: client} countryService := holiday.CountryService{DB: client} + yearService := holiday.YearService{DB: client} g.GET("/api/v1/holidays", getHolidays(holidayService)) - setupAdminDashboard(g.Group("/admin"), holidayService, countryService) + setupAdminDashboard(g.Group("/admin"), holidayService, countryService, yearService) g.GET("/", func(c *gin.Context) { year := time.Now().Year() @@ -69,11 +70,13 @@ func main() { } holidays, _ := holidayService.Find(search, holiday.Paging{PageSize: 100}) countries, _ := countryService.Find() - c.HTML(http.StatusOK, "index.gohtml", gin.H{"Countries": countries, "Search": search, "Holidays": mapHolidays(holidays).Holidays}) + years, _ := yearService.Find() + c.HTML(http.StatusOK, "index.gohtml", gin.H{"Years": years, "Countries": countries, "Search": search, "Holidays": mapHolidays(holidays).Holidays}) }) g.GET("/documentation", func(c *gin.Context) { countries, _ := countryService.Find() - c.HTML(http.StatusOK, "documentation.gohtml", gin.H{"Countries": countries}) + years, _ := yearService.Find() + c.HTML(http.StatusOK, "documentation.gohtml", gin.H{"Years": years, "Countries": countries}) }) g.GET("/search", func(c *gin.Context) { request := holiday.Search{} @@ -129,7 +132,7 @@ func loadTemplates(g *gin.Engine) { ) } -func setupAdminDashboard(adminDashboard *gin.RouterGroup, service holiday.HolidayService, countryService holiday.CountryService) { +func setupAdminDashboard(adminDashboard *gin.RouterGroup, service holiday.HolidayService, countryService holiday.CountryService, yearService holiday.YearService) { adminDashboard.Use(gin.BasicAuth(loadAuth())) adminDashboard.GET("/", func(c *gin.Context) { @@ -142,11 +145,13 @@ func setupAdminDashboard(adminDashboard *gin.RouterGroup, service holiday.Holida holidays, _ := service.Find(search, holiday.Paging{PageSize: 100}) holidayResponse := mapHolidays(holidays) countries, _ := countryService.Find() + years, _ := yearService.Find() response := map[string]any{} response["Holidays"] = holidayResponse response["Search"] = search response["Countries"] = countries + response["Years"] = years c.HTML(http.StatusOK, "admin_dashboard.gohtml", response) }) diff --git a/templates/admin_dashboard.gohtml b/templates/admin_dashboard.gohtml index 40dcac9..06f16cb 100644 --- a/templates/admin_dashboard.gohtml +++ b/templates/admin_dashboard.gohtml @@ -36,14 +36,9 @@
diff --git a/templates/documentation.gohtml b/templates/documentation.gohtml index e907ae2..0846200 100644 --- a/templates/documentation.gohtml +++ b/templates/documentation.gohtml @@ -61,14 +61,9 @@
diff --git a/templates/index.gohtml b/templates/index.gohtml index dc7c300..7055a89 100644 --- a/templates/index.gohtml +++ b/templates/index.gohtml @@ -36,10 +36,9 @@