Skip to content

Commit 7ae9eb9

Browse files
committed
Fixed doc strings return formatting a bit. Figured out how to properly use docstrings
1 parent 19876d4 commit 7ae9eb9

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

app.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,20 @@ def get(self):
6161
responses:
6262
200:
6363
description: A successful GET request
64-
content:
65-
application/json:
66-
schema:
67-
type: object
68-
properties:
69-
books:
70-
type: array
71-
items:
72-
type: object
73-
properties:
74-
title:
75-
type: string
76-
description: The title of the book
77-
author:
78-
type: string
79-
description: The author of the book
64+
schema:
65+
type: object
66+
properties:
67+
books:
68+
type: array
69+
items:
70+
type: object
71+
properties:
72+
title:
73+
type: string
74+
description: The title of the book
75+
author:
76+
type: string
77+
description: The author of the book
8078
"""
8179

8280
count = request.args.get('count') # Default to returning 10 books if count is not provided
@@ -85,7 +83,7 @@ def get(self):
8583
# Get all the books
8684
books = book_review.get_all_records(count=count, sort=sort)
8785

88-
return jsonify({"books": books})
86+
return {"books": books}, 200
8987

9088
class AddRecord(Resource):
9189

@@ -114,28 +112,23 @@ def post(self):
114112
responses:
115113
200:
116114
description: A successful POST request
117-
content:
118-
application/json:
119-
schema:
120-
type: object
121-
properties:
122-
message:
123-
type: string
115+
400:
116+
description: Bad request, missing 'Book' or 'Rating' in the request body
124117
"""
125118

126119
data = request.json
127120
print(data)
128121

129122
# Check if 'Book' and 'Rating' are present in the request body
130123
if 'Book' not in data or 'Rating' not in data:
131-
return jsonify({"message": "Bad request, missing 'Book' or 'Rating' in the request body"})
124+
return {"message": "Bad request, missing 'Book' or 'Rating' in the request body"}, 400
132125
# Call the add_record function to add the record to the DB table
133126
success = book_review.add_record(data)
134127

135128
if success:
136-
return jsonify({"message": "Record added successfully"})
129+
return {"message": "Record added successfully"}, 200
137130
else:
138-
return jsonify({"message": "Failed to add record"})
131+
return {"message": "Failed to add record"}, 500
139132

140133

141134

0 commit comments

Comments
 (0)