hiling_go/api/region.go
2026-05-31 12:08:43 +03:00

53 lines
1.4 KiB
Go
Executable File

package api
import (
"net/http"
"github.com/gin-gonic/gin"
)
// @Summary List all regions
// @Tags regions
// @Produce json
// @Success 200 {array} map[string]any
// @Router /regions [get]
func (server *Server) getListRegions(ctx *gin.Context) {
regions, err := server.Store.GetListRegions(ctx)
if err != nil {
ctx.JSON(http.StatusInternalServerError, ErrorResponse(err, "Something went wrong while try to get regions"))
return
}
ctx.JSON(http.StatusOK, regions)
}
// @Summary List provinces
// @Tags regions
// @Produce json
// @Success 200 {array} map[string]any
// @Router /region/provinces [get]
func (server *Server) getListProvinces(ctx *gin.Context) {
provinces, err := server.Store.GetListProvinces(ctx)
if err != nil {
ctx.JSON(http.StatusInternalServerError, ErrorResponse(err, "Something went wrong while try to get regions"))
return
}
ctx.JSON(http.StatusOK, provinces)
}
// @Summary List regencies
// @Tags regions
// @Produce json
// @Success 200 {array} map[string]any
// @Router /region/regencies [get]
func (server *Server) getListRegencies(ctx *gin.Context) {
regencies, err := server.Store.GetListRegencies(ctx)
if err != nil {
ctx.JSON(http.StatusInternalServerError, ErrorResponse(err, "Something went wrong while try to get regions"))
return
}
ctx.JSON(http.StatusOK, regencies)
}