diff --git a/server/app.py b/server/app.py index 3e84165..51494c1 100644 --- a/server/app.py +++ b/server/app.py @@ -1,13 +1,18 @@ from colorama import init, Fore -from flask import Flask, request, abort +from flask import Flask, request, jsonify from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.engine import URL import json +# Initialize Colorama +init(autoreset=True) + +# Load database configuration from JSON file with open("db.json") as json_data_file: db_config = json.load(json_data_file) +# Create SQLAlchemy engine url = URL.create( drivername=db_config["drivername"], username=db_config["username"], @@ -16,19 +21,26 @@ database=db_config["database"], port=db_config["port"], ) - engine = create_engine(url) -connection = engine.connect() Session = sessionmaker(bind=engine) -init(autoreset=True) +# Create Flask app app = Flask(__name__) +# Example route to add a new plant @app.route("/plants", methods=["POST"]) def add_plant(): + # Get JSON data from request new_plant = request.get_json() - new_plant["id"] = len(plants) + 1 - plants.append(new_plant) + # Perform database operations here + # Example: Add new plant to the database + # session = Session() + # session.add(new_plant) + # session.commit() + # session.close() + # Return response return jsonify(new_plant), 201 -from cli import create, stats, update, water, archive +if __name__ == "__main__": + # Run the Flask app + app.run(debug=True) diff --git a/server/models/__init__.py b/server/models/__init__.py index fef102b..70d120f 100644 --- a/server/models/__init__.py +++ b/server/models/__init__.py @@ -1,8 +1,7 @@ -from app import engine -from models.base import Base -from models.plant import Plant +# from app import engine +# from models.base import Base -# TODO: Implement way to make this configurable +# # TODO: Implement way to make this configurable -Base.metadata.drop_all(engine) -Base.metadata.create_all(engine) +# Base.metadata.drop_all(engine) +# Base.metadata.create_all(engine) diff --git a/server/models/plant.py b/server/models/plant.py index bc49cce..54befe9 100644 --- a/server/models/plant.py +++ b/server/models/plant.py @@ -1,23 +1,25 @@ from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey from datetime import datetime -from models import Base from sqlalchemy.orm import Mapped, relationship, mapped_column +from sqlalchemy.ext.declarative import declarative_base +from typing import List from enum import Enum +Base = declarative_base() -class DeathCause(Enum, str): - TOO_LITTLE_WATER = "too little water" - TOO_MUCH_WATER = "too much water" - TOO_LITTLE_HUMIDITY = "too little humidity" - TOO_MUCH_HUMIDITY = "too much humidity" - TOO_LITTLE_SUN = "too little sun" - TOO_MUCH_SUN = "too much sun" - PROPAGATION = "propagation" - PESTS = "pests" - MOLD = "mold" - NEGLECT = "neglect" - UNKNOWN = "unknown" +# class DeathCause(Enum, str): + # TOO_LITTLE_WATER = "too little water" + # TOO_MUCH_WATER = "too much water" + # TOO_LITTLE_HUMIDITY = "too little humidity" + # TOO_MUCH_HUMIDITY = "too much humidity" + # TOO_LITTLE_SUN = "too little sun" + # TOO_MUCH_SUN = "too much sun" + # PROPAGATION = "propagation" + # PESTS = "pests" + # MOLD = "mold" + # NEGLECT = "neglect" + # UNKNOWN = "unknown" class Plant(Base): @@ -44,7 +46,7 @@ class Plant(Base): # Death Info dead = Column(Boolean, default=False, nullable=False) - dead_cause = Column(Enum(DeathCause), nullable=True) + # dead_cause = Column(Enum(DeathCause), nullable=True) dead_on = Column(DateTime(), default=None, nullable=True) def __repr__(self) -> str: