Skip to content

Commit

Permalink
Merge pull request #36 from software-students-spring2024/task/21/card…
Browse files Browse the repository at this point in the history
…crud

Task/21/cardcrud
  • Loading branch information
shriyakalakata authored Feb 24, 2024
2 parents 25f6c64 + 67b3a18 commit bff7512
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@
except Exception as e:
print("MongoDB connection error:", e)

@app.route("/")
def home():
return render_template('mainScreen.html')

@app.route("/<username>/decks")
def allDecks(username):
# would need to first find user in db, but not set up yet
# would redirect to template for Decks
return f'{username} decks'

@app.route("/<username>/create", methods=["POST"])
def createDeck(username):
# would need to first find user in db, but not set up yet
title = request.form["title"]
newDeck = {"title": title, "cards": []}
db.decks.insert_one(newDeck)
# would rendirect to template for Cards
return "created deck"

@app.route("/<username>/<deckTitle>/add", methods=["POST"])
def addCard(username, deckTitle):
# would need to first find user in db, but not set up yet
deck = db.decks.find_one({"title": deckTitle})
newCard = request.form["question"]
deck["cards"].append(newCard)
db.decks.update_one({"title": deckTitle}, {"$set": deck})
# would redirect to template for Cards
return "added card"

# run the app
if __name__ == "__main__":
Expand Down

0 comments on commit bff7512

Please sign in to comment.