summary refs log tree commit diff
path: root/db.py
diff options
context:
space:
mode:
authormeltland <[email protected]>2025-03-22 15:57:13 -0400
committermeltland <[email protected]>2025-03-22 15:57:13 -0400
commita006c75df9ddbdf69a3c3ba70a29a1bf78ad826b (patch)
tree61bec00b531e8d980e80a59fe14e8df7f9b6948e /db.py
parente0b3db233b1412b14393c2f3c76ace83aa954889 (diff)
delete/edit
Diffstat (limited to 'db.py')
-rw-r--r--db.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/db.py b/db.py
index 28f3ba8..01718be 100644
--- a/db.py
+++ b/db.py
@@ -159,6 +159,37 @@ class posts:
             return "fail"
         return True
 
+    def remove(post_id):
+        post = postsd.find_one({"_id": post_id})
+        if not post:
+            return "notExists"
+        try:
+            postsd.delete_one({"_id": post_id})
+            postsd.update_many(
+                {"replies": {"$elemMatch": {"_id": post_id}}},
+                {"$set": {"replies.$.content": "post deleted"}}
+            )
+        except:
+            return "fail"
+        return True
+    
+    def edit(post_id, content):
+        post = postsd.find_one({"_id": post_id})
+        if not post:
+            return "notExists"
+        try:
+            postsd.update_one(
+                {"_id": post_id},
+                {"$set": {"content": content}}
+            )
+            postsd.update_many(
+                {"replies": {"$elemMatch": {"_id": post_id}}},
+                {"$set": {"replies.$.content": content}}
+            )
+        except:
+            return "fail"
+        return True
+
 class inbox:
     def get_recent(amount=75):
         posts = list(inboxd.find().sort("created", -1).limit(amount))