diff --git a/main_template.py b/main_template.py index 2b15666..9e910b4 100644 --- a/main_template.py +++ b/main_template.py @@ -7,7 +7,6 @@ swagger = Swagger(app) class UppercaseText(Resource): - def get(self): """ This method responds to the GET request for this endpoint and returns the data in uppercase. @@ -34,8 +33,63 @@ def get(self): """ text = request.args.get('text') - return jsonify({"text": text.upper()}) + return {"text": text.upper()}, 200 + +class ProcessText(Resource): + def get(self): + """ + This method responds to the GET request for processing text and returns the processed text. + --- + tags: + - Text Processing + parameters: + - name: text + in: query + type: string + required: true + description: The text to be processed + - name: duplication_factor + in: query + type: integer + required: false + description: The number of times to duplicate the text + - name: capitalization + in: query + type: string + required: false + enum: [UPPER, LOWER, None] + description: The capitalization style for the text + responses: + 200: + description: A successful GET request + content: + application/json: + schema: + type: object + properties: + processed_text: + type: string + description: The processed text + """ + text = request.args.get('text') + duplication_factor = int(request.args.get('duplication_factor', 1)) + capitalization = request.args.get('capitalization', 'None') + + # Validate capitalization input + if capitalization not in ['UPPER', 'LOWER', 'None']: + return {"error": "Invalid capitalization value"}, 400 + + # Process the text based on duplication_factor and capitalization + if capitalization == 'UPPER': + text = text.upper() + elif capitalization == 'LOWER': + text = text.lower() + + processed_text = text * duplication_factor + + return {"processed_text": processed_text}, 200 +api.add_resource(ProcessText, "/process_text") api.add_resource(UppercaseText, "/uppercase") if __name__ == "__main__":