Hello. This project serves as a mini Wikipedia. This application provides the features to Create, Read, Update & Delete [CRUD] on continents, countries and cities data.
Three models are required to build this application. Those are:
1. Continents
id(pk), name, population, area_in_sq_meters, created_at, updated_at
2. Countries
id(pk), name, population, area_in_sq_meters, number_of_hospitals,number_national_parks,continent_id(fk), created_at, updated_at
3. Cities
id(pk), name, population, area, number_of_roads, number_of_trees, country_id(fk), created_at, updated_at
Established a relation between Continents
to Countries
is one to many (1 -> M)
and Countries
to Cities
is One to Many (1 -> M).
Implemented Cascade delete for the models. ie., if parent record deletes then it's corresponding child records get deleted.
-
GET /api/wiki/continents HTTP/1.1
- Retrieves all the continents data from Continents model.
-
GET /api/wiki/continents/1 HTTP/1.1
- Retrieves specific continent ID (ex: 1) data from Continents models, also provides
hyperlink
to it's countries.
- Retrieves specific continent ID (ex: 1) data from Continents models, also provides
-
POST /api/wiki/continents HTTP/1.1
- Adds a new continent by providing mandatory fields -
name, population and area.
It updatescreated_at
field whenever new continent added. - all these fields mandatory as this data is required for Country level validation(Area & Population)
- Adds a new continent by providing mandatory fields -
-
PUT /api/wiki/continents/1 HTTP/1.1
- Updates a specific continent data. It updates
updated_at
field whenever any updates applied on existing data.
- Updates a specific continent data. It updates
-
DELETE /api/wiki/continents/1 HTTP/1.1
- Deletes a specific continent (ex: 1) from
Continents
model. Also deletes it's corresponding countries and cities.
- Deletes a specific continent (ex: 1) from
-
GET /api/wiki/continents/1/countries HTTP/1.1
- Retrieves all the countries data corresponds to continent 1.
-
GET /api/wiki/continents/1/countries/1 HTTP/1.1
- Retrieves specific country (ex: 1) data from Continent(1), also provides
hyperlink
to it's cities.
- Retrieves specific country (ex: 1) data from Continent(1), also provides
-
POST /api/wiki/continents/1/countries HTTP/1.1
- Adds a new country. Client should provide mandatory fields -
name, population and area.
It updatescreated_at
field whenever new country added. - Above 3 fields are mandatory as this data is required for City level validation (Area & Population)
- Adds a new country. Client should provide mandatory fields -
-
PUT /api/wiki/continents/1/countries/1 HTTP/1.1
- Updates a specific country(ID: 1) data under continent (1). It updates
updated_at
field whenever any updates applied on existing data.
- Updates a specific country(ID: 1) data under continent (1). It updates
-
DELETE /api/wiki/continents/1/countries/1 HTTP/1.1
- Deletes a specific country(ID: 1) from it's
Continents
. Also deletes it's corresponding cities.
- Deletes a specific country(ID: 1) from it's
-
GET /api/wiki/continents/1/countries/1/cities HTTP/1.1
- Retrieves all the cities data corresponds to country (ID: 1).
-
GET /api/wiki/continents/1/countries/1/cities/1 HTTP/1.1
- Retrieves specific city(ID: 1) data from Country(ID:1).
-
POST /api/wiki/continents/1/countries/1/cities HTTP/1.1
- Adds a new City. Client should provide mandatory fields -
name, population and area.
It updatescreated_at
field whenever new city added. - Above 3 fields are mandatory as this data is required for City level validation.
- Adds a new City. Client should provide mandatory fields -
-
PUT /api/wiki/continents/1/countries/1/cities/1 HTTP/1.1
- Updates a specific city(ID: 1) data under country (1). It updates
updated_at
field whenever any updates applied on existing data.
- Updates a specific city(ID: 1) data under country (1). It updates
-
DELETE /api/wiki/continents/1/countries/1/cities/1 HTTP/1.1
- Deletes a specifi city (ID: 1) from it's
Country.
- Deletes a specifi city (ID: 1) from it's
- Name, Population and Area fields are mandatory in data level validations.
- If parent gets deleted then it's corresponding children should be deleted (Cascade delete).
- Continent population and area should be
>=
all it's cities population and area respectively. - Country population and area should be
>
all it's cities population and area respectively.
-
Clone repo
$ git clone https://github.com/ravinderreddy-p/fabio-tests-nisargatman.git $ cd fabio-tests-nisargatman
-
Activate a virtual environment
$ source env/bin/activate
-
Install the dependencies:
$ pip install -r requirements.txt
-
Run the development server:
$ python main.py
-
Navigate to http://localhost:5000/api/wiki/continents