Esempio n. 1
0
def verify_owner_from_deck_id(deck_id, username):
    deck_owner = deck_repository.get_owner_of_deck(deck_id)
    if deck_owner is not None:
        if deck_owner != username:
            raise InvalidAccessError()
    else:
        raise NotFoundError()
Esempio n. 2
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()
def get_user_details(username):
    user = user_repository.get_user_details(username)
    if user is not None:
        return {
            "username": username,
            "givenName": user['givenName'],
            "familyName": user['familyName']
        }
    raise NotFoundError()
Esempio n. 4
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. 5
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. 6
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. 7
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. 8
0
def verify_owner_from_deck(deck, username):
    if deck is not None:
        if deck['username'] != username:
            raise InvalidAccessError()
    else:
        raise NotFoundError()