From 2d068eef348f3249a087e5c9b82f22ad9ff79707 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sat, 3 Jun 2023 23:25:36 +0200 Subject: [PATCH 1/9] [ref]- routes refactor --- main.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 8470c52..a652e02 100644 --- a/main.go +++ b/main.go @@ -13,30 +13,30 @@ func main() { //localhost := os.Getenv("localhost") router := gin.Default() //District routes - router.GET("/District", routes.GetDistricts) - router.GET("/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/District/Search/:search", routes.Search) + router.GET("/api/District", routes.GetDistricts) + router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) + router.GET("/api/District/Search/:search", routes.Search) //Constituency routes - router.GET("/Constituency", routes.GetConstituencies) - router.GET("/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + router.GET("/api/Constituency", routes.GetConstituencies) + router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) //Village routes - router.GET("/Village", routes.GetVillages) - router.GET("/Village/District/:search", routes.SearchVillageWithDistrict) + router.GET("/api/Village", routes.GetVillages) + router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) //Traditional Authority Routes - router.GET("/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) // Residential Areas Routes - router.GET("/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/ResidentialArea/:search", routes.SearchResidentialArea) + router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) + router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) //Wards Routes - router.GET("/Wards", routes.GetWards) - router.GET("/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/Wards/District/:search", routes.SearchWardWithDistrict) + router.GET("/api/Wards", routes.GetWards) + router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) + router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) address := os.Getenv("server_address") err := router.Run(address) From d04beb4fdb260e15034e59bfff3342b4246a9bef Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Thu, 8 Jun 2023 23:12:31 +0200 Subject: [PATCH 2/9] [feat]- all districts route --- .gitignore | 3 +- docs/docs.go | 85 ++++++++++++++++++++++++ docs/swagger.json | 60 +++++++++++++++++ docs/swagger.yaml | 39 +++++++++++ go.mod | 56 +++++++++++----- go.sum | 135 +++++++++++++++++++++++++++++++++++++++ main.go | 24 ++++++- src/routes/disctricts.go | 15 +++-- swagger.yml | 11 ++++ 9 files changed, 405 insertions(+), 23 deletions(-) create mode 100644 docs/docs.go create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml create mode 100644 swagger.yml diff --git a/.gitignore b/.gitignore index b838fde..fd87744 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ database/test.sql *.exe malawi-country-data /dist/ -/build/ \ No newline at end of file +/build/ +fly.toml \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..2a3cf89 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,85 @@ +// Code generated by swaggo/swag. DO NOT EDIT. + +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/District": { + "get": { + "description": "Get user details by their ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + } + }, + "definitions": { + "structs.District": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "traditional_authorities": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0", + Host: "localhost:8080", + BasePath: "/api", + Schemes: []string{}, + Title: "Malawi Country Data API", + Description: "An API for the malawian country details", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..1c6e842 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,60 @@ +{ + "swagger": "2.0", + "info": { + "description": "An API for the malawian country details", + "title": "Malawi Country Data API", + "contact": {}, + "version": "1.0" + }, + "host": "localhost:8080", + "basePath": "/api", + "paths": { + "/api/District": { + "get": { + "description": "Get user details by their ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + } + }, + "definitions": { + "structs.District": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "traditional_authorities": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..43997dc --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,39 @@ +basePath: /api +definitions: + structs.District: + properties: + code: + type: string + id: + type: integer + name: + type: string + region: + type: string + traditional_authorities: + items: + type: string + type: array + type: object +host: localhost:8080 +info: + contact: {} + description: An API for the malawian country details + title: Malawi Country Data API + version: "1.0" +paths: + /api/District: + get: + consumes: + - application/json + description: Get user details by their ID + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + tags: + - Districts +swagger: "2.0" diff --git a/go.mod b/go.mod index f3d6f02..f24aa2a 100644 --- a/go.mod +++ b/go.mod @@ -3,33 +3,57 @@ module malawi-country-data go 1.19 require ( - github.com/gin-gonic/gin v1.9.0 + github.com/gin-gonic/gin v1.9.1 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.7 ) require ( - github.com/bytedance/sonic v1.8.0 // indirect + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.2.0 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/spec v0.20.9 // indirect + github.com/go-openapi/swag v0.22.3 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.11.2 // indirect - github.com/goccy/go-json v0.10.0 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect - github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/gin-swagger v1.6.0 // indirect + github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.9 // indirect - golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect - golang.org/x/crypto v0.5.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + github.com/urfave/cli/v2 v2.25.5 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.9.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + golang.org/x/tools v0.9.3 // indirect + google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect + google.golang.org/grpc v1.54.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 60106c0..00257e2 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,44 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= +github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= +github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= @@ -18,35 +46,69 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -57,29 +119,102 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= +github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= +github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= +github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= +golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= +google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/main.go b/main.go index a652e02..292d083 100644 --- a/main.go +++ b/main.go @@ -2,16 +2,29 @@ package main import ( "log" + "malawi-country-data/src/routes" + _"malawi-country-data/docs" + "net/http" "os" "github.com/gin-gonic/gin" "github.com/joho/godotenv" - "malawi-country-data/src/routes" + ginSwagger "github.com/swaggo/gin-swagger" + swaggerFiles "github.com/swaggo/files" ) +// @title Malawi Country Data API +// @version 1.0 +// @description An API for the malawian country details +// @host localhost:8080 +// @Basepath /api func main() { godotenv.Load() //localhost := os.Getenv("localhost") router := gin.Default() + + // Documentation + router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) + //District routes router.GET("/api/District", routes.GetDistricts) router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) @@ -38,8 +51,15 @@ func main() { router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + // Healthcheck endpoint + router.GET("/HealthCheck", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "healthy": true, + }) + }) + address := os.Getenv("server_address") - err := router.Run(address) + err := router.Run(":8080") if err != nil { log.Fatalf("failed to start server at %s got error %v", address, err) } diff --git a/src/routes/disctricts.go b/src/routes/disctricts.go index ec86566..07094f1 100644 --- a/src/routes/disctricts.go +++ b/src/routes/disctricts.go @@ -3,15 +3,22 @@ package routes import ( "encoding/json" "fmt" + _ "malawi-country-data/docs" + "malawi-country-data/src/structs" "net/http" "strings" - "malawi-country-data/src/structs" + "github.com/gin-gonic/gin" ) -var query = "" - +var query string // Gets all the country districts +// @Description Get user details by their ID +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /api/District [get] func GetDistricts(client *gin.Context) { query = `SELECT json_build_object( @@ -147,7 +154,7 @@ func Search(client *gin.Context) { ) AS district FROM districts d WHERE d.name ILIKE '%%%s%%' OR d.code ILIKE '%%%s%%' - `, search,search) + `, search, search) rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/swagger.yml b/swagger.yml new file mode 100644 index 0000000..70491c0 --- /dev/null +++ b/swagger.yml @@ -0,0 +1,11 @@ +consumes: + - application/json +info: + title: Malawi Country Data + version: 0.1.0 +paths: {} +produces: + - application/json +schemes: + - http +swagger: "2.0" From 4a965a6cd3032ca98629bb03520a6a10f5636d14 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sun, 11 Jun 2023 01:49:06 +0200 Subject: [PATCH 3/9] [REF] - Cleaned up project directory --- docs/docs.go | 71 ++++++++++++++++++- docs/swagger.json | 71 ++++++++++++++++++- docs/swagger.yaml | 52 +++++++++++++- go.mod | 19 ++--- go.sum | 64 ++--------------- main.go | 68 +++--------------- src/{routes => controller}/constituency.go | 0 src/{routes => controller}/disctricts.go | 21 +++++- .../residential_area.go | 0 src/{routes => controller}/routes.go | 0 .../traditional_authority.go | 0 src/{routes => controller}/village.go | 0 src/{routes => controller}/ward.go | 0 src/router/router.go | 65 +++++++++++++++++ 14 files changed, 285 insertions(+), 146 deletions(-) rename src/{routes => controller}/constituency.go (100%) rename src/{routes => controller}/disctricts.go (86%) rename src/{routes => controller}/residential_area.go (100%) rename src/{routes => controller}/routes.go (100%) rename src/{routes => controller}/traditional_authority.go (100%) rename src/{routes => controller}/village.go (100%) rename src/{routes => controller}/ward.go (100%) create mode 100644 src/router/router.go diff --git a/docs/docs.go b/docs/docs.go index 2a3cf89..c8af4e4 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,7 +16,71 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/District": { + "/District/Region/{region}": { + "get": { + "description": "Gets districts by region(Southern, Central, Northern)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search district", + "parameters": [ + { + "type": "string", + "description": "region", + "name": "region", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/District/Search/{search}": { + "get": { + "description": "Searches for country districts based on the search parameter", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search District", + "parameters": [ + { + "type": "string", + "description": "district/code", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts": { "get": { "description": "Get user details by their ID", "consumes": [ @@ -28,6 +92,7 @@ const docTemplate = `{ "tags": [ "Districts" ], + "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -68,12 +133,12 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "1.0", + Version: "1.0.2", Host: "localhost:8080", BasePath: "/api", Schemes: []string{}, Title: "Malawi Country Data API", - Description: "An API for the malawian country details", + Description: "With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/docs/swagger.json b/docs/swagger.json index 1c6e842..a610dac 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,15 +1,79 @@ { "swagger": "2.0", "info": { - "description": "An API for the malawian country details", + "description": "With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure.", "title": "Malawi Country Data API", "contact": {}, - "version": "1.0" + "version": "1.0.2" }, "host": "localhost:8080", "basePath": "/api", "paths": { - "/api/District": { + "/District/Region/{region}": { + "get": { + "description": "Gets districts by region(Southern, Central, Northern)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search district", + "parameters": [ + { + "type": "string", + "description": "region", + "name": "region", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/District/Search/{search}": { + "get": { + "description": "Searches for country districts based on the search parameter", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search District", + "parameters": [ + { + "type": "string", + "description": "district/code", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts": { "get": { "description": "Get user details by their ID", "consumes": [ @@ -21,6 +85,7 @@ "tags": [ "Districts" ], + "summary": "Get all districts", "responses": { "200": { "description": "OK", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 43997dc..783a2be 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -18,11 +18,56 @@ definitions: host: localhost:8080 info: contact: {} - description: An API for the malawian country details + description: With this API, developers can easily access and retrieve data related + to these administrative divisions, enabling them to build location-based applications, + conduct geospatial analysis, or enhance existing systems with accurate and up-to-date + information about Malawi's geographic structure. title: Malawi Country Data API - version: "1.0" + version: 1.0.2 paths: - /api/District: + /District/Region/{region}: + get: + consumes: + - application/json + description: Gets districts by region(Southern, Central, Northern) + parameters: + - description: region + in: path + name: region + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Search district + tags: + - Districts + /District/Search/{search}: + get: + consumes: + - application/json + description: Searches for country districts based on the search parameter + parameters: + - description: district/code + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Search District + tags: + - Districts + /Districts: get: consumes: - application/json @@ -34,6 +79,7 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' + summary: Get all districts tags: - Districts swagger: "2.0" diff --git a/go.mod b/go.mod index f24aa2a..a7a652a 100644 --- a/go.mod +++ b/go.mod @@ -6,15 +6,15 @@ require ( github.com/gin-gonic/gin v1.9.1 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.7 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.16.1 ) require ( github.com/KyleBanks/depth v1.2.1 // indirect - github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -25,7 +25,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect @@ -35,25 +35,14 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/swaggo/files v1.0.1 // indirect - github.com/swaggo/gin-swagger v1.6.0 // indirect - github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/urfave/cli/v2 v2.25.5 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.9.3 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect - google.golang.org/grpc v1.54.0 // indirect google.golang.org/protobuf v1.30.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 00257e2..076e8fe 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,20 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= -github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= -github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= -github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -44,19 +35,14 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= -github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= -github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= @@ -64,20 +50,16 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= @@ -87,28 +69,18 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= -github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -117,7 +89,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= @@ -130,33 +101,22 @@ github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= -github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= -github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -166,10 +126,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -179,10 +136,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -191,16 +145,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= -google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -216,5 +162,3 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/main.go b/main.go index 292d083..a5144ce 100644 --- a/main.go +++ b/main.go @@ -1,66 +1,14 @@ package main -import ( - "log" - "malawi-country-data/src/routes" - _"malawi-country-data/docs" - "net/http" - "os" - "github.com/gin-gonic/gin" - "github.com/joho/godotenv" - ginSwagger "github.com/swaggo/gin-swagger" - swaggerFiles "github.com/swaggo/files" +import( + "malawi-country-data/src/router" ) -// @title Malawi Country Data API -// @version 1.0 -// @description An API for the malawian country details +// @Title Malawi Country Data API +// @version 1.0.2 +// @Description With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure. // @host localhost:8080 // @Basepath /api -func main() { - godotenv.Load() - //localhost := os.Getenv("localhost") - router := gin.Default() - - // Documentation - router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) - - //District routes - router.GET("/api/District", routes.GetDistricts) - router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/api/District/Search/:search", routes.Search) - - //Constituency routes - router.GET("/api/Constituency", routes.GetConstituencies) - router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) - - //Village routes - router.GET("/api/Village", routes.GetVillages) - router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) - - //Traditional Authority Routes - router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) - - // Residential Areas Routes - router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) - - //Wards Routes - router.GET("/api/Wards", routes.GetWards) - router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) - - // Healthcheck endpoint - router.GET("/HealthCheck", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{ - "healthy": true, - }) - }) - - address := os.Getenv("server_address") - err := router.Run(":8080") - if err != nil { - log.Fatalf("failed to start server at %s got error %v", address, err) - } -} +func main(){ + router.Route() +} \ No newline at end of file diff --git a/src/routes/constituency.go b/src/controller/constituency.go similarity index 100% rename from src/routes/constituency.go rename to src/controller/constituency.go diff --git a/src/routes/disctricts.go b/src/controller/disctricts.go similarity index 86% rename from src/routes/disctricts.go rename to src/controller/disctricts.go index 07094f1..b6e4a98 100644 --- a/src/routes/disctricts.go +++ b/src/controller/disctricts.go @@ -12,13 +12,15 @@ import ( ) var query string + // Gets all the country districts +// @Summary Get all districts // @Description Get user details by their ID // @Tags Districts // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /api/District [get] +// @Router /Districts [get] func GetDistricts(client *gin.Context) { query = `SELECT json_build_object( @@ -62,6 +64,14 @@ func GetDistricts(client *gin.Context) { } // Gets districts by country region +// @Summary Search District +// @Description Gets districts by region(Southern, Central, Northern) +// @Param region path string true "region" +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /District/Region/{region} [get] func GetDistrictByRegion(client *gin.Context) { region := client.Param("region") @@ -137,9 +147,16 @@ func districtsappend(region string) ([]structs.District, error) { } // Searches for country districts based on the search parameter +// @Summary Search District/Code +// @Description Searches for country districts based on the search parameter +// @Param search path string true "district/code" +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /District/Search/{search} [get] func Search(client *gin.Context) { search := client.Param("search") - query = fmt.Sprintf(`SELECT json_build_object( 'id', d.id, diff --git a/src/routes/residential_area.go b/src/controller/residential_area.go similarity index 100% rename from src/routes/residential_area.go rename to src/controller/residential_area.go diff --git a/src/routes/routes.go b/src/controller/routes.go similarity index 100% rename from src/routes/routes.go rename to src/controller/routes.go diff --git a/src/routes/traditional_authority.go b/src/controller/traditional_authority.go similarity index 100% rename from src/routes/traditional_authority.go rename to src/controller/traditional_authority.go diff --git a/src/routes/village.go b/src/controller/village.go similarity index 100% rename from src/routes/village.go rename to src/controller/village.go diff --git a/src/routes/ward.go b/src/controller/ward.go similarity index 100% rename from src/routes/ward.go rename to src/controller/ward.go diff --git a/src/router/router.go b/src/router/router.go new file mode 100644 index 0000000..ed4ca0b --- /dev/null +++ b/src/router/router.go @@ -0,0 +1,65 @@ +package router + +import ( + "log" + "malawi-country-data/src/controller" + _"malawi-country-data/docs" + "net/http" + "os" + "github.com/gin-gonic/gin" + "github.com/joho/godotenv" + ginSwagger "github.com/swaggo/gin-swagger" + swaggerFiles "github.com/swaggo/files" +) +var server_address string +func init(){ + godotenv.Load() + server_address = os.Getenv("server_address") +} + +func Route() { + //localhost := os.Getenv("localhost") + router := gin.Default() + + // Documentation + router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) + + //District routes + router.GET("/api/Districts", routes.GetDistricts) + router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) + router.GET("/api/District/Search/:search", routes.Search) + + //Constituency routes + router.GET("/api/Constituencies", routes.GetConstituencies) + router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + + //Village routes + router.GET("/api/Villages", routes.GetVillages) + router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) + + //Traditional Authority Routes + router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + + // Residential Areas Routes + router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) + router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) + + //Wards Routes + router.GET("/api/Wards", routes.GetWards) + router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) + router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + + // Healthcheck endpoint + router.GET("/HealthCheck", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "healthy": true, + }) + }) + + address := os.Getenv("server_address") + err := router.Run(":8080") + if err != nil { + log.Fatalf("failed to start server at %s got error %v", address, err) + } +} From bb624f232366090db43dd8774f9a4dfaf37c2355 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sun, 11 Jun 2023 23:16:07 +0200 Subject: [PATCH 4/9] [FEAT]- Documents all routes --- docs/docs.go | 506 +++++++++++++++++++++++- docs/swagger.json | 506 +++++++++++++++++++++++- docs/swagger.yaml | 336 +++++++++++++++- src/controller/constituency.go | 93 ++++- src/controller/disctricts.go | 10 +- src/controller/residential_area.go | 17 +- src/controller/routes.go | 2 +- src/controller/traditional_authority.go | 18 +- src/controller/village.go | 45 ++- src/controller/ward.go | 72 +++- src/router/router.go | 46 ++- 11 files changed, 1562 insertions(+), 89 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index c8af4e4..9ce39b1 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,7 +16,122 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/District/Region/{region}": { + "/Constituencies": { + "get": { + "description": "Gets all the constituencies", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all the country constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Central": { + "get": { + "description": "Gets all the constituencies in the Central region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all Central region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Northern": { + "get": { + "description": "Gets all the constituencies in the northern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all northern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Southern": { + "get": { + "description": "Gets all the constituencies in the southern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all southern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Districts": { + "get": { + "description": "Gets all districts with their related information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Gets all districts", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts/Region/{region}": { "get": { "description": "Gets districts by region(Southern, Central, Northern)", "consumes": [ @@ -28,7 +143,7 @@ const docTemplate = `{ "tags": [ "Districts" ], - "summary": "Search district", + "summary": "Search District", "parameters": [ { "type": "string", @@ -48,7 +163,7 @@ const docTemplate = `{ } } }, - "/District/Search/{search}": { + "/Districts/Search/{search}": { "get": { "description": "Searches for country districts based on the search parameter", "consumes": [ @@ -60,7 +175,7 @@ const docTemplate = `{ "tags": [ "Districts" ], - "summary": "Search District", + "summary": "Search District/Code", "parameters": [ { "type": "string", @@ -80,9 +195,9 @@ const docTemplate = `{ } } }, - "/Districts": { + "/ResidentialAreas": { "get": { - "description": "Get user details by their ID", + "description": "Gets all Residential Area records", "consumes": [ "application/json" ], @@ -90,9 +205,96 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Districts" + "Residential Area" + ], + "summary": "Gets all Residential Areas", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/ResidentialAreas/Search/{search}": { + "get": { + "description": "Searches though Residential Area records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Residential Area" + ], + "summary": "Searches for Residential Areas", + "parameters": [ + { + "type": "string", + "description": "Residential Area", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/TraditionalAuthorities": { + "get": { + "description": "Gets all Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Gets Traditional authorities", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/TraditionalAuthorities/Search/{search}": { + "get": { + "description": "Searches though Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Searches Traditional authorities", + "parameters": [ + { + "type": "string", + "description": "Traditional Authority", + "name": "search", + "in": "path", + "required": true + } ], - "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -102,9 +304,234 @@ const docTemplate = `{ } } } + }, + "/Villages": { + "get": { + "description": "Gets all the villages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/District/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages in a district", + "parameters": [ + { + "type": "string", + "description": "District", + "name": "district", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/Search/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Searches village name", + "parameters": [ + { + "type": "string", + "description": "village", + "name": "village", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Wards": { + "get": { + "description": "Gets all Ward records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all Wards", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/District/{search}": { + "get": { + "description": "Gets all wards by district name", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Searches wards by district", + "parameters": [ + { + "type": "string", + "description": "District name", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Central": { + "get": { + "description": "Gets all central region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the Central region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Northern": { + "get": { + "description": "Gets all northern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the northern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Southern": { + "get": { + "description": "Gets all southern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the southern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } } }, "definitions": { + "structs.Constituency": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "structs.District": { "type": "object", "properties": { @@ -127,6 +554,69 @@ const docTemplate = `{ } } } + }, + "structs.ResidentialArea": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "residential_areas": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "structs.Village": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "village_name": { + "type": "string" + } + } + }, + "structs.Ward": { + "type": "object", + "properties": { + "constituency": { + "type": "string" + }, + "district_code": { + "type": "string" + }, + "district_name": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "region": { + "type": "string" + }, + "wards": { + "type": "array", + "items": { + "type": "string" + } + } + } } } }` diff --git a/docs/swagger.json b/docs/swagger.json index a610dac..cd52618 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -9,7 +9,122 @@ "host": "localhost:8080", "basePath": "/api", "paths": { - "/District/Region/{region}": { + "/Constituencies": { + "get": { + "description": "Gets all the constituencies", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all the country constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Central": { + "get": { + "description": "Gets all the constituencies in the Central region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all Central region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Northern": { + "get": { + "description": "Gets all the constituencies in the northern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all northern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Southern": { + "get": { + "description": "Gets all the constituencies in the southern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all southern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Districts": { + "get": { + "description": "Gets all districts with their related information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Gets all districts", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts/Region/{region}": { "get": { "description": "Gets districts by region(Southern, Central, Northern)", "consumes": [ @@ -21,7 +136,7 @@ "tags": [ "Districts" ], - "summary": "Search district", + "summary": "Search District", "parameters": [ { "type": "string", @@ -41,7 +156,7 @@ } } }, - "/District/Search/{search}": { + "/Districts/Search/{search}": { "get": { "description": "Searches for country districts based on the search parameter", "consumes": [ @@ -53,7 +168,7 @@ "tags": [ "Districts" ], - "summary": "Search District", + "summary": "Search District/Code", "parameters": [ { "type": "string", @@ -73,9 +188,9 @@ } } }, - "/Districts": { + "/ResidentialAreas": { "get": { - "description": "Get user details by their ID", + "description": "Gets all Residential Area records", "consumes": [ "application/json" ], @@ -83,9 +198,96 @@ "application/json" ], "tags": [ - "Districts" + "Residential Area" + ], + "summary": "Gets all Residential Areas", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/ResidentialAreas/Search/{search}": { + "get": { + "description": "Searches though Residential Area records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Residential Area" + ], + "summary": "Searches for Residential Areas", + "parameters": [ + { + "type": "string", + "description": "Residential Area", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/TraditionalAuthorities": { + "get": { + "description": "Gets all Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Gets Traditional authorities", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/TraditionalAuthorities/Search/{search}": { + "get": { + "description": "Searches though Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Searches Traditional authorities", + "parameters": [ + { + "type": "string", + "description": "Traditional Authority", + "name": "search", + "in": "path", + "required": true + } ], - "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -95,9 +297,234 @@ } } } + }, + "/Villages": { + "get": { + "description": "Gets all the villages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/District/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages in a district", + "parameters": [ + { + "type": "string", + "description": "District", + "name": "district", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/Search/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Searches village name", + "parameters": [ + { + "type": "string", + "description": "village", + "name": "village", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Wards": { + "get": { + "description": "Gets all Ward records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all Wards", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/District/{search}": { + "get": { + "description": "Gets all wards by district name", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Searches wards by district", + "parameters": [ + { + "type": "string", + "description": "District name", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Central": { + "get": { + "description": "Gets all central region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the Central region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Northern": { + "get": { + "description": "Gets all northern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the northern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Southern": { + "get": { + "description": "Gets all southern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the southern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } } }, "definitions": { + "structs.Constituency": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "structs.District": { "type": "object", "properties": { @@ -120,6 +547,69 @@ } } } + }, + "structs.ResidentialArea": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "residential_areas": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "structs.Village": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "village_name": { + "type": "string" + } + } + }, + "structs.Ward": { + "type": "object", + "properties": { + "constituency": { + "type": "string" + }, + "district_code": { + "type": "string" + }, + "district_name": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "region": { + "type": "string" + }, + "wards": { + "type": "array", + "items": { + "type": "string" + } + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 783a2be..c38c931 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,14 @@ basePath: /api definitions: + structs.Constituency: + properties: + district: + type: string + id: + type: integer + name: + type: string + type: object structs.District: properties: code: @@ -15,6 +24,47 @@ definitions: type: string type: array type: object + structs.ResidentialArea: + properties: + code: + type: string + id: + type: integer + name: + type: string + region: + type: string + residential_areas: + items: + type: string + type: array + type: object + structs.Village: + properties: + district: + type: string + id: + type: integer + village_name: + type: string + type: object + structs.Ward: + properties: + constituency: + type: string + district_code: + type: string + district_name: + type: string + id: + type: integer + region: + type: string + wards: + items: + type: string + type: array + type: object host: localhost:8080 info: contact: {} @@ -25,7 +75,82 @@ info: title: Malawi Country Data API version: 1.0.2 paths: - /District/Region/{region}: + /Constituencies: + get: + consumes: + - application/json + description: Gets all the constituencies + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all the country constituencies + tags: + - Constituencies + /Constituencies/Region/Central: + get: + consumes: + - application/json + description: Gets all the constituencies in the Central region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all Central region constituencies + tags: + - Constituencies + /Constituencies/Region/Northern: + get: + consumes: + - application/json + description: Gets all the constituencies in the northern region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all northern region constituencies + tags: + - Constituencies + /Constituencies/Region/Southern: + get: + consumes: + - application/json + description: Gets all the constituencies in the southern region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all southern region constituencies + tags: + - Constituencies + /Districts: + get: + consumes: + - application/json + description: Gets all districts with their related information + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Gets all districts + tags: + - Districts + /Districts/Region/{region}: get: consumes: - application/json @@ -43,10 +168,10 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Search district + summary: Search District tags: - Districts - /District/Search/{search}: + /Districts/Search/{search}: get: consumes: - application/json @@ -64,14 +189,50 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Search District + summary: Search District/Code tags: - Districts - /Districts: + /ResidentialAreas: + get: + consumes: + - application/json + description: Gets all Residential Area records + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.ResidentialArea' + summary: Gets all Residential Areas + tags: + - Residential Area + /ResidentialAreas/Search/{search}: get: consumes: - application/json - description: Get user details by their ID + description: Searches though Residential Area records + parameters: + - description: Residential Area + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.ResidentialArea' + summary: Searches for Residential Areas + tags: + - Residential Area + /TraditionalAuthorities: + get: + consumes: + - application/json + description: Gets all Traditional Authority records produces: - application/json responses: @@ -79,7 +240,166 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Get all districts + summary: Gets Traditional authorities tags: - - Districts + - Traditional Authority + /TraditionalAuthorities/Search/{search}: + get: + consumes: + - application/json + description: Searches though Traditional Authority records + parameters: + - description: Traditional Authority + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Searches Traditional authorities + tags: + - Traditional Authority + /Villages: + get: + consumes: + - application/json + description: Gets all the villages + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Gets all the country villages + tags: + - villages + /Villages/District/{search}: + get: + consumes: + - application/json + description: Gets all the villages in district + parameters: + - description: District + in: path + name: district + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Gets all the country villages in a district + tags: + - villages + /Villages/Search/{search}: + get: + consumes: + - application/json + description: Gets all the villages in district + parameters: + - description: village + in: path + name: village + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Searches village name + tags: + - villages + /Wards: + get: + consumes: + - application/json + description: Gets all Ward records + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all Wards + tags: + - Wards + /Wards/District/{search}: + get: + consumes: + - application/json + description: Gets all wards by district name + parameters: + - description: District name + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Searches wards by district + tags: + - Wards + /Wards/Region/Central: + get: + consumes: + - application/json + description: Gets all central region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the Central region + tags: + - Wards + /Wards/Region/Northern: + get: + consumes: + - application/json + description: Gets all northern region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the northern region + tags: + - Wards + /Wards/Region/Southern: + get: + consumes: + - application/json + description: Gets all southern region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the southern region + tags: + - Wards swagger: "2.0" diff --git a/src/controller/constituency.go b/src/controller/constituency.go index 8833342..e8cd576 100644 --- a/src/controller/constituency.go +++ b/src/controller/constituency.go @@ -1,9 +1,8 @@ -package routes +package controller import ( "fmt" "net/http" - "strings" "malawi-country-data/src/structs" @@ -13,8 +12,14 @@ import ( var constituency []structs.Constituency var getconstituency structs.Constituency - // Gets all the country constituencies +// @Summary Gets all the country constituencies +// @Description Gets all the constituencies +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies [get] func GetConstituencies(client *gin.Context) { query = `SELECT c.id, c.name, d.name FROM constituencies c @@ -45,38 +50,88 @@ func GetConstituencies(client *gin.Context) { client.IndentedJSON(http.StatusOK, constituency) } -// Gets all the constituencies in a region -func GetConstituenciesWithRegion(client *gin.Context) { - region := strings.ToLower(client.Param("region")) - - var data []structs.Constituency - var err error - switch region { - case "central": - data, err = getConstituencyByRegion("central") - case "northern": - data, err = getConstituencyByRegion("northern") - case "southern": - data, err = getConstituencyByRegion("southern") - default: - client.JSON(http.StatusBadRequest, structs.BadRequestProblemDetail("Unknown region name.")) +// Gets all the constituencies in the northern region +// @Summary Gets all northern region constituencies +// @Description Gets all the constituencies in the northern region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Northern [get] +func GetNorthernConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("northern") + if err != nil { + client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) return } + client.IndentedJSON(http.StatusOK, data) +} +// Gets all the constituencies in the southern region +// @Summary Gets all southern region constituencies +// @Description Gets all the constituencies in the southern region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Southern [get] +func GetSouthernConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("southern") if err != nil { client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) return } + client.IndentedJSON(http.StatusOK, data) +} +// Gets all the constituencies in the Central region +// @Summary Gets all Central region constituencies +// @Description Gets all the constituencies in the Central region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Central [get] +func GetCentralConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("central") + if err != nil { + client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) + return + } client.IndentedJSON(http.StatusOK, data) } +// func GetConstituenciesWithRegion(client *gin.Context) { +// region := strings.ToLower(client.Param("region")) + +// var data []structs.Constituency +// var err error +// switch region { +// case "central": +// data, err = getConstituencyByRegion("central") +// case "northern": +// data, err = getConstituencyByRegion("northern") +// case "southern": +// data, err = getConstituencyByRegion("southern") +// default: +// client.JSON(http.StatusBadRequest, structs.BadRequestProblemDetail("Unknown region name.")) +// return +// } + +// if err != nil { +// client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) +// return +// } + +// client.IndentedJSON(http.StatusOK, data) +// } + func getConstituencyByRegion(region string) ([]structs.Constituency, error) { query = fmt.Sprintf(`SELECT c.id, c.name, d.name FROM constituencies c JOIN districts d ON d.id = c.district_id WHERE d.region ILIKE '%s'`, region) - + rows, err := db.Query(query) if err != nil { return nil, err diff --git a/src/controller/disctricts.go b/src/controller/disctricts.go index b6e4a98..3d0f7d0 100644 --- a/src/controller/disctricts.go +++ b/src/controller/disctricts.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -14,8 +14,8 @@ import ( var query string // Gets all the country districts -// @Summary Get all districts -// @Description Get user details by their ID +// @Summary Gets all districts +// @Description Gets all districts with their related information // @Tags Districts // @Accept json // @Produce application/json @@ -71,7 +71,7 @@ func GetDistricts(client *gin.Context) { // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /District/Region/{region} [get] +// @Router /Districts/Region/{region} [get] func GetDistrictByRegion(client *gin.Context) { region := client.Param("region") @@ -154,7 +154,7 @@ func districtsappend(region string) ([]structs.District, error) { // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /District/Search/{search} [get] +// @Router /Districts/Search/{search} [get] func Search(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT diff --git a/src/controller/residential_area.go b/src/controller/residential_area.go index b1552dd..be18527 100644 --- a/src/controller/residential_area.go +++ b/src/controller/residential_area.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -12,6 +12,14 @@ import ( var residential_areas []structs.ResidentialArea +// @Summary Searches for Residential Areas +// @Description Searches though Residential Area records +// @Tags Residential Area +// @Param search path string true "Residential Area" +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.ResidentialArea{} +// @Router /ResidentialAreas/Search/{search} [get] func SearchResidentialArea(client *gin.Context){ search := client.Param("search") query = fmt.Sprintf(`SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district @@ -20,6 +28,13 @@ func SearchResidentialArea(client *gin.Context){ getResidentialArea(client,query) } +// @Summary Gets all Residential Areas +// @Description Gets all Residential Area records +// @Tags Residential Area +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.ResidentialArea{} +// @Router /ResidentialAreas [get] func GetResidentialAreas(client *gin.Context){ query := `SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district FROM districts d, residential_areas r diff --git a/src/controller/routes.go b/src/controller/routes.go index f07161d..aeb45a1 100644 --- a/src/controller/routes.go +++ b/src/controller/routes.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "database/sql" diff --git a/src/controller/traditional_authority.go b/src/controller/traditional_authority.go index 8e577f2..df85eb5 100644 --- a/src/controller/traditional_authority.go +++ b/src/controller/traditional_authority.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -12,7 +12,13 @@ import ( var traditionalauthority []structs.District - +// @Summary Gets Traditional authorities +// @Description Gets all Traditional Authority records +// @Tags Traditional Authority +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /TraditionalAuthorities [get] func GetTraditionalAuthorities(client *gin.Context) { query = `SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'traditional_authorities', (SELECT json_agg(ta.name) FROM traditional_authorities ta WHERE ta.district_id = d.id)) as district FROM districts d @@ -20,6 +26,14 @@ func GetTraditionalAuthorities(client *gin.Context) { getData(client, query) } +// @Summary Searches Traditional authorities +// @Description Searches though Traditional Authority records +// @Tags Traditional Authority +// @Param search path string true "Traditional Authority" +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /TraditionalAuthorities/Search/{search} [get] func SearchTraditionalAuthorities(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'traditional_authorities', (SELECT json_agg(ta.name) FROM traditional_authorities ta WHERE ta.district_id = d.id)) as district diff --git a/src/controller/village.go b/src/controller/village.go index 63e9d60..72b8912 100644 --- a/src/controller/village.go +++ b/src/controller/village.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "fmt" @@ -11,23 +11,58 @@ import ( var village []structs.Village +// Gets all the country villages +// @Summary Gets all the country villages +// @Description Gets all the villages +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages [get] func GetVillages(client *gin.Context) { query = `SELECT v.id, v.village_name, d.name FROM villages v JOIN districts d ON d.id = v.district_id` - SearchVillage(client, query) + _search(client, query) } +// Gets all the villages in a district +// @Summary Gets all the country villages in a district +// @Description Gets all the villages in district +// @Param district path string true "District" +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages/District/{search} [get] func SearchVillageWithDistrict(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT v.id, v.village_name, d.name FROM villages v JOIN districts d ON d.id = v.district_id - WHERE d.name ilike '%s'`, search) - SearchVillage(client, query) + WHERE d.name ilike '%%%s%%'`, search) + _search(client, query) } -func SearchVillage(client *gin.Context, query string) { +// Searches for the villages +// @Summary Searches village name +// @Description Gets all the villages in district +// @Param village path string true "village" +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages/Search/{search} [get] +func VillageSearch(client *gin.Context){ + search := client.Param("search") + query = fmt.Sprintf( `SELECT v.id, v.village_name, d.name + FROM villages v + JOIN districts d ON d.id = v.district_id + WHERE v.name ilike '%%%s%%'`,search) + _search(client, query) +} + +func _search(client *gin.Context, query string) { rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/src/controller/ward.go b/src/controller/ward.go index 041c4e2..4a6ca8a 100644 --- a/src/controller/ward.go +++ b/src/controller/ward.go @@ -1,34 +1,82 @@ -package routes +package controller import ( "encoding/json" "fmt" - "net/http" "malawi-country-data/src/structs" + "net/http" + "github.com/gin-gonic/gin" ) var wards []structs.Ward -func GetWards(client *gin.Context){ +// @Summary Gets all Wards +// @Description Gets all Ward records +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards [get] +func GetWards(client *gin.Context) { query := `SELECT json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) AS district FROM districts d INNER JOIN constituencies c ON c.district_id = d.id` - SearchWard(client,query) + SearchWard(client, query) } -func SearchWardWithRegion(client *gin.Context){ - search := client.Param("search") +// @Summary Gets all wards in the northern region +// @Description Gets all northern region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Northern [get] +func NorthernRegionWards(client *gin.Context) { + SearchWardWithRegion("Northern", client) +} + +// @Summary Gets all wards in the southern region +// @Description Gets all southern region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Southern [get] +func SouthernRegionWards(client *gin.Context) { + SearchWardWithRegion("Southern", client) +} + +// @Summary Gets all wards in the Central region +// @Description Gets all central region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Central [get] +func CentralRegionWards(client *gin.Context) { + SearchWardWithRegion("Central", client) +} + +func SearchWardWithRegion(Region string, client *gin.Context) { query := fmt.Sprintf(`SELECT json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) as district FROM districts d JOIN constituencies c ON c.district_id = d.id - WHERE d.region ILIKE '%s'`, search) - SearchWard(client,query) + WHERE d.region ILIKE '%s'`, Region) + SearchWard(client, query) } -func SearchWardWithDistrict(client *gin.Context){ +// @Summary Searches wards by district +// @Description Gets all wards by district name +// @Param search path string true "District name" +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/District/{search} [get] +func SearchWardWithDistrict(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`select json_build_object( 'id', d.id, @@ -47,12 +95,12 @@ func SearchWardWithDistrict(client *gin.Context){ WHERE c.district_id=d.id AND d.name ILIKE '%s' - `,search) - SearchWard(client,query) + `, search) + SearchWard(client, query) } func SearchWard(client *gin.Context, query string) { - + rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/src/router/router.go b/src/router/router.go index ed4ca0b..8557317 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -24,31 +24,37 @@ func Route() { // Documentation router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) - //District routes - router.GET("/api/Districts", routes.GetDistricts) - router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/api/District/Search/:search", routes.Search) + //District controller + router.GET("/api/Districts", controller.GetDistricts) + router.GET("/api/Districts/Region/:region", controller.GetDistrictByRegion) + router.GET("/api/Districts/Search/:search", controller.Search) - //Constituency routes - router.GET("/api/Constituencies", routes.GetConstituencies) - router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + //Constituency controller + router.GET("/api/Constituencies", controller.GetConstituencies) + router.GET("/api/Constituencies/Region/Northern", controller.GetNorthernConstituencies) + router.GET("/api/Constituencies/Region/Southern", controller.GetSouthernConstituencies) + router.GET("/api/Constituencies/Region/Central", controller.GetCentralConstituencies) + // router.GET("/api/Constituencies/Region/:region", controller.GetConstituenciesWithRegion) - //Village routes - router.GET("/api/Villages", routes.GetVillages) - router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) + //Village controller + router.GET("/api/Villages", controller.GetVillages) + router.GET("/api/Villages/Search/:search", controller.GetVillages) + router.GET("/api/Villages/District/:search", controller.SearchVillageWithDistrict) - //Traditional Authority Routes - router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + //Traditional Authority controller + router.GET("/api/TraditionalAuthorities", controller.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthorities/Search/:search", controller.SearchTraditionalAuthorities) - // Residential Areas Routes - router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) + // Residential Areas controller + router.GET("/api/ResidentialAreas", controller.GetResidentialAreas) + router.GET("/api/ResidentialAreas/Search/:search", controller.SearchResidentialArea) - //Wards Routes - router.GET("/api/Wards", routes.GetWards) - router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + //Wards controller + router.GET("/api/Wards", controller.GetWards) + router.GET("/api/Wards/Region/Northern", controller.NorthernRegionWards) + router.GET("/api/Wards/Region/Central", controller.CentralRegionWards) + router.GET("/api/Wards/Region/Southern", controller.SouthernRegionWards) + router.GET("/api/Wards/District/:search", controller.SearchWardWithDistrict) // Healthcheck endpoint router.GET("/HealthCheck", func(c *gin.Context) { From 220ab73a31fe5af0538771b238231c7293700b39 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sat, 3 Jun 2023 23:25:36 +0200 Subject: [PATCH 5/9] [ref]- routes refactor --- main.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 8470c52..a652e02 100644 --- a/main.go +++ b/main.go @@ -13,30 +13,30 @@ func main() { //localhost := os.Getenv("localhost") router := gin.Default() //District routes - router.GET("/District", routes.GetDistricts) - router.GET("/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/District/Search/:search", routes.Search) + router.GET("/api/District", routes.GetDistricts) + router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) + router.GET("/api/District/Search/:search", routes.Search) //Constituency routes - router.GET("/Constituency", routes.GetConstituencies) - router.GET("/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + router.GET("/api/Constituency", routes.GetConstituencies) + router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) //Village routes - router.GET("/Village", routes.GetVillages) - router.GET("/Village/District/:search", routes.SearchVillageWithDistrict) + router.GET("/api/Village", routes.GetVillages) + router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) //Traditional Authority Routes - router.GET("/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) // Residential Areas Routes - router.GET("/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/ResidentialArea/:search", routes.SearchResidentialArea) + router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) + router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) //Wards Routes - router.GET("/Wards", routes.GetWards) - router.GET("/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/Wards/District/:search", routes.SearchWardWithDistrict) + router.GET("/api/Wards", routes.GetWards) + router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) + router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) address := os.Getenv("server_address") err := router.Run(address) From e01d54ad3db5df925818bf7138909cd84e92eb32 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Thu, 8 Jun 2023 23:12:31 +0200 Subject: [PATCH 6/9] [feat]- all districts route --- .gitignore | 3 +- docs/docs.go | 85 ++++++++++++++++++++++++ docs/swagger.json | 60 +++++++++++++++++ docs/swagger.yaml | 39 +++++++++++ go.mod | 56 +++++++++++----- go.sum | 135 +++++++++++++++++++++++++++++++++++++++ main.go | 24 ++++++- src/routes/disctricts.go | 15 +++-- swagger.yml | 11 ++++ 9 files changed, 405 insertions(+), 23 deletions(-) create mode 100644 docs/docs.go create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml create mode 100644 swagger.yml diff --git a/.gitignore b/.gitignore index b838fde..fd87744 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ database/test.sql *.exe malawi-country-data /dist/ -/build/ \ No newline at end of file +/build/ +fly.toml \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..2a3cf89 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,85 @@ +// Code generated by swaggo/swag. DO NOT EDIT. + +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/District": { + "get": { + "description": "Get user details by their ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + } + }, + "definitions": { + "structs.District": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "traditional_authorities": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0", + Host: "localhost:8080", + BasePath: "/api", + Schemes: []string{}, + Title: "Malawi Country Data API", + Description: "An API for the malawian country details", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..1c6e842 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,60 @@ +{ + "swagger": "2.0", + "info": { + "description": "An API for the malawian country details", + "title": "Malawi Country Data API", + "contact": {}, + "version": "1.0" + }, + "host": "localhost:8080", + "basePath": "/api", + "paths": { + "/api/District": { + "get": { + "description": "Get user details by their ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + } + }, + "definitions": { + "structs.District": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "traditional_authorities": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..43997dc --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,39 @@ +basePath: /api +definitions: + structs.District: + properties: + code: + type: string + id: + type: integer + name: + type: string + region: + type: string + traditional_authorities: + items: + type: string + type: array + type: object +host: localhost:8080 +info: + contact: {} + description: An API for the malawian country details + title: Malawi Country Data API + version: "1.0" +paths: + /api/District: + get: + consumes: + - application/json + description: Get user details by their ID + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + tags: + - Districts +swagger: "2.0" diff --git a/go.mod b/go.mod index f3d6f02..f24aa2a 100644 --- a/go.mod +++ b/go.mod @@ -3,33 +3,57 @@ module malawi-country-data go 1.19 require ( - github.com/gin-gonic/gin v1.9.0 + github.com/gin-gonic/gin v1.9.1 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.7 ) require ( - github.com/bytedance/sonic v1.8.0 // indirect + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.2.0 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/spec v0.20.9 // indirect + github.com/go-openapi/swag v0.22.3 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.11.2 // indirect - github.com/goccy/go-json v0.10.0 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect - github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/gin-swagger v1.6.0 // indirect + github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.9 // indirect - golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect - golang.org/x/crypto v0.5.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + github.com/urfave/cli/v2 v2.25.5 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.9.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + golang.org/x/tools v0.9.3 // indirect + google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect + google.golang.org/grpc v1.54.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 60106c0..00257e2 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,44 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= +github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= +github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= @@ -18,35 +46,69 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -57,29 +119,102 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= +github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= +github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= +github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= +golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= +google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/main.go b/main.go index a652e02..292d083 100644 --- a/main.go +++ b/main.go @@ -2,16 +2,29 @@ package main import ( "log" + "malawi-country-data/src/routes" + _"malawi-country-data/docs" + "net/http" "os" "github.com/gin-gonic/gin" "github.com/joho/godotenv" - "malawi-country-data/src/routes" + ginSwagger "github.com/swaggo/gin-swagger" + swaggerFiles "github.com/swaggo/files" ) +// @title Malawi Country Data API +// @version 1.0 +// @description An API for the malawian country details +// @host localhost:8080 +// @Basepath /api func main() { godotenv.Load() //localhost := os.Getenv("localhost") router := gin.Default() + + // Documentation + router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) + //District routes router.GET("/api/District", routes.GetDistricts) router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) @@ -38,8 +51,15 @@ func main() { router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + // Healthcheck endpoint + router.GET("/HealthCheck", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "healthy": true, + }) + }) + address := os.Getenv("server_address") - err := router.Run(address) + err := router.Run(":8080") if err != nil { log.Fatalf("failed to start server at %s got error %v", address, err) } diff --git a/src/routes/disctricts.go b/src/routes/disctricts.go index ec86566..07094f1 100644 --- a/src/routes/disctricts.go +++ b/src/routes/disctricts.go @@ -3,15 +3,22 @@ package routes import ( "encoding/json" "fmt" + _ "malawi-country-data/docs" + "malawi-country-data/src/structs" "net/http" "strings" - "malawi-country-data/src/structs" + "github.com/gin-gonic/gin" ) -var query = "" - +var query string // Gets all the country districts +// @Description Get user details by their ID +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /api/District [get] func GetDistricts(client *gin.Context) { query = `SELECT json_build_object( @@ -147,7 +154,7 @@ func Search(client *gin.Context) { ) AS district FROM districts d WHERE d.name ILIKE '%%%s%%' OR d.code ILIKE '%%%s%%' - `, search,search) + `, search, search) rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/swagger.yml b/swagger.yml new file mode 100644 index 0000000..70491c0 --- /dev/null +++ b/swagger.yml @@ -0,0 +1,11 @@ +consumes: + - application/json +info: + title: Malawi Country Data + version: 0.1.0 +paths: {} +produces: + - application/json +schemes: + - http +swagger: "2.0" From e47839433796eaa219e1463977c08f95d0cecbe0 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sun, 11 Jun 2023 01:49:06 +0200 Subject: [PATCH 7/9] [REF] - Cleaned up project directory --- docs/docs.go | 71 ++++++++++++++++++- docs/swagger.json | 71 ++++++++++++++++++- docs/swagger.yaml | 52 +++++++++++++- go.mod | 19 ++--- go.sum | 64 ++--------------- main.go | 68 +++--------------- src/{routes => controller}/constituency.go | 0 src/{routes => controller}/disctricts.go | 21 +++++- .../residential_area.go | 0 src/{routes => controller}/routes.go | 0 .../traditional_authority.go | 0 src/{routes => controller}/village.go | 0 src/{routes => controller}/ward.go | 0 src/router/router.go | 65 +++++++++++++++++ 14 files changed, 285 insertions(+), 146 deletions(-) rename src/{routes => controller}/constituency.go (100%) rename src/{routes => controller}/disctricts.go (86%) rename src/{routes => controller}/residential_area.go (100%) rename src/{routes => controller}/routes.go (100%) rename src/{routes => controller}/traditional_authority.go (100%) rename src/{routes => controller}/village.go (100%) rename src/{routes => controller}/ward.go (100%) create mode 100644 src/router/router.go diff --git a/docs/docs.go b/docs/docs.go index 2a3cf89..c8af4e4 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,7 +16,71 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/District": { + "/District/Region/{region}": { + "get": { + "description": "Gets districts by region(Southern, Central, Northern)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search district", + "parameters": [ + { + "type": "string", + "description": "region", + "name": "region", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/District/Search/{search}": { + "get": { + "description": "Searches for country districts based on the search parameter", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search District", + "parameters": [ + { + "type": "string", + "description": "district/code", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts": { "get": { "description": "Get user details by their ID", "consumes": [ @@ -28,6 +92,7 @@ const docTemplate = `{ "tags": [ "Districts" ], + "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -68,12 +133,12 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "1.0", + Version: "1.0.2", Host: "localhost:8080", BasePath: "/api", Schemes: []string{}, Title: "Malawi Country Data API", - Description: "An API for the malawian country details", + Description: "With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/docs/swagger.json b/docs/swagger.json index 1c6e842..a610dac 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,15 +1,79 @@ { "swagger": "2.0", "info": { - "description": "An API for the malawian country details", + "description": "With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure.", "title": "Malawi Country Data API", "contact": {}, - "version": "1.0" + "version": "1.0.2" }, "host": "localhost:8080", "basePath": "/api", "paths": { - "/api/District": { + "/District/Region/{region}": { + "get": { + "description": "Gets districts by region(Southern, Central, Northern)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search district", + "parameters": [ + { + "type": "string", + "description": "region", + "name": "region", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/District/Search/{search}": { + "get": { + "description": "Searches for country districts based on the search parameter", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Search District", + "parameters": [ + { + "type": "string", + "description": "district/code", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts": { "get": { "description": "Get user details by their ID", "consumes": [ @@ -21,6 +85,7 @@ "tags": [ "Districts" ], + "summary": "Get all districts", "responses": { "200": { "description": "OK", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 43997dc..783a2be 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -18,11 +18,56 @@ definitions: host: localhost:8080 info: contact: {} - description: An API for the malawian country details + description: With this API, developers can easily access and retrieve data related + to these administrative divisions, enabling them to build location-based applications, + conduct geospatial analysis, or enhance existing systems with accurate and up-to-date + information about Malawi's geographic structure. title: Malawi Country Data API - version: "1.0" + version: 1.0.2 paths: - /api/District: + /District/Region/{region}: + get: + consumes: + - application/json + description: Gets districts by region(Southern, Central, Northern) + parameters: + - description: region + in: path + name: region + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Search district + tags: + - Districts + /District/Search/{search}: + get: + consumes: + - application/json + description: Searches for country districts based on the search parameter + parameters: + - description: district/code + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Search District + tags: + - Districts + /Districts: get: consumes: - application/json @@ -34,6 +79,7 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' + summary: Get all districts tags: - Districts swagger: "2.0" diff --git a/go.mod b/go.mod index f24aa2a..a7a652a 100644 --- a/go.mod +++ b/go.mod @@ -6,15 +6,15 @@ require ( github.com/gin-gonic/gin v1.9.1 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.7 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.16.1 ) require ( github.com/KyleBanks/depth v1.2.1 // indirect - github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -25,7 +25,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect @@ -35,25 +35,14 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/swaggo/files v1.0.1 // indirect - github.com/swaggo/gin-swagger v1.6.0 // indirect - github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/urfave/cli/v2 v2.25.5 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.9.3 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect - google.golang.org/grpc v1.54.0 // indirect google.golang.org/protobuf v1.30.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 00257e2..076e8fe 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,20 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= -github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA= -github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= -github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -44,19 +35,14 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= -github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= -github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= @@ -64,20 +50,16 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= @@ -87,28 +69,18 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= -github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -117,7 +89,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= @@ -130,33 +101,22 @@ github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU= -github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= -github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -166,10 +126,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -179,10 +136,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -191,16 +145,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= -google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -216,5 +162,3 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/main.go b/main.go index 292d083..a5144ce 100644 --- a/main.go +++ b/main.go @@ -1,66 +1,14 @@ package main -import ( - "log" - "malawi-country-data/src/routes" - _"malawi-country-data/docs" - "net/http" - "os" - "github.com/gin-gonic/gin" - "github.com/joho/godotenv" - ginSwagger "github.com/swaggo/gin-swagger" - swaggerFiles "github.com/swaggo/files" +import( + "malawi-country-data/src/router" ) -// @title Malawi Country Data API -// @version 1.0 -// @description An API for the malawian country details +// @Title Malawi Country Data API +// @version 1.0.2 +// @Description With this API, developers can easily access and retrieve data related to these administrative divisions, enabling them to build location-based applications, conduct geospatial analysis, or enhance existing systems with accurate and up-to-date information about Malawi's geographic structure. // @host localhost:8080 // @Basepath /api -func main() { - godotenv.Load() - //localhost := os.Getenv("localhost") - router := gin.Default() - - // Documentation - router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) - - //District routes - router.GET("/api/District", routes.GetDistricts) - router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/api/District/Search/:search", routes.Search) - - //Constituency routes - router.GET("/api/Constituency", routes.GetConstituencies) - router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) - - //Village routes - router.GET("/api/Village", routes.GetVillages) - router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) - - //Traditional Authority Routes - router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) - - // Residential Areas Routes - router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) - - //Wards Routes - router.GET("/api/Wards", routes.GetWards) - router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) - - // Healthcheck endpoint - router.GET("/HealthCheck", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{ - "healthy": true, - }) - }) - - address := os.Getenv("server_address") - err := router.Run(":8080") - if err != nil { - log.Fatalf("failed to start server at %s got error %v", address, err) - } -} +func main(){ + router.Route() +} \ No newline at end of file diff --git a/src/routes/constituency.go b/src/controller/constituency.go similarity index 100% rename from src/routes/constituency.go rename to src/controller/constituency.go diff --git a/src/routes/disctricts.go b/src/controller/disctricts.go similarity index 86% rename from src/routes/disctricts.go rename to src/controller/disctricts.go index 07094f1..b6e4a98 100644 --- a/src/routes/disctricts.go +++ b/src/controller/disctricts.go @@ -12,13 +12,15 @@ import ( ) var query string + // Gets all the country districts +// @Summary Get all districts // @Description Get user details by their ID // @Tags Districts // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /api/District [get] +// @Router /Districts [get] func GetDistricts(client *gin.Context) { query = `SELECT json_build_object( @@ -62,6 +64,14 @@ func GetDistricts(client *gin.Context) { } // Gets districts by country region +// @Summary Search District +// @Description Gets districts by region(Southern, Central, Northern) +// @Param region path string true "region" +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /District/Region/{region} [get] func GetDistrictByRegion(client *gin.Context) { region := client.Param("region") @@ -137,9 +147,16 @@ func districtsappend(region string) ([]structs.District, error) { } // Searches for country districts based on the search parameter +// @Summary Search District/Code +// @Description Searches for country districts based on the search parameter +// @Param search path string true "district/code" +// @Tags Districts +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /District/Search/{search} [get] func Search(client *gin.Context) { search := client.Param("search") - query = fmt.Sprintf(`SELECT json_build_object( 'id', d.id, diff --git a/src/routes/residential_area.go b/src/controller/residential_area.go similarity index 100% rename from src/routes/residential_area.go rename to src/controller/residential_area.go diff --git a/src/routes/routes.go b/src/controller/routes.go similarity index 100% rename from src/routes/routes.go rename to src/controller/routes.go diff --git a/src/routes/traditional_authority.go b/src/controller/traditional_authority.go similarity index 100% rename from src/routes/traditional_authority.go rename to src/controller/traditional_authority.go diff --git a/src/routes/village.go b/src/controller/village.go similarity index 100% rename from src/routes/village.go rename to src/controller/village.go diff --git a/src/routes/ward.go b/src/controller/ward.go similarity index 100% rename from src/routes/ward.go rename to src/controller/ward.go diff --git a/src/router/router.go b/src/router/router.go new file mode 100644 index 0000000..ed4ca0b --- /dev/null +++ b/src/router/router.go @@ -0,0 +1,65 @@ +package router + +import ( + "log" + "malawi-country-data/src/controller" + _"malawi-country-data/docs" + "net/http" + "os" + "github.com/gin-gonic/gin" + "github.com/joho/godotenv" + ginSwagger "github.com/swaggo/gin-swagger" + swaggerFiles "github.com/swaggo/files" +) +var server_address string +func init(){ + godotenv.Load() + server_address = os.Getenv("server_address") +} + +func Route() { + //localhost := os.Getenv("localhost") + router := gin.Default() + + // Documentation + router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) + + //District routes + router.GET("/api/Districts", routes.GetDistricts) + router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) + router.GET("/api/District/Search/:search", routes.Search) + + //Constituency routes + router.GET("/api/Constituencies", routes.GetConstituencies) + router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + + //Village routes + router.GET("/api/Villages", routes.GetVillages) + router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) + + //Traditional Authority Routes + router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + + // Residential Areas Routes + router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) + router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) + + //Wards Routes + router.GET("/api/Wards", routes.GetWards) + router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) + router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + + // Healthcheck endpoint + router.GET("/HealthCheck", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "healthy": true, + }) + }) + + address := os.Getenv("server_address") + err := router.Run(":8080") + if err != nil { + log.Fatalf("failed to start server at %s got error %v", address, err) + } +} From 34aef271823bef2bff9c15ef64e90f11966b0322 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Sun, 11 Jun 2023 23:16:07 +0200 Subject: [PATCH 8/9] [FEAT]- Documents all routes --- docs/docs.go | 506 +++++++++++++++++++++++- docs/swagger.json | 506 +++++++++++++++++++++++- docs/swagger.yaml | 336 +++++++++++++++- src/controller/constituency.go | 93 ++++- src/controller/disctricts.go | 10 +- src/controller/residential_area.go | 17 +- src/controller/routes.go | 2 +- src/controller/traditional_authority.go | 18 +- src/controller/village.go | 45 ++- src/controller/ward.go | 72 +++- src/router/router.go | 46 ++- 11 files changed, 1562 insertions(+), 89 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index c8af4e4..9ce39b1 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,7 +16,122 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/District/Region/{region}": { + "/Constituencies": { + "get": { + "description": "Gets all the constituencies", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all the country constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Central": { + "get": { + "description": "Gets all the constituencies in the Central region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all Central region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Northern": { + "get": { + "description": "Gets all the constituencies in the northern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all northern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Southern": { + "get": { + "description": "Gets all the constituencies in the southern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all southern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Districts": { + "get": { + "description": "Gets all districts with their related information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Gets all districts", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts/Region/{region}": { "get": { "description": "Gets districts by region(Southern, Central, Northern)", "consumes": [ @@ -28,7 +143,7 @@ const docTemplate = `{ "tags": [ "Districts" ], - "summary": "Search district", + "summary": "Search District", "parameters": [ { "type": "string", @@ -48,7 +163,7 @@ const docTemplate = `{ } } }, - "/District/Search/{search}": { + "/Districts/Search/{search}": { "get": { "description": "Searches for country districts based on the search parameter", "consumes": [ @@ -60,7 +175,7 @@ const docTemplate = `{ "tags": [ "Districts" ], - "summary": "Search District", + "summary": "Search District/Code", "parameters": [ { "type": "string", @@ -80,9 +195,9 @@ const docTemplate = `{ } } }, - "/Districts": { + "/ResidentialAreas": { "get": { - "description": "Get user details by their ID", + "description": "Gets all Residential Area records", "consumes": [ "application/json" ], @@ -90,9 +205,96 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Districts" + "Residential Area" + ], + "summary": "Gets all Residential Areas", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/ResidentialAreas/Search/{search}": { + "get": { + "description": "Searches though Residential Area records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Residential Area" + ], + "summary": "Searches for Residential Areas", + "parameters": [ + { + "type": "string", + "description": "Residential Area", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/TraditionalAuthorities": { + "get": { + "description": "Gets all Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Gets Traditional authorities", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/TraditionalAuthorities/Search/{search}": { + "get": { + "description": "Searches though Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Searches Traditional authorities", + "parameters": [ + { + "type": "string", + "description": "Traditional Authority", + "name": "search", + "in": "path", + "required": true + } ], - "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -102,9 +304,234 @@ const docTemplate = `{ } } } + }, + "/Villages": { + "get": { + "description": "Gets all the villages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/District/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages in a district", + "parameters": [ + { + "type": "string", + "description": "District", + "name": "district", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/Search/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Searches village name", + "parameters": [ + { + "type": "string", + "description": "village", + "name": "village", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Wards": { + "get": { + "description": "Gets all Ward records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all Wards", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/District/{search}": { + "get": { + "description": "Gets all wards by district name", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Searches wards by district", + "parameters": [ + { + "type": "string", + "description": "District name", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Central": { + "get": { + "description": "Gets all central region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the Central region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Northern": { + "get": { + "description": "Gets all northern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the northern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Southern": { + "get": { + "description": "Gets all southern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the southern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } } }, "definitions": { + "structs.Constituency": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "structs.District": { "type": "object", "properties": { @@ -127,6 +554,69 @@ const docTemplate = `{ } } } + }, + "structs.ResidentialArea": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "residential_areas": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "structs.Village": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "village_name": { + "type": "string" + } + } + }, + "structs.Ward": { + "type": "object", + "properties": { + "constituency": { + "type": "string" + }, + "district_code": { + "type": "string" + }, + "district_name": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "region": { + "type": "string" + }, + "wards": { + "type": "array", + "items": { + "type": "string" + } + } + } } } }` diff --git a/docs/swagger.json b/docs/swagger.json index a610dac..cd52618 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -9,7 +9,122 @@ "host": "localhost:8080", "basePath": "/api", "paths": { - "/District/Region/{region}": { + "/Constituencies": { + "get": { + "description": "Gets all the constituencies", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all the country constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Central": { + "get": { + "description": "Gets all the constituencies in the Central region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all Central region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Northern": { + "get": { + "description": "Gets all the constituencies in the northern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all northern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Constituencies/Region/Southern": { + "get": { + "description": "Gets all the constituencies in the southern region", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Constituencies" + ], + "summary": "Gets all southern region constituencies", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Constituency" + } + } + } + } + }, + "/Districts": { + "get": { + "description": "Gets all districts with their related information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Districts" + ], + "summary": "Gets all districts", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/Districts/Region/{region}": { "get": { "description": "Gets districts by region(Southern, Central, Northern)", "consumes": [ @@ -21,7 +136,7 @@ "tags": [ "Districts" ], - "summary": "Search district", + "summary": "Search District", "parameters": [ { "type": "string", @@ -41,7 +156,7 @@ } } }, - "/District/Search/{search}": { + "/Districts/Search/{search}": { "get": { "description": "Searches for country districts based on the search parameter", "consumes": [ @@ -53,7 +168,7 @@ "tags": [ "Districts" ], - "summary": "Search District", + "summary": "Search District/Code", "parameters": [ { "type": "string", @@ -73,9 +188,9 @@ } } }, - "/Districts": { + "/ResidentialAreas": { "get": { - "description": "Get user details by their ID", + "description": "Gets all Residential Area records", "consumes": [ "application/json" ], @@ -83,9 +198,96 @@ "application/json" ], "tags": [ - "Districts" + "Residential Area" + ], + "summary": "Gets all Residential Areas", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/ResidentialAreas/Search/{search}": { + "get": { + "description": "Searches though Residential Area records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Residential Area" + ], + "summary": "Searches for Residential Areas", + "parameters": [ + { + "type": "string", + "description": "Residential Area", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.ResidentialArea" + } + } + } + } + }, + "/TraditionalAuthorities": { + "get": { + "description": "Gets all Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Gets Traditional authorities", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.District" + } + } + } + } + }, + "/TraditionalAuthorities/Search/{search}": { + "get": { + "description": "Searches though Traditional Authority records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Traditional Authority" + ], + "summary": "Searches Traditional authorities", + "parameters": [ + { + "type": "string", + "description": "Traditional Authority", + "name": "search", + "in": "path", + "required": true + } ], - "summary": "Get all districts", "responses": { "200": { "description": "OK", @@ -95,9 +297,234 @@ } } } + }, + "/Villages": { + "get": { + "description": "Gets all the villages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/District/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Gets all the country villages in a district", + "parameters": [ + { + "type": "string", + "description": "District", + "name": "district", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Villages/Search/{search}": { + "get": { + "description": "Gets all the villages in district", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "villages" + ], + "summary": "Searches village name", + "parameters": [ + { + "type": "string", + "description": "village", + "name": "village", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Village" + } + } + } + } + }, + "/Wards": { + "get": { + "description": "Gets all Ward records", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all Wards", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/District/{search}": { + "get": { + "description": "Gets all wards by district name", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Searches wards by district", + "parameters": [ + { + "type": "string", + "description": "District name", + "name": "search", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Central": { + "get": { + "description": "Gets all central region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the Central region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Northern": { + "get": { + "description": "Gets all northern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the northern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } + }, + "/Wards/Region/Southern": { + "get": { + "description": "Gets all southern region wards", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Wards" + ], + "summary": "Gets all wards in the southern region", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structs.Ward" + } + } + } + } } }, "definitions": { + "structs.Constituency": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "structs.District": { "type": "object", "properties": { @@ -120,6 +547,69 @@ } } } + }, + "structs.ResidentialArea": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "region": { + "type": "string" + }, + "residential_areas": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "structs.Village": { + "type": "object", + "properties": { + "district": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "village_name": { + "type": "string" + } + } + }, + "structs.Ward": { + "type": "object", + "properties": { + "constituency": { + "type": "string" + }, + "district_code": { + "type": "string" + }, + "district_name": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "region": { + "type": "string" + }, + "wards": { + "type": "array", + "items": { + "type": "string" + } + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 783a2be..c38c931 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,14 @@ basePath: /api definitions: + structs.Constituency: + properties: + district: + type: string + id: + type: integer + name: + type: string + type: object structs.District: properties: code: @@ -15,6 +24,47 @@ definitions: type: string type: array type: object + structs.ResidentialArea: + properties: + code: + type: string + id: + type: integer + name: + type: string + region: + type: string + residential_areas: + items: + type: string + type: array + type: object + structs.Village: + properties: + district: + type: string + id: + type: integer + village_name: + type: string + type: object + structs.Ward: + properties: + constituency: + type: string + district_code: + type: string + district_name: + type: string + id: + type: integer + region: + type: string + wards: + items: + type: string + type: array + type: object host: localhost:8080 info: contact: {} @@ -25,7 +75,82 @@ info: title: Malawi Country Data API version: 1.0.2 paths: - /District/Region/{region}: + /Constituencies: + get: + consumes: + - application/json + description: Gets all the constituencies + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all the country constituencies + tags: + - Constituencies + /Constituencies/Region/Central: + get: + consumes: + - application/json + description: Gets all the constituencies in the Central region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all Central region constituencies + tags: + - Constituencies + /Constituencies/Region/Northern: + get: + consumes: + - application/json + description: Gets all the constituencies in the northern region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all northern region constituencies + tags: + - Constituencies + /Constituencies/Region/Southern: + get: + consumes: + - application/json + description: Gets all the constituencies in the southern region + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Constituency' + summary: Gets all southern region constituencies + tags: + - Constituencies + /Districts: + get: + consumes: + - application/json + description: Gets all districts with their related information + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Gets all districts + tags: + - Districts + /Districts/Region/{region}: get: consumes: - application/json @@ -43,10 +168,10 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Search district + summary: Search District tags: - Districts - /District/Search/{search}: + /Districts/Search/{search}: get: consumes: - application/json @@ -64,14 +189,50 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Search District + summary: Search District/Code tags: - Districts - /Districts: + /ResidentialAreas: + get: + consumes: + - application/json + description: Gets all Residential Area records + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.ResidentialArea' + summary: Gets all Residential Areas + tags: + - Residential Area + /ResidentialAreas/Search/{search}: get: consumes: - application/json - description: Get user details by their ID + description: Searches though Residential Area records + parameters: + - description: Residential Area + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.ResidentialArea' + summary: Searches for Residential Areas + tags: + - Residential Area + /TraditionalAuthorities: + get: + consumes: + - application/json + description: Gets all Traditional Authority records produces: - application/json responses: @@ -79,7 +240,166 @@ paths: description: OK schema: $ref: '#/definitions/structs.District' - summary: Get all districts + summary: Gets Traditional authorities tags: - - Districts + - Traditional Authority + /TraditionalAuthorities/Search/{search}: + get: + consumes: + - application/json + description: Searches though Traditional Authority records + parameters: + - description: Traditional Authority + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.District' + summary: Searches Traditional authorities + tags: + - Traditional Authority + /Villages: + get: + consumes: + - application/json + description: Gets all the villages + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Gets all the country villages + tags: + - villages + /Villages/District/{search}: + get: + consumes: + - application/json + description: Gets all the villages in district + parameters: + - description: District + in: path + name: district + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Gets all the country villages in a district + tags: + - villages + /Villages/Search/{search}: + get: + consumes: + - application/json + description: Gets all the villages in district + parameters: + - description: village + in: path + name: village + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Village' + summary: Searches village name + tags: + - villages + /Wards: + get: + consumes: + - application/json + description: Gets all Ward records + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all Wards + tags: + - Wards + /Wards/District/{search}: + get: + consumes: + - application/json + description: Gets all wards by district name + parameters: + - description: District name + in: path + name: search + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Searches wards by district + tags: + - Wards + /Wards/Region/Central: + get: + consumes: + - application/json + description: Gets all central region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the Central region + tags: + - Wards + /Wards/Region/Northern: + get: + consumes: + - application/json + description: Gets all northern region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the northern region + tags: + - Wards + /Wards/Region/Southern: + get: + consumes: + - application/json + description: Gets all southern region wards + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/structs.Ward' + summary: Gets all wards in the southern region + tags: + - Wards swagger: "2.0" diff --git a/src/controller/constituency.go b/src/controller/constituency.go index 8833342..e8cd576 100644 --- a/src/controller/constituency.go +++ b/src/controller/constituency.go @@ -1,9 +1,8 @@ -package routes +package controller import ( "fmt" "net/http" - "strings" "malawi-country-data/src/structs" @@ -13,8 +12,14 @@ import ( var constituency []structs.Constituency var getconstituency structs.Constituency - // Gets all the country constituencies +// @Summary Gets all the country constituencies +// @Description Gets all the constituencies +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies [get] func GetConstituencies(client *gin.Context) { query = `SELECT c.id, c.name, d.name FROM constituencies c @@ -45,38 +50,88 @@ func GetConstituencies(client *gin.Context) { client.IndentedJSON(http.StatusOK, constituency) } -// Gets all the constituencies in a region -func GetConstituenciesWithRegion(client *gin.Context) { - region := strings.ToLower(client.Param("region")) - - var data []structs.Constituency - var err error - switch region { - case "central": - data, err = getConstituencyByRegion("central") - case "northern": - data, err = getConstituencyByRegion("northern") - case "southern": - data, err = getConstituencyByRegion("southern") - default: - client.JSON(http.StatusBadRequest, structs.BadRequestProblemDetail("Unknown region name.")) +// Gets all the constituencies in the northern region +// @Summary Gets all northern region constituencies +// @Description Gets all the constituencies in the northern region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Northern [get] +func GetNorthernConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("northern") + if err != nil { + client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) return } + client.IndentedJSON(http.StatusOK, data) +} +// Gets all the constituencies in the southern region +// @Summary Gets all southern region constituencies +// @Description Gets all the constituencies in the southern region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Southern [get] +func GetSouthernConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("southern") if err != nil { client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) return } + client.IndentedJSON(http.StatusOK, data) +} +// Gets all the constituencies in the Central region +// @Summary Gets all Central region constituencies +// @Description Gets all the constituencies in the Central region +// @Tags Constituencies +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Constituency{} +// @Router /Constituencies/Region/Central [get] +func GetCentralConstituencies(client *gin.Context) { + data, err := getConstituencyByRegion("central") + if err != nil { + client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) + return + } client.IndentedJSON(http.StatusOK, data) } +// func GetConstituenciesWithRegion(client *gin.Context) { +// region := strings.ToLower(client.Param("region")) + +// var data []structs.Constituency +// var err error +// switch region { +// case "central": +// data, err = getConstituencyByRegion("central") +// case "northern": +// data, err = getConstituencyByRegion("northern") +// case "southern": +// data, err = getConstituencyByRegion("southern") +// default: +// client.JSON(http.StatusBadRequest, structs.BadRequestProblemDetail("Unknown region name.")) +// return +// } + +// if err != nil { +// client.JSON(http.StatusInternalServerError, structs.BadRequestProblemDetail(err.Error())) +// return +// } + +// client.IndentedJSON(http.StatusOK, data) +// } + func getConstituencyByRegion(region string) ([]structs.Constituency, error) { query = fmt.Sprintf(`SELECT c.id, c.name, d.name FROM constituencies c JOIN districts d ON d.id = c.district_id WHERE d.region ILIKE '%s'`, region) - + rows, err := db.Query(query) if err != nil { return nil, err diff --git a/src/controller/disctricts.go b/src/controller/disctricts.go index b6e4a98..3d0f7d0 100644 --- a/src/controller/disctricts.go +++ b/src/controller/disctricts.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -14,8 +14,8 @@ import ( var query string // Gets all the country districts -// @Summary Get all districts -// @Description Get user details by their ID +// @Summary Gets all districts +// @Description Gets all districts with their related information // @Tags Districts // @Accept json // @Produce application/json @@ -71,7 +71,7 @@ func GetDistricts(client *gin.Context) { // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /District/Region/{region} [get] +// @Router /Districts/Region/{region} [get] func GetDistrictByRegion(client *gin.Context) { region := client.Param("region") @@ -154,7 +154,7 @@ func districtsappend(region string) ([]structs.District, error) { // @Accept json // @Produce application/json // @Success 200 {object} structs.District{} -// @Router /District/Search/{search} [get] +// @Router /Districts/Search/{search} [get] func Search(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT diff --git a/src/controller/residential_area.go b/src/controller/residential_area.go index b1552dd..be18527 100644 --- a/src/controller/residential_area.go +++ b/src/controller/residential_area.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -12,6 +12,14 @@ import ( var residential_areas []structs.ResidentialArea +// @Summary Searches for Residential Areas +// @Description Searches though Residential Area records +// @Tags Residential Area +// @Param search path string true "Residential Area" +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.ResidentialArea{} +// @Router /ResidentialAreas/Search/{search} [get] func SearchResidentialArea(client *gin.Context){ search := client.Param("search") query = fmt.Sprintf(`SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district @@ -20,6 +28,13 @@ func SearchResidentialArea(client *gin.Context){ getResidentialArea(client,query) } +// @Summary Gets all Residential Areas +// @Description Gets all Residential Area records +// @Tags Residential Area +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.ResidentialArea{} +// @Router /ResidentialAreas [get] func GetResidentialAreas(client *gin.Context){ query := `SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district FROM districts d, residential_areas r diff --git a/src/controller/routes.go b/src/controller/routes.go index f07161d..aeb45a1 100644 --- a/src/controller/routes.go +++ b/src/controller/routes.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "database/sql" diff --git a/src/controller/traditional_authority.go b/src/controller/traditional_authority.go index 8e577f2..df85eb5 100644 --- a/src/controller/traditional_authority.go +++ b/src/controller/traditional_authority.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "encoding/json" @@ -12,7 +12,13 @@ import ( var traditionalauthority []structs.District - +// @Summary Gets Traditional authorities +// @Description Gets all Traditional Authority records +// @Tags Traditional Authority +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /TraditionalAuthorities [get] func GetTraditionalAuthorities(client *gin.Context) { query = `SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'traditional_authorities', (SELECT json_agg(ta.name) FROM traditional_authorities ta WHERE ta.district_id = d.id)) as district FROM districts d @@ -20,6 +26,14 @@ func GetTraditionalAuthorities(client *gin.Context) { getData(client, query) } +// @Summary Searches Traditional authorities +// @Description Searches though Traditional Authority records +// @Tags Traditional Authority +// @Param search path string true "Traditional Authority" +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.District{} +// @Router /TraditionalAuthorities/Search/{search} [get] func SearchTraditionalAuthorities(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'traditional_authorities', (SELECT json_agg(ta.name) FROM traditional_authorities ta WHERE ta.district_id = d.id)) as district diff --git a/src/controller/village.go b/src/controller/village.go index 63e9d60..72b8912 100644 --- a/src/controller/village.go +++ b/src/controller/village.go @@ -1,4 +1,4 @@ -package routes +package controller import ( "fmt" @@ -11,23 +11,58 @@ import ( var village []structs.Village +// Gets all the country villages +// @Summary Gets all the country villages +// @Description Gets all the villages +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages [get] func GetVillages(client *gin.Context) { query = `SELECT v.id, v.village_name, d.name FROM villages v JOIN districts d ON d.id = v.district_id` - SearchVillage(client, query) + _search(client, query) } +// Gets all the villages in a district +// @Summary Gets all the country villages in a district +// @Description Gets all the villages in district +// @Param district path string true "District" +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages/District/{search} [get] func SearchVillageWithDistrict(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`SELECT v.id, v.village_name, d.name FROM villages v JOIN districts d ON d.id = v.district_id - WHERE d.name ilike '%s'`, search) - SearchVillage(client, query) + WHERE d.name ilike '%%%s%%'`, search) + _search(client, query) } -func SearchVillage(client *gin.Context, query string) { +// Searches for the villages +// @Summary Searches village name +// @Description Gets all the villages in district +// @Param village path string true "village" +// @Tags villages +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Village{} +// @Router /Villages/Search/{search} [get] +func VillageSearch(client *gin.Context){ + search := client.Param("search") + query = fmt.Sprintf( `SELECT v.id, v.village_name, d.name + FROM villages v + JOIN districts d ON d.id = v.district_id + WHERE v.name ilike '%%%s%%'`,search) + _search(client, query) +} + +func _search(client *gin.Context, query string) { rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/src/controller/ward.go b/src/controller/ward.go index 041c4e2..4a6ca8a 100644 --- a/src/controller/ward.go +++ b/src/controller/ward.go @@ -1,34 +1,82 @@ -package routes +package controller import ( "encoding/json" "fmt" - "net/http" "malawi-country-data/src/structs" + "net/http" + "github.com/gin-gonic/gin" ) var wards []structs.Ward -func GetWards(client *gin.Context){ +// @Summary Gets all Wards +// @Description Gets all Ward records +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards [get] +func GetWards(client *gin.Context) { query := `SELECT json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) AS district FROM districts d INNER JOIN constituencies c ON c.district_id = d.id` - SearchWard(client,query) + SearchWard(client, query) } -func SearchWardWithRegion(client *gin.Context){ - search := client.Param("search") +// @Summary Gets all wards in the northern region +// @Description Gets all northern region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Northern [get] +func NorthernRegionWards(client *gin.Context) { + SearchWardWithRegion("Northern", client) +} + +// @Summary Gets all wards in the southern region +// @Description Gets all southern region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Southern [get] +func SouthernRegionWards(client *gin.Context) { + SearchWardWithRegion("Southern", client) +} + +// @Summary Gets all wards in the Central region +// @Description Gets all central region wards +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/Region/Central [get] +func CentralRegionWards(client *gin.Context) { + SearchWardWithRegion("Central", client) +} + +func SearchWardWithRegion(Region string, client *gin.Context) { query := fmt.Sprintf(`SELECT json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) as district FROM districts d JOIN constituencies c ON c.district_id = d.id - WHERE d.region ILIKE '%s'`, search) - SearchWard(client,query) + WHERE d.region ILIKE '%s'`, Region) + SearchWard(client, query) } -func SearchWardWithDistrict(client *gin.Context){ +// @Summary Searches wards by district +// @Description Gets all wards by district name +// @Param search path string true "District name" +// @Tags Wards +// @Accept json +// @Produce application/json +// @Success 200 {object} structs.Ward{} +// @Router /Wards/District/{search} [get] +func SearchWardWithDistrict(client *gin.Context) { search := client.Param("search") query = fmt.Sprintf(`select json_build_object( 'id', d.id, @@ -47,12 +95,12 @@ func SearchWardWithDistrict(client *gin.Context){ WHERE c.district_id=d.id AND d.name ILIKE '%s' - `,search) - SearchWard(client,query) + `, search) + SearchWard(client, query) } func SearchWard(client *gin.Context, query string) { - + rows, err := db.Query(query) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) diff --git a/src/router/router.go b/src/router/router.go index ed4ca0b..8557317 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -24,31 +24,37 @@ func Route() { // Documentation router.GET("/docs/*any",ginSwagger.WrapHandler(swaggerFiles.Handler)) - //District routes - router.GET("/api/Districts", routes.GetDistricts) - router.GET("/api/District/Region/:region", routes.GetDistrictByRegion) - router.GET("/api/District/Search/:search", routes.Search) + //District controller + router.GET("/api/Districts", controller.GetDistricts) + router.GET("/api/Districts/Region/:region", controller.GetDistrictByRegion) + router.GET("/api/Districts/Search/:search", controller.Search) - //Constituency routes - router.GET("/api/Constituencies", routes.GetConstituencies) - router.GET("/api/Constituency/Region/:region", routes.GetConstituenciesWithRegion) + //Constituency controller + router.GET("/api/Constituencies", controller.GetConstituencies) + router.GET("/api/Constituencies/Region/Northern", controller.GetNorthernConstituencies) + router.GET("/api/Constituencies/Region/Southern", controller.GetSouthernConstituencies) + router.GET("/api/Constituencies/Region/Central", controller.GetCentralConstituencies) + // router.GET("/api/Constituencies/Region/:region", controller.GetConstituenciesWithRegion) - //Village routes - router.GET("/api/Villages", routes.GetVillages) - router.GET("/api/Village/District/:search", routes.SearchVillageWithDistrict) + //Village controller + router.GET("/api/Villages", controller.GetVillages) + router.GET("/api/Villages/Search/:search", controller.GetVillages) + router.GET("/api/Villages/District/:search", controller.SearchVillageWithDistrict) - //Traditional Authority Routes - router.GET("/api/TraditionalAuthorities", routes.GetTraditionalAuthorities) - router.GET("/api/TraditionalAuthority/:search", routes.SearchTraditionalAuthorities) + //Traditional Authority controller + router.GET("/api/TraditionalAuthorities", controller.GetTraditionalAuthorities) + router.GET("/api/TraditionalAuthorities/Search/:search", controller.SearchTraditionalAuthorities) - // Residential Areas Routes - router.GET("/api/ResidentialAreas", routes.GetResidentialAreas) - router.GET("/api/ResidentialArea/:search", routes.SearchResidentialArea) + // Residential Areas controller + router.GET("/api/ResidentialAreas", controller.GetResidentialAreas) + router.GET("/api/ResidentialAreas/Search/:search", controller.SearchResidentialArea) - //Wards Routes - router.GET("/api/Wards", routes.GetWards) - router.GET("/api/Wards/Region/:search", routes.SearchWardWithRegion) - router.GET("/api/Wards/District/:search", routes.SearchWardWithDistrict) + //Wards controller + router.GET("/api/Wards", controller.GetWards) + router.GET("/api/Wards/Region/Northern", controller.NorthernRegionWards) + router.GET("/api/Wards/Region/Central", controller.CentralRegionWards) + router.GET("/api/Wards/Region/Southern", controller.SouthernRegionWards) + router.GET("/api/Wards/District/:search", controller.SearchWardWithDistrict) // Healthcheck endpoint router.GET("/HealthCheck", func(c *gin.Context) { From a13f8164afe262fa385fe98962f07bdf7222db50 Mon Sep 17 00:00:00 2001 From: PreciousNyasulu Date: Wed, 6 Sep 2023 21:24:29 +0200 Subject: [PATCH 9/9] refactor models added pgsql data file added docker compose file --- data/data.sql | 605 +++++++++++++++++++++++++++++ docker-compose.yml | 19 + docs/docs.go | 21 +- docs/swagger.json | 21 +- docs/swagger.yaml | 15 +- src/controller/residential_area.go | 8 +- src/controller/village.go | 14 +- src/controller/ward.go | 4 +- src/structs/structs.go | 25 +- 9 files changed, 689 insertions(+), 43 deletions(-) create mode 100644 data/data.sql create mode 100644 docker-compose.yml diff --git a/data/data.sql b/data/data.sql new file mode 100644 index 0000000..dd28f16 --- /dev/null +++ b/data/data.sql @@ -0,0 +1,605 @@ +-- public.constituencies definition + +-- Drop table + +-- DROP TABLE public.constituencies; + +CREATE TABLE public.constituencies ( + id int4 NOT NULL, + "name" varchar NULL, + district_id int4 NOT NULL, + created_at timestamp NULL, + updated_at timestamp NULL, + CONSTRAINT constituencies_pk PRIMARY KEY (id) +); + + +-- public.districts definition + +-- Drop table + +-- DROP TABLE public.districts; + +CREATE TABLE public.districts ( + id int4 NOT NULL, + "name" varchar NULL, + code varchar NULL, + region varchar NULL, + created_at timestamp NULL, + updated_at timestamp NULL, + CONSTRAINT districts_pk PRIMARY KEY (id) +); + + +-- public.residential_areas definition + +-- Drop table + +-- DROP TABLE public.residential_areas; + +CREATE TABLE public.residential_areas ( + id int4 NOT NULL, + district_id int4 NULL, + "name" varchar NULL, + created_at timestamp NULL, + updated_at timestamp NULL, + CONSTRAINT residential_areas_pk PRIMARY KEY (id) +); + + +-- public.traditional_authorities definition + +-- Drop table + +-- DROP TABLE public.traditional_authorities; + +CREATE TABLE public.traditional_authorities ( + id int4 NOT NULL, + "name" varchar NULL, + district_id int4 NULL, + created_at timestamp NULL, + updated_at timestamp NULL, + CONSTRAINT traditional_authorities_pk PRIMARY KEY (id) +); + + +-- public.villages definition + +-- Drop table + +-- DROP TABLE public.villages; + +CREATE TABLE public.villages ( + id int4 NOT NULL, + village_name varchar NULL, + district_id int4 NULL, + CONSTRAINT villages_pk PRIMARY KEY (id) +); + + +-- public.wards definition + +-- Drop table + +-- DROP TABLE public.wards; + +CREATE TABLE public.wards ( + id int4 NOT NULL, + "name" varchar NULL, + constituency_id int4 NULL, + created_at timestamp NULL, + updated_at timestamp NULL, + CONSTRAINT wards_pk PRIMARY KEY (id) +); + +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (1,'Iponjola',1,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (2,'Kapoka',1,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (3,'Mahowe',2,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (4,'Nthalire',2,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (5,'Zambwe',3,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (6,'Yamba',3,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (7,'Nkhangwa',4,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (8,'Hanga',4,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (9,'Chisenga',5,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (10,'Wenya',5,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (11,'Songwe',6,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (12,'Kaporo',6,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (13,'Chilanga',7,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (14,'Rukuru',7,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (15,'Lupembe',8,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (16,'Mlale',8,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (17,'Nyungwe',9,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (18,'Zgeba',9,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (19,'Khwawa',10,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (20,'Uliwa',10,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (21,'Tcharo',11,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (22,'Mchenga',11,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (23,'Chinyolo/Mphompha',12,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (24,'Mayembe',12,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (25,'Hewe - Mwazisi',13,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (26,'Nkhamanga',13,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (27,'Henga-Phoka',14,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (28,'Phoka',14,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (29,'Usisya',15,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (30,'Chikwina',15,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (31,'Boma',16,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (32,'Kandoli',16,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (33,'Chitheka',17,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (34,'Tchesamu',17,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (35,'Kavuzi',18,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (36,'Mpamba',18,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (37,'Sanga',19,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (38,'Chintheche',19,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (39,'Tukombo',20,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (40,'Mbamba',20,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (41,'Likoma',21,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (42,'Chizumulu',21,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (43,'Lupaso Nkholongo',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (44,'Chibanja',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (45,'Katawa',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (46,'Mzilawaingwe',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (47,'Mchengautuwa West',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (48,'Chibavi East',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (49,'Jombo/Kaning''ina',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (50,'Zolozolo East',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (51,'Masasa',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (52,'Msongwe',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (53,'Luwinga',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (54,'Chiputula',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (55,'Mchengautuwa West',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (56,'Chibavi West',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (57,'Zolozolo West',22,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (58,'Kasito East',23,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (59,'Kasito West',23,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (60,'Njuyu',24,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (61,'Ekwendeni',24,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (62,'Kafukule',25,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (63,'Emcisweni',25,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (64,'Luviri',26,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (65,'Mabiri',26,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (66,'Euthini',27,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (67,'Mbalachanda',27,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (68,'Bulala',28,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (69,'Mzalangwe',28,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (70,'Mabilabo North',29,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (71,'Mabilabo South',29,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (72,'Manyamula',30,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (73,'Perekezi',30,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (74,'Kampingo Central',31,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (75,'Walula',31,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (76,'Engalaweni',32,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (77,'Kapopo',32,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (78,'Khonsolo North',33,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (79,'Khonsolo South',33,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (80,'Nthembwe',34,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (81,'Lodjwa',34,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (82,'Mpeni',35,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (83,'Mthabua',35,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (84,'Lisasadzi',36,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (85,'Lifupa',36,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (86,'Mpasadzi',37,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (87,'Matenje',37,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (88,'Chigodi',38,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (89,'Rusa',38,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (90,'Mziza',39,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (91,'Chibophi',39,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (92,'Kachokolo',40,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (93,'Kambira',40,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (94,'Chipala',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (95,'Mponda',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (96,'Belere',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (97,'Chankhanga',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (98,'Chimbuna',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (99,'Chitete',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (100,'Chithiba',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (101,'Chithiba',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (102,'Bunda',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (103,'Kapalankhwazi',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (104,'Kasalika',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (105,'Kabvunguti',41,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (106,'Ndonda',42,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (107,'Mbongozi',42,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (108,'Kasitu',43,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (109,'Nkhunga',43,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (110,'Liwaladzi',45,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (111,'Bua',44,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (112,'Mpondagaga',45,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (113,'Boma',45,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (114,'Linga-Sani',46,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (115,'Mpama',46,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (116,'Mtosa',47,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (117,'Kasangadzi',47,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (118,'Katete-Thumba',48,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (119,'Kalira-Masamba',48,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (120,'Bawala',49,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (121,'Masangano',49,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (122,'Kamlenje',50,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (123,'Chimbwadzi',50,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (124,'Langa',51,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (125,'Mtsiro',51,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (126,'Chiwere North',52,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (127,'Chiwere East',52,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (128,'Mukula East',53,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (129,'Mukula West',53,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (130,'Msakambewa East',54,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (131,'Msakambewa West',54,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (132,'Chakhaza South-West',55,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (133,'Chakhaza North-West',55,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (134,'Mponela',56,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (135,'Dzoole North',56,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (136,'Dzoole South',57,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (137,'Kayembe',57,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (138,'Chakhaza North',58,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (139,'Chakhaza South',58,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (140,'Liwadzi',59,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (141,'Lingadzi',59,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (142,'Maganga-Kuluunda',60,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (143,'Kalonga',60,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (144,'Ndindi',61,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (145,'Kambalame',61,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (146,'Kambwiri',62,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (147,'Pemba',62,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (148,'Chitala',63,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (149,'Lipimbi',63,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (150,'Mchemani',64,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (151,'Luweledzi',64,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (152,'Mponda',65,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (153,'Kapiri',65,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (154,'Mikundi',66,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (155,'Msachembe',66,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (156,'Mkoma',67,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (157,'Mtope',67,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (158,'Msitu',68,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (159,'Namnjiwa',68,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (160,'Kalumbe',69,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (161,'Chimimbe',69,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (162,'Mapuyu',70,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (163,'Nyanja',70,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (164,'Kachawa',71,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (165,'Kamanzi',71,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (166,'Demera',72,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (167,'Kalambe',72,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (168,'Mlodzenzi',73,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (169,'Dzanzi',73,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (170,'Nsanjiko',74,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (171,'Ngala',74,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (172,'Njewa',75,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (173,'Nalikule',76,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (174,'Chiwamba',76,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (175,'Nkhoma',77,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (176,'Chilenje',77,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (177,'Mkuza',78,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (178,'Mazengera',78,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (179,'Mtenthera',79,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (180,'Nyanja',79,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (181,'Chowo',80,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (182,'Chitsime',81,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (183,'Mlodza',81,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (184,'Chilobwe',82,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (185,'Nyang''amire',82,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (186,'Mteza',83,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (187,'Milindi',83,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (188,'Chiwenga',84,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (189,'Mthunthumala',84,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (190,'Bunda',85,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (191,'Katope',85,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (192,'Msinja',86,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (193,'Nadzumi',86,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (194,'Malingunde',87,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (195,'Chiputu',87,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (196,'Chisapo I',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (197,'Chisapo II',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (198,'Phwetekere',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (199,'Mbidzi',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (200,'Chigoneka',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (201,'Mtsiliza',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (202,'Mtandire',88,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (203,'Mvunguti',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (204,'M''gona - Chitata',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (205,'Kabwabwa',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (206,'Chimutu',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (207,'Nyama',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (208,'Maria',89,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (209,'Nankhaka',90,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (210,'Lumbadzi',90,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (211,'State House',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (212,'Chilinde I',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (213,'Chilinde II',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (214,'Kaliyeka',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (215,'Tsabango I',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (216,'Tsabango II',91,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (217,'Kawale I',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (218,'Kawale II',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (219,'Ngwenya',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (220,'Biwi',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (221,'Mchesi',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (222,'Sese',92,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (223,'Mayani North',93,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (224,'Mayani South',93,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (225,'Thiwi',94,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (226,'Diamphwe',94,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (227,'Malembo',95,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (228,'Thete',95,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (229,'Katewe',96,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (230,'Magomero',96,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (231,'Golomoti',97,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (232,'Mtakataka',97,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (233,'Bembeke',98,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (234,'Mlunduni',98,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (235,'Msunduzi',99,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (236,'Kambirimbiri',99,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (237,'Mkundi',100,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (238,'Chongoni',100,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (239,'Mphepozinai',101,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (240,'Kandeu',101,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (241,'Kasinje',102,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (242,'Sharpe Valley',102,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (243,'Mwalawoyera',103,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (244,'Bilira',103,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (245,'Dzunje',104,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (246,'Livilidzi',104,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (247,'Likudzi',105,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (248,'Ntonda',105,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (249,'Njolomole',106,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (250,'Lizulu',106,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (251,'Gomani Chikuse',107,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (252,'Tsangano',107,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (253,'Makanjira North',108,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (254,'Makanjira South',108,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (255,'Malindi',109,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (256,'Mikongo',109,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (257,'Maiwa',110,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (258,'Masanje',110,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (259,'Katuli North',111,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (260,'Katuli South',111,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (261,'Nlimba',112,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (262,'Chipunga',112,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (263,'Chilipa',113,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (264,'Katemba-Mtimabi',113,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (265,'Koche',114,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (266,'Thundu',114,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (267,'Mtumbwasi',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (268,'Mwasa',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (269,'Chigawe',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (270,'Chikole',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (271,'Kalungu',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (272,'Mikomwa',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (273,'Nkanamwano',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (274,'Msikisi',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (275,'Msukamwere',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (276,'Ndege',115,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (277,'Nkungulu',116,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (278,'Mpale',116,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (279,'Mvumba',117,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (280,'Malembo',117,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (281,'Monkey Bay',118,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (282,'Nkope',118,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (283,'Namavi',119,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (284,'Mbwazi',119,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (285,'Majuni',120,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (286,'Mandimba',120,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (287,'Shire',121,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (288,'Nkhonde',121,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (289,'Bwaila',122,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (290,'Liwawadzi',122,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (291,'Liviridzi',123,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (292,'Mulunguzi',123,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (293,'Utale',124,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (294,'Chimwalire',124,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (295,'Nyambi',125,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (296,'Mpiri',125,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (297,'Nsanama',126,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (298,'Mbonechera',126,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (299,'Mlomba',127,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (300,'Kanjuli',127,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (301,'Kawinga',128,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (302,'Nkoola',128,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (303,'Mposa',129,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (304,'Chamba',129,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (305,'Chinguni',130,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (306,'Lisanjala',130,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (307,'Chikweo',131,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (308,'Ngokwe',131,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (309,'Naisi',132,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (310,'Songani',132,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (311,'Chikomwe',133,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (312,'Chimwalira',133,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (313,'Linthipe',134,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (314,'Chingale',134,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (315,'Nswaswa',135,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (316,'Namilongo',135,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (317,'Mtungulutsi',136,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (318,'Chisenjere',136,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (319,'Lifani',137,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (320,'Naming''azi',137,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (321,'Chanda',138,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (322,'Ulumba',138,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (323,'Mbindi',139,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (324,'Chiphoola',139,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (325,'Chilwa',140,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (326,'Matiya',140,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (327,'Masongola',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (328,'Chinamwali',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (329,'Chirunga',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (330,'Central',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (331,'Likangala',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (332,'Chambo',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (333,'Sadzi',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (334,'Mbedza',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (335,'Mtiya',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (336,'Mpira',141,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (337,'Mitumbira',142,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (338,'Chikowa',142,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (339,'Mombezi',143,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (340,'Nguludi',143,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (341,'Nangalukutiche',144,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (342,'Ntayamwana',144,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (343,'Mwanje',145,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (344,'Thumbwe',145,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (345,'Mulombozi',146,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (346,'Lirangwe',146,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (347,'Chikwembere',147,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (348,'Linjidzi',147,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (349,'Matindi',148,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (350,'Lunzu',148,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (351,'Chilaweni',149,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (352,'Mudi',149,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (353,'Mpemba',150,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (354,'Soche',150,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (355,'Chilangoma',151,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (356,'Chikowa',151,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (357,'Namalimwe',152,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (358,'Ndirande Matope',152,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (359,'Ndirande Gamulani',153,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (360,'Ndirande Makata',153,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (361,'Nyambadwe',153,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (362,'Soche East',154,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (363,'Soche West',154,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (364,'Green Corner',154,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (365,'Blantyre South',154,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (366,'Naotcha',154,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (367,'Mapanga',155,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (368,'Nkolokoti',155,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (369,'Limbe Central',155,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (370,'Bangwe Nthandizi',156,'2019-02-12 07:06:16','2019-02-12 07:06:16'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (371,'Mzedi',156,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (372,'Bangwe',156,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (373,'Namiyango',157,'2019-02-12 07:06:16','2019-02-12 07:06:16'), + (374,'Chigumula',157,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (375,'Misesa',157,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (376,'Mzamba Nantipwiri',157,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (377,'Makungwa',157,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (378,'Blantyre City Central',158,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (379,'Chilomoni',158,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (380,'Chigwaja',158,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (381,'Mbayani',159,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (382,'Michiru',159,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (383,'South Lunzu',159,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (384,'Khudze',160,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (385,'Mitseche',160,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (386,'Thambani',161,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (387,'Mpandadzi',161,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (388,'Lisungwi',162,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (389,'Ligowe',162,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (390,'Chilimbondo',163,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (391,'Chikonde',163,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (392,'Makungwa',164,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (393,'Mikolongwe',164,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (394,'Masenjere',165,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (395,'Didi',165,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (396,'Khonjeni',166,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (397,'Nchima',166,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (398,'Thekerani',167,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (399,'Mapanga',167,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (400,'Magunda',168,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (401,'Muonekera',168,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (402,'Namadzi',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (403,'Namisonga',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (404,'Sambagaru',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (405,'Lolo',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (406,'Mthundu',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (407,'Luchenza',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (408,'Mapanga',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (409,'Kapiri',169,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (410,'Masambanjati',170,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (411,'Namagazi',170,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (412,'Thava',171,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (413,'Dzimbiri',171,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (414,'Mpasa',172,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (415,'Likulezi',172,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (416,'Machemba',173,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (417,'Migowi',173,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (418,'Khongoloni',174,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (419,'Thundu',174,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (420,'Chiringa',175,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (421,'Sukasanje',175,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (422,'Mauzi',176,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (423,'Swang''oma',176,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (424,'Mimosa',177,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (425,'Milonde',177,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (426,'Chitakale',178,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (427,'Likhubula',178,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (428,'Chisitu',179,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (429,'Ntenjera',179,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (430,'Muloza',180,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (431,'Limbuli',180,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (432,'Msikawanjala',181,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (433,'Mkumbiza',181,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (434,'Mulemba',182,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (435,'Chikuli',182,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (436,'Chole',183,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (437,'Chambe',183,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (438,'Nambilanje',184,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (439,'Namboya',184,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (440,'Mulomba',185,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (441,'Mombezi',185,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (442,'Kawanda',186,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (443,'Nyakamba',186,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (444,'Mikalango',187,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (445,'Alumenda',187,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (446,'Lengwe',188,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (447,'Bwabwali',188,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (448,'Mwamphanzi',189,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (449,'Ndalanda',189,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (450,'Makhwira North',190,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (451,'Makhwira South',190,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (452,'Chibisa',191,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (453,'Chimwanjale',191,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (454,'Nyachilenda',192,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (455,'Matundu',192,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (456,'Dinde',193,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (457,'Chekelere',193,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (458,'Chigumukire',194,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (459,'Misamvu',194,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (460,'Lalanje',195,'2019-02-12 07:06:17','2019-02-12 07:06:17'); +INSERT INTO public.wards (id,name,constituency_id,created_at,updated_at) VALUES + (461,'Mlonda',195,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (462,'Kalulu',196,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (463,'Ruo',196,'2019-02-12 07:06:17','2019-02-12 07:06:17'), + (464,'Area 18',89,'2019-03-17 04:50:57','2019-03-17 04:50:57'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..590880d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + postgres: + image: postgres:latest + container_name: postgres-container + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: country_data + ports: + - "5432:5432" + volumes: + - ./data/data.sql:/docker-entrypoint-initdb.d/data.sql # Mount the SQL dump into the container's init directory + networks: + - postgres-network + +networks: + postgres-network: diff --git a/docs/docs.go b/docs/docs.go index 9ce39b1..8016452 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -558,14 +558,19 @@ const docTemplate = `{ "structs.ResidentialArea": { "type": "object", "properties": { - "code": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" + "district": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } }, "region": { "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index cd52618..db6190a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -551,14 +551,19 @@ "structs.ResidentialArea": { "type": "object", "properties": { - "code": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" + "district": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } }, "region": { "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c38c931..e935a79 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -26,12 +26,15 @@ definitions: type: object structs.ResidentialArea: properties: - code: - type: string - id: - type: integer - name: - type: string + district: + properties: + code: + type: string + id: + type: integer + name: + type: string + type: object region: type: string residential_areas: diff --git a/src/controller/residential_area.go b/src/controller/residential_area.go index be18527..10b34ae 100644 --- a/src/controller/residential_area.go +++ b/src/controller/residential_area.go @@ -22,9 +22,9 @@ var residential_areas []structs.ResidentialArea // @Router /ResidentialAreas/Search/{search} [get] func SearchResidentialArea(client *gin.Context){ search := client.Param("search") - query = fmt.Sprintf(`SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district - FROM districts d, residential_areas r - WHERE r.district_id=d.id AND r.name ILIKE '%s'`,search) + query = fmt.Sprintf(`SELECT json_build_object('district', jsonb_build_object('id', d.id, 'name', d.name, 'code', d.code), 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district + FROM districts d, residential_areas r + WHERE r.district_id=d.id AND r.name ilike '%s'`,search) getResidentialArea(client,query) } @@ -36,7 +36,7 @@ func SearchResidentialArea(client *gin.Context){ // @Success 200 {object} structs.ResidentialArea{} // @Router /ResidentialAreas [get] func GetResidentialAreas(client *gin.Context){ - query := `SELECT json_build_object('id', d.id, 'name', d.name, 'code', d.code, 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district + query := `SELECT json_build_object( 'district', jsonb_build_object('id', d.id, 'name', d.name, 'code', d.code), 'region', d.region, 'residential_areas', (SELECT json_agg(ra.name) FROM residential_areas ra WHERE ra.district_id=d.id)) as district FROM districts d, residential_areas r WHERE r.district_id=d.id` getResidentialArea(client,query) diff --git a/src/controller/village.go b/src/controller/village.go index 72b8912..c4d1708 100644 --- a/src/controller/village.go +++ b/src/controller/village.go @@ -20,7 +20,7 @@ var village []structs.Village // @Success 200 {object} structs.Village{} // @Router /Villages [get] func GetVillages(client *gin.Context) { - query = `SELECT v.id, v.village_name, d.name + query = `SELECT json_build_object('id',v.id, 'name',v.village_name, 'district',json_build_object('id', d.id, 'name', d.name, 'code', d.code ),'region', d.region) FROM villages v JOIN districts d ON d.id = v.district_id` _search(client, query) @@ -37,8 +37,8 @@ func GetVillages(client *gin.Context) { // @Router /Villages/District/{search} [get] func SearchVillageWithDistrict(client *gin.Context) { search := client.Param("search") - query = fmt.Sprintf(`SELECT v.id, v.village_name, d.name - FROM villages v + query = fmt.Sprintf(`SELECT json_build_object('id',v.id, 'name',v.village_name, 'district',json_build_object('id', d.id, 'name', d.name, 'code', d.code ),'region', d.region) + FROM villages v JOIN districts d ON d.id = v.district_id WHERE d.name ilike '%%%s%%'`, search) _search(client, query) @@ -55,9 +55,9 @@ func SearchVillageWithDistrict(client *gin.Context) { // @Router /Villages/Search/{search} [get] func VillageSearch(client *gin.Context){ search := client.Param("search") - query = fmt.Sprintf( `SELECT v.id, v.village_name, d.name - FROM villages v - JOIN districts d ON d.id = v.district_id + query = fmt.Sprintf( `SELECT json_build_object('id',v.id, 'name',v.village_name, 'district',json_build_object('id', d.id, 'name', d.name, 'code', d.code ),'region', d.region) + FROM villages v + JOIN districts d ON d.id = v.district_id WHERE v.name ilike '%%%s%%'`,search) _search(client, query) } @@ -71,7 +71,7 @@ func _search(client *gin.Context, query string) { defer rows.Close() var getvillage structs.Village for rows.Next() { - err = rows.Scan(&getvillage.Id, &getvillage.Village_Name, &getvillage.District) + err = rows.Scan(&getvillage.Id , &getvillage.Name, &getvillage.Region, &getvillage.District) if err != nil { client.JSON(http.StatusInternalServerError, structs.InternalServerProblemDetail(err.Error())) return diff --git a/src/controller/ward.go b/src/controller/ward.go index 4a6ca8a..5ecd238 100644 --- a/src/controller/ward.go +++ b/src/controller/ward.go @@ -20,7 +20,7 @@ var wards []structs.Ward // @Router /Wards [get] func GetWards(client *gin.Context) { query := `SELECT - json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) + json_build_object( 'district', json_build_object('id', d.id, 'name', d.name, 'code', d.code), 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) AS district FROM districts d INNER JOIN constituencies c ON c.district_id = d.id` @@ -61,7 +61,7 @@ func CentralRegionWards(client *gin.Context) { } func SearchWardWithRegion(Region string, client *gin.Context) { - query := fmt.Sprintf(`SELECT json_build_object('id', d.id, 'district_name', d.name, 'district_code', d.code, 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) as district + query := fmt.Sprintf(`SELECT json_build_object('district', json_build_object('id', d.id, 'name', d.name, 'code', d.code), 'region', d.region, 'constituency', c.name, 'wards', (SELECT json_agg(wa.name) FROM wards wa WHERE wa.constituency_id = c.id)) as district FROM districts d JOIN constituencies c ON c.district_id = d.id WHERE d.region ILIKE '%s'`, Region) diff --git a/src/structs/structs.go b/src/structs/structs.go index 40dd48e..d15ae9e 100644 --- a/src/structs/structs.go +++ b/src/structs/structs.go @@ -15,18 +15,22 @@ type Constituency struct { } type Ward struct { - Id int `json:"id"` - District string `json:"district_name"` - Code string `json:"district_code"` + District struct{ + Id int `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + } `json:"district"` Region string `json:"region"` Constituency string `json:"constituency"` Wards []string `json:"wards"` } type ResidentialArea struct { - Id int `json:"id"` - Name string `json:"name"` - Code string `json:"code"` + District struct{ + Id int `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + } `json:"district"` Region string `json:"region"` Residential_Areas []string `json:"residential_areas"` } @@ -39,8 +43,13 @@ type TraditionalAuthority struct { type Village struct { Id int `json:"id"` - Village_Name string `json:"village_name"` - District string `json:"district"` + Name string `json:"name"` + Region string `json:"region"` + District struct { + Id int `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + } `json:"district"` } type ProblemDetail struct {