From 2161173065ad2f3cf6725fc001a98a0c1da5696c Mon Sep 17 00:00:00 2001 From: Tami Date: Fri, 23 Dec 2022 07:09:33 +0800 Subject: [PATCH 01/11] Completed backend setup --- app/__init__.py | 2 + app/models/board.py | 6 ++ app/models/card.py | 6 ++ migrations/README | 1 + migrations/alembic.ini | 45 +++++++++ migrations/env.py | 96 +++++++++++++++++++ migrations/script.py.mako | 24 +++++ ...1602f98994c8_adds_board_and_card_models.py | 40 ++++++++ 8 files changed, 220 insertions(+) create mode 100644 migrations/README create mode 100644 migrations/alembic.ini create mode 100644 migrations/env.py create mode 100644 migrations/script.py.mako create mode 100644 migrations/versions/1602f98994c8_adds_board_and_card_models.py diff --git a/app/__init__.py b/app/__init__.py index 1c821436..74bb78f7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,6 +19,8 @@ def create_app(): # Import models here for Alembic setup # from app.models.ExampleModel import ExampleModel + from app.models.card import Card + from app.models.board import Board db.init_app(app) migrate.init_app(app, db) diff --git a/app/models/board.py b/app/models/board.py index 147eb748..0360bc3b 100644 --- a/app/models/board.py +++ b/app/models/board.py @@ -1 +1,7 @@ from app import db + + +class Board(db.Model): + board_id = db.Column(db.Integer, primary_key=True, autoincrement=True) + title = db.Column(db.String) + owner = db.Column(db.String) diff --git a/app/models/card.py b/app/models/card.py index 147eb748..85d9e08e 100644 --- a/app/models/card.py +++ b/app/models/card.py @@ -1 +1,7 @@ from app import db + + +class Card(db.Model): + card_id = db.Column(db.Integer, primary_key=True, autoincrement=True) + message = db.Column(db.String) + likes_count = db.Column(db.Integer) diff --git a/migrations/README b/migrations/README new file mode 100644 index 00000000..98e4f9c4 --- /dev/null +++ b/migrations/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/migrations/alembic.ini b/migrations/alembic.ini new file mode 100644 index 00000000..f8ed4801 --- /dev/null +++ b/migrations/alembic.ini @@ -0,0 +1,45 @@ +# A generic, single database configuration. + +[alembic] +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/migrations/env.py b/migrations/env.py new file mode 100644 index 00000000..8b3fb335 --- /dev/null +++ b/migrations/env.py @@ -0,0 +1,96 @@ +from __future__ import with_statement + +import logging +from logging.config import fileConfig + +from sqlalchemy import engine_from_config +from sqlalchemy import pool +from flask import current_app + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +config.set_main_option( + 'sqlalchemy.url', + str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) +target_metadata = current_app.extensions['migrate'].db.metadata + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def run_migrations_offline(): + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, target_metadata=target_metadata, literal_binds=True + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + connectable = engine_from_config( + config.get_section(config.config_ini_section), + prefix='sqlalchemy.', + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + process_revision_directives=process_revision_directives, + **current_app.extensions['migrate'].configure_args + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/migrations/script.py.mako b/migrations/script.py.mako new file mode 100644 index 00000000..2c015630 --- /dev/null +++ b/migrations/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/migrations/versions/1602f98994c8_adds_board_and_card_models.py b/migrations/versions/1602f98994c8_adds_board_and_card_models.py new file mode 100644 index 00000000..70895ab5 --- /dev/null +++ b/migrations/versions/1602f98994c8_adds_board_and_card_models.py @@ -0,0 +1,40 @@ +"""adds Board and Card models + +Revision ID: 1602f98994c8 +Revises: +Create Date: 2022-12-23 07:07:46.653883 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '1602f98994c8' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('board', + sa.Column('board_id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('title', sa.String(), nullable=True), + sa.Column('owner', sa.String(), nullable=True), + sa.PrimaryKeyConstraint('board_id') + ) + op.create_table('card', + sa.Column('card_id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('message', sa.String(), nullable=True), + sa.Column('likes_count', sa.Integer(), nullable=True), + sa.PrimaryKeyConstraint('card_id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('card') + op.drop_table('board') + # ### end Alembic commands ### From df2e071853cd47bc09f1e1deabf7b1adea515fff Mon Sep 17 00:00:00 2001 From: Tami Date: Sat, 24 Dec 2022 06:09:12 +0800 Subject: [PATCH 02/11] Created read, delete, and post routes for cards --- app/__init__.py | 4 ++-- app/models/card.py | 16 +++++++++++++ app/routes.py | 59 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 74bb78f7..948d3309 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,8 +26,8 @@ def create_app(): migrate.init_app(app, db) # Register Blueprints here - # from .routes import example_bp - # app.register_blueprint(example_bp) + from .routes import card_bp + app.register_blueprint(card_bp) CORS(app) return app diff --git a/app/models/card.py b/app/models/card.py index 85d9e08e..2def8a56 100644 --- a/app/models/card.py +++ b/app/models/card.py @@ -1,7 +1,23 @@ from app import db +from flask import abort, make_response class Card(db.Model): card_id = db.Column(db.Integer, primary_key=True, autoincrement=True) message = db.Column(db.String) likes_count = db.Column(db.Integer) + + def to_json(self): + card_as_json = {} + card_as_json["id"] = self.card_id + card_as_json["message"] = self.message + card_as_json["likes_count"] = self.likes_count + return card_as_json + + @classmethod + def from_json(cls, card_json): + if "message" in card_json and len(card_json["message"]) <= 40: + new_obj = cls(message=card_json["message"]) + return new_obj + else: + abort(make_response({"Invalid data": "Message cannot be blank or more than 40 characters"}, 400)) diff --git a/app/routes.py b/app/routes.py index 480b8c4b..9389068c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,59 @@ -from flask import Blueprint, request, jsonify, make_response +from flask import Blueprint, request, jsonify, abort, make_response from app import db +from app.models.card import Card -# example_bp = Blueprint('example_bp', __name__) + +def get_one_obj_or_abort(cls, obj_id): + try: + obj_id = int(obj_id) + except ValueError: + abort(make_response({"message":f"Invalid {cls.__name__} ID: `{obj_id}`. ID must be an integer"}, 400)) + + matching_obj = cls.query.get(obj_id) + + if not matching_obj: + abort(make_response({"message":f"{cls.__name__} with id `{obj_id}` was not found in the database."}, 404)) + + return matching_obj + +card_bp = Blueprint('card_bp', __name__, url_prefix='/cards') + +@card_bp.route("", methods=["POST"]) +def add_card(): + request_body = request.get_json() + + new_card = Card.from_json(request_body) + + db.session.add(new_card) + db.session.commit() + + return {"card": new_card.to_json()}, 201 + + +@card_bp.route("", methods=["GET"]) +def get_all_cards(): + cards = Card.query.all() + + cards_response = [card.to_json() for card in cards] + + return jsonify(cards_response) + + +@card_bp.route("/", methods=["GET"]) +def get_one_card(card_id): + chosen_card = get_one_obj_or_abort(Card, card_id) + + card_json = chosen_card.to_json() + + return jsonify(card_json), 200 + + +@card_bp.route("/", methods=["DELETE"]) +def delete_one_card(card_id): + chosen_card = get_one_obj_or_abort(Card, card_id) + + db.session.delete(chosen_card) + + db.session.commit() + + return jsonify({"message": f"Successfully deleted card with id `{card_id}`"}), 200 From d3d6e394ccba2d5d1aa2c87c37cfd892ec1d8d37 Mon Sep 17 00:00:00 2001 From: Tami Date: Wed, 4 Jan 2023 10:43:42 -0800 Subject: [PATCH 03/11] Implemented cards & boards relationship --- app/models/board.py | 1 + app/models/card.py | 2 ++ ...ec0631776_implemented_cards_and_boards_.py | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 migrations/versions/c95ec0631776_implemented_cards_and_boards_.py diff --git a/app/models/board.py b/app/models/board.py index 0360bc3b..e1b1a93d 100644 --- a/app/models/board.py +++ b/app/models/board.py @@ -5,3 +5,4 @@ class Board(db.Model): board_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) owner = db.Column(db.String) + card = db.relationship("Card", back_populates="board", lazy=True) diff --git a/app/models/card.py b/app/models/card.py index 2def8a56..eeda45ab 100644 --- a/app/models/card.py +++ b/app/models/card.py @@ -6,6 +6,8 @@ class Card(db.Model): card_id = db.Column(db.Integer, primary_key=True, autoincrement=True) message = db.Column(db.String) likes_count = db.Column(db.Integer) + board_id = db.Column(db.Integer, db.ForeignKey("board.board_id"), nullable=True) + board = db.relationship("Card", back_populates="cards") def to_json(self): card_as_json = {} diff --git a/migrations/versions/c95ec0631776_implemented_cards_and_boards_.py b/migrations/versions/c95ec0631776_implemented_cards_and_boards_.py new file mode 100644 index 00000000..c433c6a9 --- /dev/null +++ b/migrations/versions/c95ec0631776_implemented_cards_and_boards_.py @@ -0,0 +1,30 @@ +"""Implemented cards and boards relationship + +Revision ID: c95ec0631776 +Revises: 1602f98994c8 +Create Date: 2023-01-04 10:41:02.177755 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'c95ec0631776' +down_revision = '1602f98994c8' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('card', sa.Column('board_id', sa.Integer(), nullable=True)) + op.create_foreign_key(None, 'card', 'board', ['board_id'], ['board_id']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'card', type_='foreignkey') + op.drop_column('card', 'board_id') + # ### end Alembic commands ### From 5a9aa77ec9b6abd24e0a1933a861893ad6111868 Mon Sep 17 00:00:00 2001 From: Tami Date: Wed, 4 Jan 2023 11:10:18 -0800 Subject: [PATCH 04/11] Fixed back_populates mistake --- app/models/card.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/card.py b/app/models/card.py index eeda45ab..50aa0611 100644 --- a/app/models/card.py +++ b/app/models/card.py @@ -7,7 +7,7 @@ class Card(db.Model): message = db.Column(db.String) likes_count = db.Column(db.Integer) board_id = db.Column(db.Integer, db.ForeignKey("board.board_id"), nullable=True) - board = db.relationship("Card", back_populates="cards") + board = db.relationship("Board", back_populates="cards") def to_json(self): card_as_json = {} From b6960c94a02c0cc332e445e9811f60ddb2b06525 Mon Sep 17 00:00:00 2001 From: Tami Date: Thu, 5 Jan 2023 12:06:03 -0800 Subject: [PATCH 05/11] Completed nested routes for boards and cards --- app/__init__.py | 4 +-- app/models/board.py | 19 +++++++++++- app/routes.py | 71 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 948d3309..ce13c449 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,8 +26,8 @@ def create_app(): migrate.init_app(app, db) # Register Blueprints here - from .routes import card_bp - app.register_blueprint(card_bp) + from .routes import boards_bp + app.register_blueprint(boards_bp) CORS(app) return app diff --git a/app/models/board.py b/app/models/board.py index e1b1a93d..6cb75f6a 100644 --- a/app/models/board.py +++ b/app/models/board.py @@ -1,8 +1,25 @@ from app import db +from flask import abort, make_response class Board(db.Model): board_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) owner = db.Column(db.String) - card = db.relationship("Card", back_populates="board", lazy=True) + cards = db.relationship("Card", back_populates="board", lazy=True) + + def to_json(self): + board_as_json = {} + board_as_json["id"] = self.board_id + board_as_json["title"] = self.title + board_as_json["owner"] = self.owner + return board_as_json + + @classmethod + def from_json(cls, board_json): + if board_json.get("title") and board_json.get("owner"): + new_obj = cls(title=board_json["title"], owner=board_json["owner"]) + return new_obj + else: + abort(make_response({"Invalid data": "Board title or owner's name cannot be blank"}, 400)) + diff --git a/app/routes.py b/app/routes.py index 9389068c..0465b5b9 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,6 +1,7 @@ from flask import Blueprint, request, jsonify, abort, make_response from app import db from app.models.card import Card +from app.models.board import Board def get_one_obj_or_abort(cls, obj_id): @@ -16,39 +17,66 @@ def get_one_obj_or_abort(cls, obj_id): return matching_obj -card_bp = Blueprint('card_bp', __name__, url_prefix='/cards') -@card_bp.route("", methods=["POST"]) -def add_card(): +# **************************** CRUD ROUTES FOR BOARDS ***************************************** + +boards_bp = Blueprint("boards", __name__, url_prefix="/boards") + +@boards_bp.route("", methods=["POST"]) +def add_board(): request_body = request.get_json() - new_card = Card.from_json(request_body) + new_board = Board.from_json(request_body) - db.session.add(new_card) + db.session.add(new_board) db.session.commit() - return {"card": new_card.to_json()}, 201 + return {"board": new_board.to_json()}, 201 -@card_bp.route("", methods=["GET"]) -def get_all_cards(): - cards = Card.query.all() +@boards_bp.route("", methods=["GET"]) +def get_all_boards(): + boards = Board.query.all() - cards_response = [card.to_json() for card in cards] + boards_response = [board.to_json() for board in boards] - return jsonify(cards_response) + return jsonify(boards_response) -@card_bp.route("/", methods=["GET"]) -def get_one_card(card_id): - chosen_card = get_one_obj_or_abort(Card, card_id) +@boards_bp.route("/", methods=["GET"]) +def get_one_board(board_id): + chosen_board = get_one_obj_or_abort(Board, board_id) - card_json = chosen_card.to_json() + board_json = chosen_board.to_json() - return jsonify(card_json), 200 + return jsonify(board_json), 200 +# ***************************** NESTED ROUTES FOR BOARDS AND CARDS ********************************* + +@boards_bp.route("//cards", methods=["POST"]) +def add_board_card(board_id): + chosen_board = get_one_obj_or_abort(Board, board_id) + request_body = request.get_json() + new_card = Card.from_json(request_body) + + new_card.board_id = chosen_board.board_id + + db.session.add(new_card) + db.session.commit() -@card_bp.route("/", methods=["DELETE"]) + return {"card": new_card.to_json()}, 201 + + +@boards_bp.route("//cards", methods=["GET"]) +def get_board_cards(board_id): + chosen_board = get_one_obj_or_abort(Board, board_id) + + cards_response = [card.to_json() for card in chosen_board.cards] + + return jsonify({"chosen board id": chosen_board.board_id, "title": chosen_board.title, "chosen board cards": cards_response}) + + +@boards_bp.route("/cards/", methods=["DELETE"]) def delete_one_card(card_id): chosen_card = get_one_obj_or_abort(Card, card_id) @@ -57,3 +85,12 @@ def delete_one_card(card_id): db.session.commit() return jsonify({"message": f"Successfully deleted card with id `{card_id}`"}), 200 + + +@boards_bp.route("/cards/", methods=["GET"]) +def get_one_card(card_id): + chosen_card = get_one_obj_or_abort(Card, card_id) + + card_json = chosen_card.to_json() + + return jsonify(card_json), 200 \ No newline at end of file From 18a76c04a7db54419f9c05f78e6b6a588aa7db7d Mon Sep 17 00:00:00 2001 From: Tami Date: Wed, 18 Jan 2023 11:22:57 -0800 Subject: [PATCH 06/11] Removed board id req from add cards --- app/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 0465b5b9..f3f67a0c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -53,7 +53,7 @@ def get_one_board(board_id): # ***************************** NESTED ROUTES FOR BOARDS AND CARDS ********************************* -@boards_bp.route("//cards", methods=["POST"]) +@boards_bp.route("/cards", methods=["POST"]) def add_board_card(board_id): chosen_board = get_one_obj_or_abort(Board, board_id) request_body = request.get_json() From 291c6bd31e09555d058c4f7631e791461da6a93d Mon Sep 17 00:00:00 2001 From: Tami Date: Wed, 18 Jan 2023 11:32:08 -0800 Subject: [PATCH 07/11] Put back board id req --- app/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index f3f67a0c..0465b5b9 100644 --- a/app/routes.py +++ b/app/routes.py @@ -53,7 +53,7 @@ def get_one_board(board_id): # ***************************** NESTED ROUTES FOR BOARDS AND CARDS ********************************* -@boards_bp.route("/cards", methods=["POST"]) +@boards_bp.route("//cards", methods=["POST"]) def add_board_card(board_id): chosen_board = get_one_obj_or_abort(Board, board_id) request_body = request.get_json() From b911a90f3df7b9761063dda6ec4613150ce3aa8c Mon Sep 17 00:00:00 2001 From: Tami Date: Thu, 19 Jan 2023 10:31:32 -0800 Subject: [PATCH 08/11] Added board id to card delete route --- app/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 0465b5b9..a5b9336d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -76,7 +76,7 @@ def get_board_cards(board_id): return jsonify({"chosen board id": chosen_board.board_id, "title": chosen_board.title, "chosen board cards": cards_response}) -@boards_bp.route("/cards/", methods=["DELETE"]) +@boards_bp.route("//cards/", methods=["DELETE"]) def delete_one_card(card_id): chosen_card = get_one_obj_or_abort(Card, card_id) From 4b4d5be2741322d11dccc50c455058a85a39e102 Mon Sep 17 00:00:00 2001 From: Tami Date: Thu, 19 Jan 2023 12:12:54 -0800 Subject: [PATCH 09/11] Fixed card delete route --- app/routes.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/routes.py b/app/routes.py index a5b9336d..4545f480 100644 --- a/app/routes.py +++ b/app/routes.py @@ -77,10 +77,18 @@ def get_board_cards(board_id): @boards_bp.route("//cards/", methods=["DELETE"]) -def delete_one_card(card_id): +def delete_one_card(board_id, card_id): + chosen_board = get_one_obj_or_abort(Board, board_id) + chosen_card = get_one_obj_or_abort(Card, card_id) - db.session.delete(chosen_card) + card_to_delete = None + + for card in chosen_board.cards: + if chosen_card == card.id: + card_to_delete = card + + db.session.delete(card_to_delete) db.session.commit() From 965ee186ecc38b32036f0ee0ee82e2c29dee796f Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 19 Jan 2023 14:38:48 -0800 Subject: [PATCH 10/11] Debugging delete card route --- app/routes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 4545f480..0c7729d1 100644 --- a/app/routes.py +++ b/app/routes.py @@ -85,7 +85,8 @@ def delete_one_card(board_id, card_id): card_to_delete = None for card in chosen_board.cards: - if chosen_card == card.id: + print(f"🌼 {card.__dict__}") + if chosen_card == card.card_id: card_to_delete = card db.session.delete(card_to_delete) From 7a783486b4f72279e992621b22a6c36a0729eeba Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 19 Jan 2023 14:48:33 -0800 Subject: [PATCH 11/11] Debugging delete card route --- app/routes.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/routes.py b/app/routes.py index 0c7729d1..681bb486 100644 --- a/app/routes.py +++ b/app/routes.py @@ -76,20 +76,20 @@ def get_board_cards(board_id): return jsonify({"chosen board id": chosen_board.board_id, "title": chosen_board.title, "chosen board cards": cards_response}) -@boards_bp.route("//cards/", methods=["DELETE"]) -def delete_one_card(board_id, card_id): - chosen_board = get_one_obj_or_abort(Board, board_id) +@boards_bp.route("/cards/", methods=["DELETE"]) +def delete_one_card(card_id): + # chosen_board = get_one_obj_or_abort(Board, board_id) chosen_card = get_one_obj_or_abort(Card, card_id) - card_to_delete = None + # card_to_delete = None - for card in chosen_board.cards: - print(f"🌼 {card.__dict__}") - if chosen_card == card.card_id: - card_to_delete = card + # for card in chosen_board.cards: + # print(f"🌼 {card.__dict__}") + # if chosen_card == card.card_id: + # card_to_delete = card - db.session.delete(card_to_delete) + db.session.delete(chosen_card) db.session.commit()