Skip to content

Commit 0c9aaa8

Browse files
committed
gavin updatev1
+gavinlowe+gavin mix+gavinUpp
1 parent 9bad5c5 commit 0c9aaa8

8 files changed

Lines changed: 515 additions & 3 deletions

File tree

GitHub.code-workspace

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {}
8+
}
2.13 KB
Binary file not shown.

app copy.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
from flask import Flask, jsonify, request
2+
from flask_restful import Api, Resource
3+
from flasgger import Swagger
4+
5+
import book_review
6+
7+
app = Flask(__name__)
8+
api = Api(app)
9+
swagger = Swagger(app)
10+
11+
class UppercaseText(Resource):
12+
def get(self):
13+
"""
14+
This method responds to the GET request for this endpoint and returns the data in uppercase.
15+
---
16+
tags:
17+
- Text Processing
18+
parameters:
19+
- name: text
20+
in: query
21+
type: string
22+
required: true
23+
description: The text to be converted to uppercase
24+
responses:
25+
200:
26+
description: A successful GET request
27+
content:
28+
application/json:
29+
schema:
30+
type: object
31+
properties:
32+
text:
33+
type: string
34+
description: The text in uppercase
35+
"""
36+
text = request.args.get('text')
37+
38+
return jsonify({"text": text.upper()})
39+
40+
class Records(Resource):
41+
def get(self):
42+
"""
43+
This method responds to the GET request for returning a number of books.
44+
---
45+
tags:
46+
- Records
47+
parameters:
48+
- name: count
49+
in: query
50+
type: integer
51+
required: false
52+
description: The number of books to return
53+
- name: sort
54+
in: query
55+
type: string
56+
enum: ['ASC', 'DESC']
57+
required: false
58+
description: Sort order for the books
59+
responses:
60+
200:
61+
description: A successful GET request
62+
schema:
63+
type: object
64+
properties:
65+
books:
66+
type: array
67+
items:
68+
type: object
69+
properties:
70+
title:
71+
type: string
72+
description: The title of the book
73+
author:
74+
type: string
75+
description: The author of the book
76+
"""
77+
78+
count = request.args.get('count') # Default to returning 10 books if count is not provided
79+
sort = request.args.get('sort')
80+
81+
# Get all the books
82+
books = book_review.get_all_records(count=count, sort=sort)
83+
84+
return {"books": books}, 200
85+
86+
class AddRecord(Resource):
87+
def post(self):
88+
"""
89+
This method responds to the POST request for adding a new record to the DB table.
90+
---
91+
tags:
92+
- Records
93+
parameters:
94+
- in: body
95+
name: body
96+
required: true
97+
schema:
98+
id: BookReview
99+
required:
100+
- Book
101+
- Rating
102+
properties:
103+
Book:
104+
type: string
105+
description: the name of the book
106+
Rating:
107+
type: integer
108+
description: the rating of the book (1-10)
109+
responses:
110+
200:
111+
description: A successful POST request
112+
400:
113+
description: Bad request, missing 'Book' or 'Rating' in the request body
114+
"""
115+
116+
data = request.json
117+
print(data)
118+
119+
# Check if 'Book' and 'Rating' are present in the request body
120+
if 'Book' not in data or 'Rating' not in data:
121+
return {"message": "Bad request, missing 'Book' or 'Rating' in the request body"}, 400
122+
# Call the add_record function to add the record to the DB table
123+
success = book_review.add_record(data)
124+
125+
if success:
126+
return {"message": "Record added successfully"}, 200
127+
else:
128+
return {"message": "Failed to add record"}, 500
129+
130+
131+
132+
133+
api.add_resource(AddRecord, "/add-record")
134+
api.add_resource(Records, "/records")
135+
api.add_resource(UppercaseText, "/uppercase")
136+
137+
138+
if __name__ == "__main__":
139+
app.run(debug=True)

app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get(self):
1414
This method responds to the GET request for this endpoint and returns the data in uppercase.
1515
---
1616
tags:
17-
- Text Processing
17+
- Text Processing
1818
parameters:
1919
- name: text
2020
in: query
@@ -129,9 +129,11 @@ def post(self):
129129

130130

131131

132+
132133
api.add_resource(AddRecord, "/add-record")
133134
api.add_resource(Records, "/records")
134135
api.add_resource(UppercaseText, "/uppercase")
135136

137+
136138
if __name__ == "__main__":
137139
app.run(debug=True)

gavinlowercaser.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from flask import Flask, jsonify, request
2+
from flask_restful import Api, Resource
3+
from flasgger import Swagger
4+
5+
app = Flask(__name__)
6+
api = Api(app)
7+
swagger = Swagger(app)
8+
9+
class GavinLowercaser(Resource):
10+
def get(self):
11+
"""
12+
This method responds to the GET request for this endpoint and returns the data in Lowercase.
13+
---
14+
tags:
15+
- Text Processing
16+
parameters:
17+
- name: text
18+
in: query
19+
type: string
20+
required: true
21+
description: The text to be converted to lowercase
22+
responses:
23+
200:
24+
description: A successful GET request
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
text:
31+
type: string
32+
description: The text in lowercase
33+
"""
34+
text = request.args.get('text')
35+
36+
return {"text": text.lower()}, 200
37+
38+
class ProcessText(Resource):
39+
def get(self):
40+
"""
41+
This method responds to the GET request for processing text and returns the processed text.
42+
---
43+
tags:
44+
- Text Processing
45+
parameters:
46+
- name: text
47+
in: query
48+
type: string
49+
required: true
50+
description: The text to be processed
51+
- name: duplication_factor
52+
in: query
53+
type: integer
54+
required: false
55+
description: The number of times to duplicate the text
56+
- name: capitalization
57+
in: query
58+
type: string
59+
required: false
60+
enum: [UPPER, LOWER, None]
61+
description: The capitalization style for the text
62+
responses:
63+
200:
64+
description: A successful GET request
65+
content:
66+
application/json:
67+
schema:
68+
type: object
69+
properties:
70+
processed_text:
71+
type: string
72+
description: The processed text
73+
"""
74+
text = request.args.get('text')
75+
duplication_factor = int(request.args.get('duplication_factor', 1))
76+
capitalization = request.args.get('capitalization', 'None')
77+
78+
# Validate capitalization input
79+
if capitalization not in ['UPPER', 'LOWER', 'None']:
80+
return {"error": "Invalid capitalization value"}, 400
81+
82+
# Process the text based on duplication_factor and capitalization
83+
if capitalization == 'UPPER':
84+
text = text.upper()
85+
elif capitalization == 'LOWER':
86+
text = text.lower()
87+
88+
processed_text = text * duplication_factor
89+
90+
return {"processed_text": processed_text}, 200
91+
92+
api.add_resource(ProcessText, "/process_text")
93+
api.add_resource(GavinLowercaser, "/lowercase")
94+
95+
if __name__ == "__main__":
96+
app.run(debug=True)

gavinmixcaser.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
from flask import Flask, jsonify, request
2+
from flask_restful import Api, Resource
3+
from flasgger import Swagger
4+
5+
app = Flask(__name__)
6+
api = Api(app)
7+
swagger = Swagger(app)
8+
9+
class GavinMixcaser(Resource):
10+
def get(self):
11+
"""
12+
This method responds to the GET request for this endpoint and returns the data in mixcase.
13+
---
14+
tags:
15+
- Text Processing
16+
parameters:
17+
- name: text
18+
in: query
19+
type: string
20+
required: true
21+
description: The text to be converted to mixcase
22+
responses:
23+
200:
24+
description: A successful GET request
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
text:
31+
type: string
32+
description: The text in mixcase
33+
34+
"""
35+
text = request.args.get('text')
36+
textuppper = text.upper()
37+
textlowwer = text.lower()
38+
textmix = textuppper + textlowwer
39+
return {"text": textmix}, 200
40+
41+
42+
43+
class ProcessText(Resource):
44+
def get(self):
45+
"""
46+
This method responds to the GET request for processing text and returns the processed text.
47+
---
48+
tags:
49+
- Text Processing
50+
parameters:
51+
- name: text
52+
in: query
53+
type: string
54+
required: true
55+
description: The text to be processed
56+
- name: duplication_factor
57+
in: query
58+
type: integer
59+
required: false
60+
description: The number of times to duplicate the text
61+
- name: capitalization
62+
in: query
63+
type: string
64+
required: false
65+
enum: [UPPER, LOWER,MIXED,UPPER LOWER, None]
66+
description: The capitalization style for the text
67+
responses:
68+
200:
69+
description: A successful GET request
70+
content:
71+
application/json:
72+
schema:
73+
type: object
74+
properties:
75+
processed_text:
76+
type: string
77+
description: The processed text
78+
"""
79+
text = request.args.get('text')
80+
duplication_factor = int(request.args.get('duplication_factor', 1))
81+
capitalization = request.args.get('capitalization', 'None')
82+
def mixedtextchecker(){
83+
if text == text.upper(){
84+
text.upper()
85+
}
86+
if text == text.lower(){
87+
text.lower()
88+
}
89+
90+
}
91+
# Validate capitalization input
92+
if capitalization not in ['UPPER', 'LOWER', 'UPPER LOWER', 'MIXED', 'None']:
93+
return {"error": "Invalid capitalization value"}, 400
94+
95+
# Process the text based on duplication_factor and capitalization
96+
if capitalization == 'UPPER':
97+
text = text.upper()
98+
elif capitalization == 'LOWER':
99+
text = text.lower()
100+
elif capitalization == 'MIXED':
101+
mixedtextchecker()
102+
elif capitalization == 'UPPER LOWER':
103+
text = text.lower()
104+
text = text.lower()
105+
mixedtext = text.lower() + " " + text.upper()
106+
107+
processed_text = text * duplication_factor
108+
109+
return {"processed_text": processed_text}, 200
110+
111+
api.add_resource(ProcessText, "/process_text")
112+
api.add_resource(GavinMixcaser, "/mixcase")
113+
114+
if __name__ == "__main__":
115+
app.run(debug=True)
116+
117+

0 commit comments

Comments
 (0)