Esempio n. 1
0
def get_card_details(card_id):
    validate_id(card_id, "Card ID")
    card = card_repository.get_card_details(card_id)
    if card:
        stringify_id(card)
        return card
    else:
        raise NotFoundError()
Esempio n. 2
0
def update_deck_details(deck_id, deck_name, username):
    validate_id(deck_id, "Deck ID")
    if deck_name:
        verify_owner_from_deck_id(deck_id, username)
        deck_repository.update_deck_details(deck_id, deck_name)
        return {"id": deck_id, "name": deck_name}
    else:
        raise InvalidDataError()
Esempio n. 3
0
def add_card_to_deck(deck_id, card_id, username):
    validate_id(deck_id, "Deck ID")
    validate_id(card_id, "Card ID")
    verify_owner_from_deck_id(deck_id, username)
    card = card_repository.get_card_details(card_id)
    if card is not None:
        card_deck_id = deck_repository.add_card_to_deck(deck_id, card_id)
        return {"cardDeckId": str(card_deck_id)}
    else:
        raise NotFoundError("Card could not be found")
Esempio n. 4
0
def delete_note_from_deck(deck_id, note_id, username):
    validate_id(deck_id, "Deck ID")
    validate_id(note_id, "Note ID")
    deck = deck_repository.get_deck_details(deck_id)
    if deck is not None:
        if deck['username'] == username:
            return note_repository.delete_note_from_deck(deck_id, note_id)
        else:
            raise InvalidAccessError()
    else:
        raise NotFoundError("Deck could not be found")
Esempio n. 5
0
def get_deck_details(deck_id, username):
    validate_id(deck_id, "Deck ID")
    deck = deck_repository.get_deck_details(deck_id)
    verify_owner_from_deck(deck, username)
    stringify_id(deck)
    for card in deck['cards']:
        stringify_id(card)
        stringify_id_nonstandard_key(card, 'card_deck_id', 'cardDeckId')
    for note in deck['notes']:
        stringify_id(note)
    return deck
Esempio n. 6
0
def add_note_to_deck(deck_id, note_message, username):
    if note_message:
        validate_id(deck_id, "Deck ID")
        deck = deck_repository.get_deck_details(deck_id)
        if deck is not None:
            if deck['username'] == username:
                new_note_id = ObjectId()
                new_note = {"_id": new_note_id, "message": note_message}
                note_repository.add_note_to_deck(deck_id, new_note)
                return {
                    "id": str(new_note_id),
                }
            else:
                raise InvalidAccessError()
        else:
            raise NotFoundError("Deck could not be found")
    raise InvalidDataError()
Esempio n. 7
0
def update_note_in_deck(deck_id, note_id, note_message, username):
    if note_message:
        validate_id(deck_id, "Deck ID")
        validate_id(note_id, "Note ID")
        deck = deck_repository.get_deck_details(deck_id)
        if deck is not None:
            if deck['username'] == username:
                edited_note = {"notes.$.message": note_message}
                result = note_repository.update_note_in_deck(
                    note_id, edited_note)
                if result.matched_count > 0:
                    return {"id": str(note_id), "message": note_message}
                else:
                    raise NotFoundError("Note could not be found")
            else:
                raise InvalidAccessError()
        else:
            raise NotFoundError("Deck could not be found")
    raise InvalidDataError()
Esempio n. 8
0
def delete_card_from_deck(deck_id, card_deck_id, username):
    validate_id(deck_id, "Deck ID")
    validate_id(card_deck_id, "Card Deck ID")
    verify_owner_from_deck_id(deck_id, username)
    return deck_repository.delete_card_from_deck(deck_id, card_deck_id)