Pre requisites: Docker Desktop
- Run
docker pull vgarcia13/traffic_tickets:latest - Finally, run
docker run -it -p 8000:8000 vgarcia13/traffic_tickets - Navigate to http://0.0.0.0:8000/api/ to access API root.
Pre requisites: Docker Desktop
- Clone this repository
- Access the repo's root folder
/traffic_tickets - Run
docker build -t traffic_tickets .to build and create the container. - Finally, run
docker run -it -p 8000:8000 traffic_ticketsto run the container. - Navigate to http://0.0.0.0:8000/api/ to access API root.
Pre requisites: Python 3.8+ installed locally
- Clone this repository
- Access the repo's root folder
/traffic_tickets - Run
python3 -m venv venvto create a brand new virtual env, - Run
source venv/bin/activateto activate te virtual env. - Run
pip install -r requirements.txtto install project's dependencies. - Run
python manage.py migrateto apply current model into DB (sqlite) - Finally, run
python manage.py runserver 0.0.0.0:8000to run Django server - Navigate to http://0.0.0.0:8000/api/ to access API root.
- To access administration site, first run
docker container lsand extract theContainer IDrelated totraffic_ticketsimage. - Run
docker exec -it <CONTAINER_ID> python manage.py createsuperuserand type a username and password. - Navigate to http://0.0.0.0:8000/admin/ with the credentials created.
- To access administration site, run
python manage.py createsuperuser(withvenvactivated) and type a username and password. - Navigate to http://0.0.0.0:8000/admin/ with the credentials created.
- Within the admin site, click
"Add"button right after"Persons" - You need to create a
Userinstance first (used for access token generation), click the"+"button in the"User"row and type the email of thePersonto create in theUsernamefield, nothing else is required here. - After the
Usercreation, type thePersonemail (used in the last step) and the full name, and click "Save"
Person instance is the base model for Officer and Vehicle creation.
- Within the admin site, click
"Add"button right after"Token" - Select the related
User - Click
"Save"
The generated token is the access token related to the Person related to the selected User
- Within the admin site, click
"Add"button right after"Officer" - Select the
Personrelated to theOfficerto be created. - Click
"Save"
- Within the admin site, click
"Add"button right after"Vehicle" - Select the
Personrelated to theVehicleto be created and fill all the other values. - Click
"Save"
- Within the admin site, click
"Add"button right after"Ticket" - Select the
Vehiclerelated to theTicketto be created and theOfficerthat is creating the ticket.Notesfield is optional. - Click
"Save"
NOTE: This process is not intended to be done in the admin site, there is an endpoint available for this.
CRUD operations are fully supported.
- Navigate to http://0.0.0.0:8000/api/ with the credentials created.
- All CRUD operations in all the instances described above are supported here.
NOTE: Processes have been simplified in the API instance for a more intuitive use.
EX: When creating a Person within the API instance, a Token is created automatically.
Forms are rendered to create new records and accessing elements using GET with the unique record UUID,
PUT, PATCH and DELETE operations are supported.
EX:
http://0.0.0.0:8000/api/persons/<PERSON_UUID>/
http://0.0.0.0:8000/api/vehicles/<VEHICLE_UUID>/
http://0.0.0.0:8000/api/officers/<OFFICER_UUID>/
http://0.0.0.0:8000/api/tickets/<TICKET_UUID>/
- For creating a ticket, a
POSTrequest needs to be done to http://0.0.0.0:8000/api/tickets using abodylike this:
{
"plate": "<VEHICLE_PLATE>,
"notes": "<NOTES>
}
This request needs to be done with an Authorization header, like:
Authorization: Token <PERSON_ACCESS_TOKEN>
- If the plate is not found, a 404 status will be returned.
- If the access_token is not found or is invalid, a 401 status will be returned.
- The ticket's
timestampis saved by default usingdatetime.now()
- For generating an inform (a JSON with the tickets related to a specific
Person), aGETrequest needs to be done to http://0.0.0.0:8000/api/generate_inform using aquery_paramlike this:
http://0.0.0.0:8000/api/generate_inform/?email=<PERSON_EMAIL>
This request don't need authorization.