From 725f028d694f8930e6508f3ada106ab151ef1644 Mon Sep 17 00:00:00 2001 From: jChenvan <188939308+jChenvan@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:13:31 -0400 Subject: [PATCH] Add sources config --- .../migrate_approval.cpython-39.pyc | Bin 2044 -> 2044 bytes docker/ploughshares/app.py | 84 ++++++++++++++++++ docker/ploughshares/schema.sql | 8 ++ docker/ploughshares/templates/base.html | 15 ++-- .../ploughshares/templates/view_sources.html | 73 +++++++++++++++ 5 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 docker/ploughshares/templates/view_sources.html diff --git a/docker/ploughshares/__pycache__/migrate_approval.cpython-39.pyc b/docker/ploughshares/__pycache__/migrate_approval.cpython-39.pyc index d06f8d46f2b40cfc9cd737cf0921a700959ea6b5..587e858556cfad080f56923614ec686ccc08333d 100644 GIT binary patch delta 20 acmeyv|A(JDk(ZZ?0SKH=', methods=['DELETE']) +def api_delete_source(id): + """API endpoint to delete a source""" + conn = get_db_connection() + if conn is None: + return jsonify({"error": "Database connection error"}), 500 + + try: + with conn.cursor() as cur: + # Check if transaction exists + cur.execute('SELECT src_id FROM sources WHERE src_id = %s', (id,)) + if cur.fetchone() is None: + return jsonify({"error": "Source not found"}), 404 + + # Delete the transaction + cur.execute('DELETE FROM sources WHERE src_id = %s', (id,)) + conn.commit() + return jsonify({"message": "Source deleted successfully"}), 200 + except Exception as e: + logger.error(f"Error deleting transaction via API: {e}") + return jsonify({"error": f"Error deleting source: {str(e)}"}), 500 + finally: + conn.close() + if __name__ == '__main__': logger.info(f"Starting Ploughshares v{VERSION}") bootstrap_database() diff --git a/docker/ploughshares/schema.sql b/docker/ploughshares/schema.sql index e494e0f..6a77357 100644 --- a/docker/ploughshares/schema.sql +++ b/docker/ploughshares/schema.sql @@ -1,6 +1,7 @@ -- Drop tables if they exist DROP TABLE IF EXISTS transaction_documents CASCADE; DROP TABLE IF EXISTS transactions CASCADE; +DROP TABLE IF EXISTS sources CASCADE; -- Create transactions table CREATE TABLE IF NOT EXISTS transactions ( @@ -41,6 +42,13 @@ CREATE TABLE transaction_documents ( upload_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ); +CREATE TABLE sources ( + src_id SERIAL PRIMARY KEY, + title VARCHAR(255) NOT NULL, + link VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL +); + -- Create indexes for better performance CREATE INDEX IF NOT EXISTS idx_transactions_type ON transactions(transaction_type); CREATE INDEX IF NOT EXISTS idx_transactions_division ON transactions(company_division); diff --git a/docker/ploughshares/templates/base.html b/docker/ploughshares/templates/base.html index 0991dfb..7638228 100644 --- a/docker/ploughshares/templates/base.html +++ b/docker/ploughshares/templates/base.html @@ -59,11 +59,16 @@ - + + diff --git a/docker/ploughshares/templates/view_sources.html b/docker/ploughshares/templates/view_sources.html new file mode 100644 index 0000000..f29f1ba --- /dev/null +++ b/docker/ploughshares/templates/view_sources.html @@ -0,0 +1,73 @@ +{% extends "base.html" %} + +{% block title %}Sources - Project Ploughshares{% endblock %} + +{% block content %} +
+
+
+

Sources

+
+
+
+

Add Source

+ + + + +
+
+ + + + + + + + + + + + {% for source in sources %} + + + + + + + + {% endfor %} + +
Source No.TitleLinkType
{{ source['src_id'] }}{{ source['title'] }}{{ source['link'] }}{{ source['type'] }}
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} \ No newline at end of file