def delete(self, id): if security.can_modify(request.cookies.get("user")): find_id = security.getObjectId(id) if find_id: model.Deck.find_one({"_id": find_id}).delete() else: abort(403)
def get(self, id): find_id = security.getObjectId(id) if find_id: result = model.Card.find_one({"_id": find_id}) if result: return jsonify(result.dump()) abort(404)
def get(self, id): shuffle = "shuffle" in request.args.keys() get_cards_content = "cards_content" in request.args.keys() find_id = security.getObjectId(id) if find_id: result = model.Deck.find_one({"_id": find_id}) if result: raw_deck = result.dump() if get_cards_content: cards = [] for card_id_raw in raw_deck["cards"]: card_id = security.getObjectId(card_id_raw) if not card_id: print( f"Invalid card id : {card_id_raw} in deck {id}" ) abort(500) card = model.Card.find_one({"_id": card_id}) if not card: print( f"Couldn't find card with id {card_id_raw} in deck {id}" ) abort(500) cards.append(card.dump()) raw_deck["cards"] = cards if shuffle: random.shuffle(raw_deck["cards"]) return jsonify(raw_deck) abort(404)
def put(self, id): if security.can_modify(request.cookies.get("user")): find_id = security.getObjectId(id) if find_id: new_deck = request.get_json().get("deck") if new_deck: try: old_deck_obj = model.Deck.find_one({"_id": find_id}) old_deck_obj.update(new_deck) old_deck_obj.commit() return (old_deck_obj.dump()) except marshmallow.exceptions.ValidationError as e: abort(400) abort(403)