Beispiel #1
0
def notify_chat_member(id_chat, message):
    # get chat data
    chat = get_chat(id_chat)
    id_receiver = ""
    if message["uid_sender"] == chat["uid_1"]:
        id_receiver = chat["uid_2"]
    else:
        id_receiver = chat["uid_1"]

    # get chat members data
    sender = user_repository.get_user(message["uid_sender"])
    receiver = user_repository.get_user(id_receiver)
    registration_token = receiver["fcmToken"]

    # notification payload.
    message_payload = {
        'title': sender["name"] + sender["last_name"],
        'body': message["message"],
        'channelId': 'Chat Channel',
        'senderId': message["uid_sender"],
        'senderProfileImage': sender["profile_image"],
        'receiverId': id_receiver,
        'group': id_chat,
        'timestamp': str(message["timestamp"])
    }

    messaging_repository.send_message_to_device(message_payload,
                                                registration_token)
    def test_unassign_order_updates_status_and_delivery(
            self, an_order, a_delivery_user):
        order_service.take(an_order.id, a_delivery_user.id)

        delivery = user_repository.get_user(a_delivery_user.id)
        assert not delivery.available

        order_service.update(an_order.id, {'status': Order.WAITING_STATUS})
        order = order_repository.get_order(an_order.id)
        delivery = user_repository.get_user(a_delivery_user.id)

        assert order.status == Order.WAITING_STATUS
        assert order.delivery is None
        assert order.quotation == 0
        assert delivery.available
    def test_deliver_order_updates_status_and_delivery(self, an_order,
                                                       a_delivery_user):
        order_service.deliver(an_order.id)

        order = order_repository.get_order(an_order.id)
        delivery = user_repository.get_user(a_delivery_user.id)

        assert order.status == Order.DELIVERED_STATUS
        assert order.delivery.id == a_delivery_user.id
        assert delivery.available
    def test_take_order_updates_status_and_delivery(self, an_order,
                                                    a_delivery_user):
        order_service.take(an_order.id, a_delivery_user.id)

        order = order_repository.get_order(an_order.id)
        delivery = user_repository.get_user(a_delivery_user.id)

        assert order.status == Order.TAKEN_STATUS
        assert order.delivery.id == a_delivery_user.id
        assert not delivery.available
Beispiel #5
0
def create(name,
           order_type,
           ordered_products,
           payment_method,
           owner,
           gratitude_points=0):
    user = user_repository.get_user(owner)
    if order_type == Order.FAVOR_TYPE and user.gratitude_points < gratitude_points:
        raise NotEnoughGratitudePointsException()

    return order_repository.create(name=name,
                                   order_type=order_type,
                                   owner=owner,
                                   ordered_products=ordered_products,
                                   payment_method=payment_method,
                                   number=order_repository.count() + 1,
                                   gratitude_points=gratitude_points)
def get_user(username):
    return user_repository.get_user(username)
def get_user():
    name = request.args["name"]
    if name:
        return jsonify(user_repository.get_user(name))
    else:
        return jsonify({"error": "NotFound"})