diff --git a/backend/endpoints.py b/backend/endpoints.py index 0e177a0..39607a2 100644 --- a/backend/endpoints.py +++ b/backend/endpoints.py @@ -167,6 +167,31 @@ def send_bloom(): ) +# === Rebloom Feature === +@jwt_required() +def rebloom(bloom_id): + current_user = get_current_user() + + # Check if the bloom exists + original_bloom = blooms.get_bloom(bloom_id) + + if original_bloom is None: + return make_response( + jsonify({"success": False, "message": "Bloom not found"}), 404 + ) + + # Create a new bloom from the original one + content = f"Rebloomed from @{original_bloom.sender}: {original_bloom.content}" + + blooms.add_bloom(sender=current_user, content=content) + + return jsonify( + { + "success": True, + } + ) + + def get_bloom(id_str): try: id_int = int(id_str) @@ -244,4 +269,4 @@ def verify_request_fields(names_to_types: Dict[str, type]) -> Union[Response, No 400, ) ) - return None + return None \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 7ba155f..9364972 100644 --- a/backend/main.py +++ b/backend/main.py @@ -12,6 +12,7 @@ register, self_profile, send_bloom, + rebloom, suggested_follows, user_blooms, ) @@ -57,6 +58,7 @@ def main(): app.add_url_rule("/suggested-follows/", view_func=suggested_follows) app.add_url_rule("/bloom", methods=["POST"], view_func=send_bloom) + app.add_url_rule("/rebloom/", methods=["POST"], view_func=rebloom) app.add_url_rule("/bloom/", methods=["GET"], view_func=get_bloom) app.add_url_rule("/blooms/", view_func=user_blooms) app.add_url_rule("/hashtag/", view_func=hashtag) @@ -65,4 +67,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/front-end/index.html b/front-end/index.html index 89d6b13..3bcb53e 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -236,9 +236,17 @@

Share a Bloom

@@ -258,4 +266,4 @@

Share a Bloom

- + \ No newline at end of file diff --git a/front-end/index.mjs b/front-end/index.mjs index be49922..3a7128f 100644 --- a/front-end/index.mjs +++ b/front-end/index.mjs @@ -57,6 +57,18 @@ window.addEventListener("unhandledrejection", (event) => { handleErrorDialog(event.reason); }); +// Rebloom click handler +document.querySelector("#app").addEventListener("click", async (event) => { + const action = event.target.dataset.action; + + if (action === "rebloom") { + const bloomElement = event.target.closest("[data-bloom]"); + const bloomId = bloomElement.dataset.bloomId; + + await apiService.rebloom(bloomId); + } +}); + export { getLogoutContainer, getLoginContainer, @@ -68,4 +80,4 @@ export { getErrorDialog, state, apiService, -}; +}; \ No newline at end of file diff --git a/front-end/lib/api.mjs b/front-end/lib/api.mjs index f4b5339..9943726 100644 --- a/front-end/lib/api.mjs +++ b/front-end/lib/api.mjs @@ -212,6 +212,23 @@ async function postBloom(content) { } } +// Re bloom +async function rebloom(bloomId) { + try { + const data = await _apiRequest(`/rebloom/${bloomId}`, { + method: "POST", + }); + + if (data.success) { + await getBlooms(); + } + + return data; + } catch (error) { + return {success: false}; + } +} + // ======= USER methods async function getProfile(username) { const endpoint = username ? `/profile/${username}` : "/profile"; @@ -291,6 +308,7 @@ const apiService = { getBloom, getBlooms, postBloom, + rebloom, getBloomsByHashtag, // User methods