Skip to content

Commit

Permalink
ENH: Logging and get plants endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mseng10 committed May 26, 2024
1 parent 5bef973 commit dd504b3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sqlalchemy.orm import sessionmaker
from sqlalchemy.engine import URL
import json
import logging

# Initialize Colorama
init(autoreset=True)
Expand All @@ -27,11 +28,16 @@
# Create Flask app
app = Flask(__name__)

# Example route to add a new plant
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@app.route("/plants", methods=["POST"])
def add_plant():
# Get JSON data from request
new_plant = request.get_json()
# Log the request
logger.info("Received request to add a new plant: %s", new_plant)
# Perform database operations here
# Example: Add new plant to the database
# session = Session()
Expand All @@ -41,6 +47,23 @@ def add_plant():
# Return response
return jsonify(new_plant), 201

# Example route to get all plants
@app.route("/plants", methods=["GET"])
def get_plants():
# Log the request
logger.info("Received request to retrieve all plants")
print("HELLO")
# Perform database query to retrieve all plants
# Example: Query all plants from the database
# session = Session()
# plants = session.query(Plant).all()
# session.close()
# Transform plants to JSON format
# Example: Convert plants to JSON format
# plants_json = [plant.to_json() for plant in plants]
# Return JSON response
return jsonify([]) # Placeholder response

if __name__ == "__main__":
# Run the Flask app
app.run(debug=True)

0 comments on commit dd504b3

Please sign in to comment.