This repo contains the backend code for Abidria project. This simple app aims to be a reference to discover interesting places and also to record our past experiences, sharing content with other people.
Application domain is composed by scenes
,
which are defined as something that happened
or can be done/seen in a located place.
A group of scenes
are defined as an experience
.
Response:
[
{
"id": "2",
"title": "Baboon",
"description": "Mystical place...",
"picture": {
"small_url": "https://experiences/8c29.small.jpg",
"medium_url": "https://experiences/8c29.medium.jpg",
"large_url": "https://experiences/8c29.large.jpg"
}
},
{
"id": "3",
"title": "Magic Castle of Lost Swamps",
"description": "Don't even try to go there!",
"picture": null
}
]
Request(application/x-www-form-urlencoded):
{
"title": "My travel",
"description": "and other adventures",
}
Response:
201
{
"id": "8",
"title": "My travel",
"description": "and other adventures",
"picture": null,
}
422
{
"error": {
"source": "title",
"code": "empty_attribute",
"message": "Title cannot be empty"
}
}
Request(application/x-www-form-urlencoded):
{
"title": "",
"description": "A new description",
}
It is also allowed to not define some fields (if defined blank value will be set to blank).
Response:
200
{
"id": "8",
"title": "MainSquare",
"description": "A new description",
"picture": null,
}
404
{
"error": {
"source": "entity",
"code": "not_found",
"message": "Entity not found"
}
}
422
{
"error": {
"source": "title",
"code": "wrong_size",
"message": "Title must be between 1 and 30 chars"
}
}
Request(multipart/form-data):
Param name to send the file: picture
Response:
200
{
"id": "8",
"title": "My travel",
"description": "and other adventures",
"picture": {
"small_url": "https://scenes/37d6.small.jpeg",
"medium_url": "https://scenes/37d6.medium.jpeg",
"large_url": "https://scenes/37d6.large.jpeg"
},
}
Response:
[
{
"id": "5",
"title": "Plaça Mundial",
"description": "World wide square!",
"picture": {
"small_url": "https://scenes/37d6.small.jpeg",
"medium_url": "https://scenes/37d6.medium.jpeg",
"large_url": "https://scenes/37d6.large.jpeg"
},
"latitude": 1.000000,
"longitude": 2.000000,
"experience_id": "5"
},
{
"id": "4",
"title": "I've been here",
"description": "",
"picture": null,
"latitude": 0.000000,
"longitude": 1.000000,
"experience_id": "5"
},
]
Request(application/x-www-form-urlencoded):
{
"title": "Plaça Major",
"description": "The main square",
"latitude": 1.2,
"longitude": 0.3,
"experience_id": "3"
}
Response:
201
{
"id": "8",
"title": "Plaça Major",
"description": "The main square",
"picture": null,
"latitude": 1.2,
"longitude": 0.3,
"experience_id": "3"
}
422
{
"error": {
"source": "title",
"code": "empty_attribute",
"message": "Title cannot be empty"
}
}
Request(application/x-www-form-urlencoded):
{
"title": "",
"description": "A new description",
"latitude": -0.3,
"longitude": 0.56,
}
It is also allowed to not define some fields (if defined blank value will be set to blank).
Response:
200
{
"id": "8",
"title": "MainSquare",
"description": "A new description",
"picture": null,
"latitude": 1.2,
"longitude": 0.56,
"experience_id": "3"
}
404
{
"error": {
"source": "entity",
"code": "not_found",
"message": "Entity not found"
}
}
422
{
"error": {
"source": "title",
"code": "wrong_size",
"message": "Title must be between 1 and 30 chars"
}
}
Request(multipart/form-data):
Param name to send the file: picture
Response:
200
{
"id": "8",
"title": "Plaça Major",
"description": "The main square",
"picture": {
"small_url": "https://scenes/37d6.small.jpeg",
"medium_url": "https://scenes/37d6.medium.jpeg",
"large_url": "https://scenes/37d6.large.jpeg"
},
"latitude": 1.2,
"longitude": 0.3,
"experience_id": "3"
}
This project has been developed using Django framework, with Postgres as database and S3 as storage service.
Code structure follows a Clean Architecture approach (explained in detail here), emphasizing on code readability, responsibility decoupling and unit testing.
Follow these instructions to start working locally on the project:
- Download code cloning this repo:
git clone https://github.com/jordifierro/abidria-api.git
- Install postgres and run:
./abidria/setup/postgres.sh
to create user and database.
- Run postgres:
postgres -D /usr/local/var/postgres &
- Install python version specified on
runtime.txt
and run:
virtualenv -p `which python3.6` ../env
- Add this to the end of
../env/bin/activate
file:
source abidria/setup/envvars.sh
- Get into the environment:
source ../env/bin/activate
and install dependencies:
pip install -r requirements.txt
- Migrate database:
python manage.py migrate
- Create django admin super user:
python manage.py createsuperuser
- Finally, you should be able to run unit and integration tests:
pytest # python tests
python manage.py test # django tests
Once we have made the first time setup, we can start everything up running:
source abidria/setup/startup.sh