feat: add fetch by id for API wilayah indonesia
This commit is contained in:
parent
e57ce46ce6
commit
32e789ce9f
|
@ -1,22 +1,25 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Province struct {
|
type Province struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
ListRegency []Regency `json:"list_regency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Regency struct {
|
type Regency struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ProvinceID string `json:"province_id"`
|
ProvinceID string `json:"province_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Province *Province `json:"province,omitempty"`
|
Province *Province `json:"province,omitempty"`
|
||||||
|
ListDistrict []District `json:"list_district,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type District struct {
|
type District struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
RegencyID string `json:"regency_id"`
|
RegencyID string `json:"regency_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Regency *Regency `json:"regency,omitempty"`
|
Regency *Regency `json:"regency,omitempty"`
|
||||||
|
ListVillage []Village `json:"list_village,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Village struct {
|
type Village struct {
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package dto
|
|
||||||
|
|
||||||
type ProvinceDetailResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
ProvinsiName string `json:"provinsi_name"`
|
|
||||||
ListRegency []RegencyItem `json:"list_regency"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RegencyDetailResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
RegencyName string `json:"regency_name"`
|
|
||||||
ProvinceID string `json:"province_id"`
|
|
||||||
ProvinceName string `json:"province_name"`
|
|
||||||
ListDistrict []DistrictItem `json:"list_districts"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DistrictDetailResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
DistrictName string `json:"district_name"`
|
|
||||||
ProvinceID string `json:"province_id"`
|
|
||||||
ProvinceName string `json:"province_name"`
|
|
||||||
RegencyID string `json:"regency_id"`
|
|
||||||
RegencyName string `json:"regency_name"`
|
|
||||||
ListVillages []VillageItem `json:"list_villages"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type VillageDetailResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
VillageName string `json:"village_name"`
|
|
||||||
ProvinceID string `json:"province_id"`
|
|
||||||
RegencyID string `json:"regency_id"`
|
|
||||||
DistrictID string `json:"district_id"`
|
|
||||||
ProvinceName string `json:"province_name"`
|
|
||||||
RegencyName string `json:"regency_name"`
|
|
||||||
DistrictName string `json:"district_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RegencyItem struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
RegencyName string `json:"regency_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DistrictItem struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
DistrictName string `json:"district_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type VillageItem struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
VillageName string `json:"village_name"`
|
|
||||||
}
|
|
|
@ -23,7 +23,6 @@ func GetProvinces(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRegencies handles the GET request for regencies
|
|
||||||
func GetRegencies(c *fiber.Ctx) error {
|
func GetRegencies(c *fiber.Ctx) error {
|
||||||
regencies, err := services.GetRegencies()
|
regencies, err := services.GetRegencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,7 +40,6 @@ func GetRegencies(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDistricts handles the GET request for districts
|
|
||||||
func GetDistricts(c *fiber.Ctx) error {
|
func GetDistricts(c *fiber.Ctx) error {
|
||||||
districts, err := services.GetDistricts()
|
districts, err := services.GetDistricts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -59,7 +57,6 @@ func GetDistricts(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVillages handles the GET request for villages
|
|
||||||
func GetVillages(c *fiber.Ctx) error {
|
func GetVillages(c *fiber.Ctx) error {
|
||||||
villages, err := services.GetVillages()
|
villages, err := services.GetVillages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,101 +74,57 @@ func GetVillages(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetProvinceByID(c *fiber.Ctx) error {
|
func GetProvinceByID(c *fiber.Ctx) error {
|
||||||
id := c.Params("id")
|
id := c.Params("id")
|
||||||
province, regencies, err := services.GetProvinceByID(id)
|
province, err := services.GetProvinceByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||||
fiber.StatusNotFound,
|
fiber.StatusInternalServerError,
|
||||||
"Province not found",
|
"Failed to retrieve province",
|
||||||
nil,
|
nil,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
fiber.StatusOK,
|
fiber.StatusOK,
|
||||||
"Provinces by id retrieved successfully",
|
"Province by id retrieved successfully",
|
||||||
fiber.Map{
|
province,
|
||||||
"id": province.ID,
|
|
||||||
"provinsi_name": province.Name,
|
|
||||||
"list_regency": regencies,
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRegencyByID(c *fiber.Ctx) error {
|
func GetRegencyByID(c *fiber.Ctx) error {
|
||||||
id := c.Params("id")
|
id := c.Params("id")
|
||||||
regency, districts, err := services.GetRegencyByID(id)
|
regency, err := services.GetRegencyByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||||
fiber.StatusNotFound,
|
fiber.StatusInternalServerError,
|
||||||
"Regency not found",
|
"Failed to retrieve regency",
|
||||||
nil,
|
nil,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
provinces, _ := services.GetProvinces()
|
|
||||||
var provinceName string
|
|
||||||
for _, province := range provinces {
|
|
||||||
if province.ID == regency.ProvinceID {
|
|
||||||
provinceName = province.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
fiber.StatusOK,
|
fiber.StatusOK,
|
||||||
"Regency by id retrieved successfully",
|
"Regency by id retrieved successfully",
|
||||||
fiber.Map{
|
regency,
|
||||||
"id": regency.ID,
|
|
||||||
"province_id": regency.ProvinceID,
|
|
||||||
"province_name": provinceName,
|
|
||||||
"regency_name": regency.Name,
|
|
||||||
"list_districts": districts,
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDistrictByID(c *fiber.Ctx) error {
|
func GetDistrictByID(c *fiber.Ctx) error {
|
||||||
id := c.Params("id")
|
id := c.Params("id")
|
||||||
district, villages, err := services.GetDistrictByID(id)
|
district, err := services.GetDistrictByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||||
fiber.StatusNotFound,
|
fiber.StatusInternalServerError,
|
||||||
"District not found",
|
"Failed to retrieve district",
|
||||||
nil,
|
nil,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
provinces, _ := services.GetProvinces()
|
|
||||||
regencies, _ := services.GetRegencies()
|
|
||||||
var provinceName, regencyName string
|
|
||||||
for _, province := range provinces {
|
|
||||||
if province.ID == district.RegencyID {
|
|
||||||
provinceName = province.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, regency := range regencies {
|
|
||||||
if regency.ID == district.RegencyID {
|
|
||||||
regencyName = regency.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
fiber.StatusOK,
|
fiber.StatusOK,
|
||||||
"district by id retrieved successfully",
|
"District by id retrieved successfully",
|
||||||
fiber.Map{
|
district,
|
||||||
"id": district.ID,
|
|
||||||
"province_id": district.RegencyID,
|
|
||||||
"regency_id": district.RegencyID,
|
|
||||||
"province_name": provinceName,
|
|
||||||
"regency_name": regencyName,
|
|
||||||
"district_name": district.Name,
|
|
||||||
"list_villages": villages,
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,46 +132,16 @@ func GetVillageByID(c *fiber.Ctx) error {
|
||||||
id := c.Params("id")
|
id := c.Params("id")
|
||||||
village, err := services.GetVillageByID(id)
|
village, err := services.GetVillageByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||||
fiber.StatusNotFound,
|
fiber.StatusInternalServerError,
|
||||||
"Village not found",
|
"Failed to retrieve village",
|
||||||
nil,
|
nil,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
provinces, _ := services.GetProvinces()
|
|
||||||
regencies, _ := services.GetRegencies()
|
|
||||||
districts, _ := services.GetDistricts()
|
|
||||||
|
|
||||||
var provinceName, regencyName, districtName string
|
|
||||||
for _, province := range provinces {
|
|
||||||
if province.ID == village.ID {
|
|
||||||
provinceName = province.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, regency := range regencies {
|
|
||||||
if regency.ID == village.ID {
|
|
||||||
regencyName = regency.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, district := range districts {
|
|
||||||
if district.ID == village.ID {
|
|
||||||
districtName = district.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
fiber.StatusOK,
|
fiber.StatusOK,
|
||||||
"villages by id retrieved successfully",
|
"Village by id retrieved successfully",
|
||||||
fiber.Map{
|
village,
|
||||||
"id": village.ID,
|
|
||||||
"province_id": village.ID,
|
|
||||||
"regency_id": village.ID,
|
|
||||||
"district_id": village.ID,
|
|
||||||
"province_name": provinceName,
|
|
||||||
"regency_name": regencyName,
|
|
||||||
"district_name": districtName,
|
|
||||||
"village_name": village.Name,
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ func GetProvinces() ([]domain.Province, error) {
|
||||||
return provinces, nil
|
return provinces, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRegencies reads the regencies data from CSV and returns a slice of Regency
|
|
||||||
func GetRegencies() ([]domain.Regency, error) {
|
func GetRegencies() ([]domain.Regency, error) {
|
||||||
records, err := utils.ReadCSV("public/document/regencies.csv")
|
records, err := utils.ReadCSV("public/document/regencies.csv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,7 +44,6 @@ func GetRegencies() ([]domain.Regency, error) {
|
||||||
return regencies, nil
|
return regencies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDistricts reads the districts data from CSV and returns a slice of District
|
|
||||||
func GetDistricts() ([]domain.District, error) {
|
func GetDistricts() ([]domain.District, error) {
|
||||||
records, err := utils.ReadCSV("public/document/districts.csv")
|
records, err := utils.ReadCSV("public/document/districts.csv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,7 +63,6 @@ func GetDistricts() ([]domain.District, error) {
|
||||||
return districts, nil
|
return districts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVillages reads the villages data from CSV and returns a slice of Village
|
|
||||||
func GetVillages() ([]domain.Village, error) {
|
func GetVillages() ([]domain.Village, error) {
|
||||||
records, err := utils.ReadCSV("public/document/villages.csv")
|
records, err := utils.ReadCSV("public/document/villages.csv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,8 +82,7 @@ func GetVillages() ([]domain.Village, error) {
|
||||||
return villages, nil
|
return villages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetProvinceByID(id string) (domain.Province, error) {
|
||||||
func FindProvinceByID(id string) (domain.Province, error) {
|
|
||||||
provinces, err := GetProvinces()
|
provinces, err := GetProvinces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Province{}, err
|
return domain.Province{}, err
|
||||||
|
@ -94,13 +90,20 @@ func FindProvinceByID(id string) (domain.Province, error) {
|
||||||
|
|
||||||
for _, province := range provinces {
|
for _, province := range provinces {
|
||||||
if province.ID == id {
|
if province.ID == id {
|
||||||
|
|
||||||
|
regencies, err := GetRegenciesByProvinceID(id)
|
||||||
|
if err != nil {
|
||||||
|
return domain.Province{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
province.ListRegency = regencies
|
||||||
return province, nil
|
return province, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return domain.Province{}, errors.New("province not found")
|
return domain.Province{}, errors.New("province not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindRegencyByID(id string) (domain.Regency, error) {
|
func GetRegencyByID(id string) (domain.Regency, error) {
|
||||||
regencies, err := GetRegencies()
|
regencies, err := GetRegencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Regency{}, err
|
return domain.Regency{}, err
|
||||||
|
@ -108,13 +111,20 @@ func FindRegencyByID(id string) (domain.Regency, error) {
|
||||||
|
|
||||||
for _, regency := range regencies {
|
for _, regency := range regencies {
|
||||||
if regency.ID == id {
|
if regency.ID == id {
|
||||||
|
|
||||||
|
districts, err := GetDistrictsByRegencyID(id)
|
||||||
|
if err != nil {
|
||||||
|
return domain.Regency{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
regency.ListDistrict = districts
|
||||||
return regency, nil
|
return regency, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return domain.Regency{}, errors.New("regency not found")
|
return domain.Regency{}, errors.New("regency not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindDistrictByID(id string) (domain.District, error) {
|
func GetDistrictByID(id string) (domain.District, error) {
|
||||||
districts, err := GetDistricts()
|
districts, err := GetDistricts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.District{}, err
|
return domain.District{}, err
|
||||||
|
@ -122,13 +132,20 @@ func FindDistrictByID(id string) (domain.District, error) {
|
||||||
|
|
||||||
for _, district := range districts {
|
for _, district := range districts {
|
||||||
if district.ID == id {
|
if district.ID == id {
|
||||||
|
|
||||||
|
villages, err := GetVillagesByDistrictID(id)
|
||||||
|
if err != nil {
|
||||||
|
return domain.District{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
district.ListVillage = villages
|
||||||
return district, nil
|
return district, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return domain.District{}, errors.New("district not found")
|
return domain.District{}, errors.New("district not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindVillageByID(id string) (domain.Village, error) {
|
func GetVillageByID(id string) (domain.Village, error) {
|
||||||
villages, err := GetVillages()
|
villages, err := GetVillages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Village{}, err
|
return domain.Village{}, err
|
||||||
|
@ -141,3 +158,48 @@ func FindVillageByID(id string) (domain.Village, error) {
|
||||||
}
|
}
|
||||||
return domain.Village{}, errors.New("village not found")
|
return domain.Village{}, errors.New("village not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRegenciesByProvinceID(provinceID string) ([]domain.Regency, error) {
|
||||||
|
regencies, err := GetRegencies()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []domain.Regency
|
||||||
|
for _, regency := range regencies {
|
||||||
|
if regency.ProvinceID == provinceID {
|
||||||
|
result = append(result, regency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDistrictsByRegencyID(regencyID string) ([]domain.District, error) {
|
||||||
|
districts, err := GetDistricts()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []domain.District
|
||||||
|
for _, district := range districts {
|
||||||
|
if district.RegencyID == regencyID {
|
||||||
|
result = append(result, district)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetVillagesByDistrictID(districtID string) ([]domain.Village, error) {
|
||||||
|
villages, err := GetVillages()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []domain.Village
|
||||||
|
for _, village := range villages {
|
||||||
|
if village.DistrictID == districtID {
|
||||||
|
result = append(result, village)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ func GetProvinces() ([]domain.Province, error) {
|
||||||
return provinces, nil
|
return provinces, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRegencies retrieves a list of regencies
|
|
||||||
func GetRegencies() ([]domain.Regency, error) {
|
func GetRegencies() ([]domain.Regency, error) {
|
||||||
regencies, err := repositories.GetRegencies()
|
regencies, err := repositories.GetRegencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -22,7 +21,6 @@ func GetRegencies() ([]domain.Regency, error) {
|
||||||
return regencies, nil
|
return regencies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDistricts retrieves a list of districts
|
|
||||||
func GetDistricts() ([]domain.District, error) {
|
func GetDistricts() ([]domain.District, error) {
|
||||||
districts, err := repositories.GetDistricts()
|
districts, err := repositories.GetDistricts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,7 +29,6 @@ func GetDistricts() ([]domain.District, error) {
|
||||||
return districts, nil
|
return districts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVillages retrieves a list of villages
|
|
||||||
func GetVillages() ([]domain.Village, error) {
|
func GetVillages() ([]domain.Village, error) {
|
||||||
villages, err := repositories.GetVillages()
|
villages, err := repositories.GetVillages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,71 +37,32 @@ func GetVillages() ([]domain.Village, error) {
|
||||||
return villages, nil
|
return villages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProvinceByID(id string) (domain.Province, []domain.Regency, error) {
|
func GetProvinceByID(id string) (domain.Province, error) {
|
||||||
province, err := repositories.FindProvinceByID(id)
|
province, err := repositories.GetProvinceByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Province{}, nil, err
|
return domain.Province{}, err
|
||||||
}
|
}
|
||||||
|
return province, nil
|
||||||
regencies, err := repositories.GetRegencies()
|
|
||||||
if err != nil {
|
|
||||||
return domain.Province{}, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var listRegency []domain.Regency
|
|
||||||
for _, regency := range regencies {
|
|
||||||
if regency.ProvinceID == province.ID {
|
|
||||||
listRegency = append(listRegency, regency)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return province, listRegency, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRegencyByID(id string) (domain.Regency, []domain.District, error) {
|
func GetRegencyByID(id string) (domain.Regency, error) {
|
||||||
regency, err := repositories.FindRegencyByID(id)
|
regency, err := repositories.GetRegencyByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Regency{}, nil, err
|
return domain.Regency{}, err
|
||||||
}
|
}
|
||||||
|
return regency, nil
|
||||||
districts, err := repositories.GetDistricts()
|
|
||||||
if err != nil {
|
|
||||||
return domain.Regency{}, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var listDistrict []domain.District
|
|
||||||
for _, district := range districts {
|
|
||||||
if district.RegencyID == regency.ID {
|
|
||||||
listDistrict = append(listDistrict, district)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return regency, listDistrict, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDistrictByID(id string) (domain.District, []domain.Village, error) {
|
func GetDistrictByID(id string) (domain.District, error) {
|
||||||
district, err := repositories.FindDistrictByID(id)
|
district, err := repositories.GetDistrictByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.District{}, nil, err
|
return domain.District{}, err
|
||||||
}
|
}
|
||||||
|
return district, nil
|
||||||
villages, err := repositories.GetVillages()
|
|
||||||
if err != nil {
|
|
||||||
return domain.District{}, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var listVillage []domain.Village
|
|
||||||
for _, village := range villages {
|
|
||||||
if village.DistrictID == district.ID {
|
|
||||||
listVillage = append(listVillage, village)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return district, listVillage, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVillageByID(id string) (domain.Village, error) {
|
func GetVillageByID(id string) (domain.Village, error) {
|
||||||
village, err := repositories.FindVillageByID(id)
|
village, err := repositories.GetVillageByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.Village{}, err
|
return domain.Village{}, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue