Skip to content

Live Tanzania ๐Ÿ‡น๐Ÿ‡ฟ locations API ๐Ÿ”ฅ

License

Notifications You must be signed in to change notification settings

HackEAC/locations-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

46 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Location Data API

A RESTful API for Tanzania location data including countries, regions, districts, wards, and places.

Features

  • Hierarchical location data with proper relationships
  • RESTful API with clean structure
  • Input validation and error handling
  • Pagination and search support

Tech Stack

  • Node.js / Express
  • PostgreSQL
  • Prisma ORM
  • Jest & Supertest for testing

Getting Started

Prerequisites

  • Node.js LTS
  • Tanzania Locations Database running ๐Ÿƒ๐Ÿฟโ€โ™‚๏ธ๐Ÿƒ๐Ÿฟโ€โ™€๏ธ
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/locations-API.git
    cd locations-API
  2. Install dependencies

    npm install
  3. Create .env for your environment

    echo DATABASE_URL="postgresql://postgres:password@localhost:5433/locations" > .env

    The above DATABASE_URL is for the Tanzania-locations-database Docker container provision.

  4. Sync up your API with the locations database:

    • a. Pull existing DB schema into your Prisma schema

      pnpx prisma db pull
    • b. Create migration init files

      mkdir prisma/migrations/init
    • c. Mark the current schema as baseline

      pnpx prisma migrate diff \
        --from-empty \
        --to-schema-datamodel prisma/schema.prisma \
        --script > prisma/migrations/init/migration.sql
    • d. Create migration history manually

      pnpx prisma migrate resolve --applied init

    โœ… Now you're synced! Future prisma migrate dev or migrate deploy will work cleanly.

  5. Start development server

    npm run dev
  6. Build application

    npm run build
  7. Start production server

    npm run start

API Endpoints

Countries

  • GET /api/countries - Get all countries
  • GET /api/countries/:id - Get country by ID

Regions

  • GET /api/regions - Get all regions
  • GET /api/regions/:regionCode - Get region by code
  • GET /api/regions/:regionCode/districts - Get districts in a region

Districts

  • GET /api/districts - Get all districts
  • GET /api/districts/:districtCode - Get district by code
  • GET /api/districts/:districtCode/wards - Get wards in a district

Wards

  • GET /api/wards - Get all wards
  • GET /api/wards/:wardCode - Get ward by code
  • GET /api/wards/:wardCode/places - Get places in a ward

Places

  • GET /api/places - Get all places
  • GET /api/places/:id - Get place by ID

Running Tests

npm test

License

This project is licensed under the CopyLeft License โ€“ see the LICENSE file for details.

About

Live Tanzania ๐Ÿ‡น๐Ÿ‡ฟ locations API ๐Ÿ”ฅ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published