File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -20,3 +20,27 @@ export DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/postgres
2020./manage.py migrate
2121./manage.py runserver
2222```
23+
24+ ## Usage
25+
26+ ### Adding a TODO item
27+
28+ Using cURL, make a POST request to ` /api/todo/ ` with the two required fields, description & due date:
29+
30+ ``` bash
31+ curl \
32+ --silent \
33+ -X POST \
34+ -d ' {"description": "Make a New Year resolution list", "due_date": "2025-01-01"}' \
35+ -H ' Content-Type: application/json' \
36+ http://localhost:8000/api/todo/
37+ ```
38+
39+ ### Searching for similar TODO items
40+
41+ ``` bash
42+ curl \
43+ --silent \
44+ -H " Content-Type: application/json" \
45+ ' http://localhost:8000/api/todo/search/?q=resolution&limit=1' | jq " .[0].description"
46+ ```
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ def search(self, request):
2020 """
2121 query = request .query_params .get ("q" )
2222 completed = request .query_params .get ("completed" )
23+ limit = request .query_params .get ("limit" )
24+
25+ if limit :
26+ limit = int (limit )
2327
2428 if completed :
2529 completed = completed .lower () == "true"
@@ -38,6 +42,9 @@ def search(self, request):
3842 if completed :
3943 results = results .filter (completed = completed )
4044
45+ if limit :
46+ results = results [:limit ]
47+
4148 # If you want to see the query that is executed, uncomment the following line.
4249 # print(results.query)
4350
You can’t perform that action at this time.
0 commit comments