From c0add7d96b9fb8f806cac0d555633d4aebf869f2 Mon Sep 17 00:00:00 2001 From: ameneh-keshavarz Date: Sat, 31 May 2025 12:22:32 +0100 Subject: [PATCH 1/2] add root route to confirm backend is running --- backend/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/main.py b/backend/main.py index 7ba155f..ff696c2 100644 --- a/backend/main.py +++ b/backend/main.py @@ -46,6 +46,10 @@ def main(): jwt = JWTManager(app) jwt.user_lookup_loader(lookup_user) + @app.route("/") + def index(): + return "PurpleForest backend is running!" + app.add_url_rule("/register", methods=["POST"], view_func=register) app.add_url_rule("/login", methods=["POST"], view_func=login) From cf41cbc149b49aad07f1643970ca2746e4b8531e Mon Sep 17 00:00:00 2001 From: ameneh-keshavarz Date: Wed, 18 Jun 2025 16:13:21 +0100 Subject: [PATCH 2/2] add 280 character limitation for blooms --- backend/data/blooms.py | 5 ++++- backend/populate.py | 4 ++-- db/schema.sql | 2 +- front-end/components/bloom-form.mjs | 12 +++++++++++- front-end/index.html | 1 + 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/backend/data/blooms.py b/backend/data/blooms.py index 7e280cf..7cf459a 100644 --- a/backend/data/blooms.py +++ b/backend/data/blooms.py @@ -16,10 +16,13 @@ class Bloom: def add_bloom(*, sender: User, content: str) -> Bloom: - hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] + if len(content) > 280: + raise ValueError("Bloom content exceeds the 280 character limit.") + hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] now = datetime.datetime.now(tz=datetime.UTC) bloom_id = int(now.timestamp() * 1000000) + with db_cursor() as cur: cur.execute( "INSERT INTO blooms (id, sender_id, content, send_timestamp) VALUES (%(bloom_id)s, %(sender_id)s, %(content)s, %(timestamp)s)", diff --git a/backend/populate.py b/backend/populate.py index 414218b..e952aaf 100644 --- a/backend/populate.py +++ b/backend/populate.py @@ -64,8 +64,8 @@ def main(): writer_access_token = create_user("AS", "neverSt0pTalking") send_bloom( writer_access_token, - "In this essay I will convince you that my views are correct in ways you have never imagined. If it doesn't change your life, read it again. Marshmallows are magnificent. They have great squish, tasty good, and you can even toast them over a fire. Toast them just right until they have a tiny bit of crunch when you bite into them, and have just started melting in the middle.", - ) + "In this essay I will convince you my views are correct in ways you never imagined. If it doesn't change your life, read it again. Marshmallows are magnificent—great squish, tasty, and perfect toasted with a crisp outside and melty middle." + ) justsomeguy_access_token = create_user("JustSomeGuy", "mysterious") send_bloom(justsomeguy_access_token, "Hello.") diff --git a/db/schema.sql b/db/schema.sql index 61e7580..13a5a51 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -9,7 +9,7 @@ CREATE TABLE users ( CREATE TABLE blooms ( id BIGSERIAL NOT NULL PRIMARY KEY, sender_id INT NOT NULL REFERENCES users(id), - content TEXT NOT NULL, + content TEXT NOT NULL CHECK (char_length(content) <= 280), send_timestamp TIMESTAMP NOT NULL ); diff --git a/front-end/components/bloom-form.mjs b/front-end/components/bloom-form.mjs index e047f9a..433d7cd 100644 --- a/front-end/components/bloom-form.mjs +++ b/front-end/components/bloom-form.mjs @@ -52,7 +52,17 @@ function handleTyping(event) { .closest("[data-form]") ?.querySelector("[data-counter]"); const maxLength = parseInt(textarea.getAttribute("maxlength"), 10); - counter.textContent = `${textarea.value.length} / ${maxLength}`; + const currentLength = textarea.value.length; + + counter.textContent = `${currentLength} / ${maxLength}`; + + if (currentLength >= maxLength) { + counter.style.color = "red"; + counter.textContent += " — character limit reached!"; + } else { + counter.style.color = ""; + } } + export {createBloomForm, handleBloomSubmit, handleTyping}; diff --git a/front-end/index.html b/front-end/index.html index 89d6b13..624127a 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -219,6 +219,7 @@

Share a Bloom

placeholder="What's happening?" maxlength="280" spellcheck="true" + maxlength="280" required >
0/280