-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement Swagger documentation for main.py
- Loading branch information
IshayuR
committed
Nov 6, 2024
1 parent
2c834cc
commit 8d29d0c
Showing
3 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,106 @@ | ||
""" | ||
This module provides functions for HTTP communication and | ||
route functions | ||
This module provides functions for HTTP communication and route functions. | ||
""" | ||
from flask import Flask, request, jsonify | ||
from flasgger import Swagger | ||
from petfuc import get_random_pet | ||
from userfuc import add_user_faviorte, remove_user_faviorte, replace_user_location | ||
|
||
app = Flask(__name__) | ||
Swagger(app) # Initialize Swagger | ||
|
||
#Get Random Pet information - For homepage | ||
# Get Random Pet information - For homepage | ||
@app.route("/Get_Random_pet", methods=["GET"]) | ||
def random_pet(): | ||
""" | ||
Function to extract random pet information | ||
Retrieve a random pet's information for the homepage. | ||
--- | ||
responses: | ||
200: | ||
description: Returns random pet information successfully. | ||
schema: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
example: 'Rex' | ||
breed: | ||
type: string | ||
example: 'Dog' | ||
age: | ||
type: integer | ||
example: 5 | ||
""" | ||
return get_random_pet(), 200 # Return dog information | ||
return get_random_pet(), 200 | ||
|
||
# Faviortes route. add user faviorte pet to database | ||
# Favorites route. Add user favorite pet to database | ||
@app.route("/Add_User_Faviorte", methods=["POST"]) | ||
def adduserfaviorte(): | ||
""" | ||
Function to add user from database | ||
Add a pet to the user's favorites in the database. | ||
--- | ||
parameters: | ||
- in: body | ||
name: pet | ||
required: true | ||
schema: | ||
type: object | ||
properties: | ||
pet_id: | ||
type: integer | ||
example: 101 | ||
responses: | ||
200: | ||
description: Pet added to favorites successfully. | ||
""" | ||
json_data = request.get_json() | ||
|
||
# Api accesses database and append post json in database | ||
#Retrun database with succses code | ||
return jsonify(add_user_faviorte(json_data)), 200 | ||
|
||
# Un Faviote Route. remove user faviorte pet from there database | ||
# Unfavorite Route. Remove user favorite pet from their database | ||
@app.route("/Remove_User_Faviorte", methods=["DELETE"]) | ||
def removeuserfaviorte(): | ||
""" | ||
Function to remove user from database | ||
Remove a pet from the user's favorites in the database. | ||
--- | ||
parameters: | ||
- in: body | ||
name: pet | ||
required: true | ||
schema: | ||
type: object | ||
properties: | ||
pet_id: | ||
type: integer | ||
example: 101 | ||
responses: | ||
200: | ||
description: Pet removed from favorites successfully. | ||
""" | ||
json_data = request.get_json() | ||
return jsonify(remove_user_faviorte(json_data)), 200 | ||
|
||
# Api accesses database and append post json in database | ||
#Retrun database with succses code | ||
return jsonify(remove_user_faviorte(json_data)), 200 # return new user database | ||
|
||
# Change a Users account location | ||
# Change a User's account location | ||
@app.route("/Change_User_Location", methods=["PUT"]) | ||
def replace_user_information(): | ||
""" | ||
Function to change the location associated with | ||
an account | ||
Change the location associated with a user's account. | ||
--- | ||
parameters: | ||
- in: body | ||
name: location | ||
required: true | ||
schema: | ||
type: object | ||
properties: | ||
new_location: | ||
type: string | ||
example: 'New York, NY' | ||
responses: | ||
200: | ||
description: User location updated successfully. | ||
""" | ||
newlocation = request.get_json() # Get new location from post request | ||
return jsonify(replace_user_location(newlocation)) # retrun user account info | ||
newlocation = request.get_json() | ||
return jsonify(replace_user_location(newlocation)), 200 | ||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=5000, debug=True) |