File tree 2 files changed +31
-0
lines changed
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:
[email protected] :5432/postgres
20
20
./manage.py migrate
21
21
./manage.py runserver
22
22
```
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):
20
20
"""
21
21
query = request .query_params .get ("q" )
22
22
completed = request .query_params .get ("completed" )
23
+ limit = request .query_params .get ("limit" )
24
+
25
+ if limit :
26
+ limit = int (limit )
23
27
24
28
if completed :
25
29
completed = completed .lower () == "true"
@@ -38,6 +42,9 @@ def search(self, request):
38
42
if completed :
39
43
results = results .filter (completed = completed )
40
44
45
+ if limit :
46
+ results = results [:limit ]
47
+
41
48
# If you want to see the query that is executed, uncomment the following line.
42
49
# print(results.query)
43
50
You can’t perform that action at this time.
0 commit comments