Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/21/cardcrud #36

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading