Skip to content

Commit

Permalink
implement Swagger documentation for main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
IshayuR committed Nov 6, 2024
1 parent 2c834cc commit 8d29d0c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
Binary file added Backend/__pycache__/petfuc.cpython-311.pyc
Binary file not shown.
Binary file added Backend/__pycache__/userfuc.cpython-311.pyc
Binary file not shown.
94 changes: 73 additions & 21 deletions Backend/main.py
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)

0 comments on commit 8d29d0c

Please sign in to comment.