From 29c1e40205936bc8f55fb5c390551e7693095f1f Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Thu, 26 Feb 2026 13:48:30 +0100 Subject: [PATCH 1/5] Implementata funzione aggiornamento file --- app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.py b/app.py index bdcfb4a..bd36cdd 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ from flask import Flask, jsonify, request, render_template +import json compiti = [ {"id": 1, "descrizione": "Compito matematica"}, @@ -8,6 +9,10 @@ compiti = [ ] id_counter = 5 +def update_file(): + with open('compiti.json', 'w') as f: + json.dump(compiti, f) + app = Flask(__name__) @app.route("/", methods=["GET"]) @@ -38,6 +43,7 @@ def create_compito(): j["id"] = id_counter id_counter += 1 compiti.append(j) + update_file() return jsonify(j), 201 @app.route("/compiti/", methods=["DELETE"]) @@ -46,6 +52,7 @@ def delete_compito(id): if ciscomerda["id"] == id: compiti.remove(ciscomerda) return jsonify(ciscomerda), 200 + update_file() return jsonify([]), 404 app.run("0.0.0.0") -- 2.49.1 From bb6408e816f03d943804fe23ade8d772273540f2 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Fri, 27 Feb 2026 09:43:07 +0100 Subject: [PATCH 2/5] Implementazione lettura file JSON --- app.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index bd36cdd..368dd6d 100644 --- a/app.py +++ b/app.py @@ -1,18 +1,30 @@ from flask import Flask, jsonify, request, render_template import json +import os -compiti = [ -{"id": 1, "descrizione": "Compito matematica"}, -{"id": 2, "descrizione": "Consegna TPSIT progetto API REST"}, -{"id": 3, "descrizione": "Compito di sistemi"}, -{"id": 4, "descrizione": "Compito di italiano"} -] -id_counter = 5 +compiti = [] +id_counter = 0 def update_file(): with open('compiti.json', 'w') as f: json.dump(compiti, f) +if os.path.isfile('compiti.json'): + with open('compiti.json', 'r') as f: + compiti = json.load(f) + id_counter = 104 +else: + compiti = [ + {"id": 1, "descrizione": "Compito matematica"}, + {"id": 2, "descrizione": "Consegna TPSIT progetto API REST"}, + {"id": 3, "descrizione": "Compito di sistemi"}, + {"id": 4, "descrizione": "Compito di italiano"} + ] + id_counter = 5 + update_file() + + + app = Flask(__name__) @app.route("/", methods=["GET"]) -- 2.49.1 From b430d944bcd6b3b73af12d1a0fefe1365216e54c Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Fri, 27 Feb 2026 09:43:25 +0100 Subject: [PATCH 3/5] Aggiunto file JSON compiti in gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b630c93 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +compiti.json -- 2.49.1 From 8c870484acb30745e08506cf339763d808b420aa Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Tue, 3 Mar 2026 11:20:58 +0100 Subject: [PATCH 4/5] Implementato ripristino ID counter a caricamento file --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 368dd6d..74e7cd4 100644 --- a/app.py +++ b/app.py @@ -12,7 +12,7 @@ def update_file(): if os.path.isfile('compiti.json'): with open('compiti.json', 'r') as f: compiti = json.load(f) - id_counter = 104 + id_counter = compiti[-1]["id"] + 1 else: compiti = [ {"id": 1, "descrizione": "Compito matematica"}, -- 2.49.1 From a24912712191df003b527effd43448c0be02e10f Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Tue, 3 Mar 2026 11:22:20 +0100 Subject: [PATCH 5/5] Fix file non aggiornato a operazione DELETE effettuata senza errori --- app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app.py b/app.py index 74e7cd4..f348924 100644 --- a/app.py +++ b/app.py @@ -63,6 +63,7 @@ def delete_compito(id): for ciscomerda in compiti: if ciscomerda["id"] == id: compiti.remove(ciscomerda) + update_file() return jsonify(ciscomerda), 200 update_file() return jsonify([]), 404 -- 2.49.1