Esempio n. 1
0
from caldavHandler import DAVHandler

__author__ = "mfernandes"

dh = DAVHandler("http://127.0.0.1:5190/", "admin-caldav", "FZiFFEE1Cc6FXtC8M4bjekrtbqLXyjeM")

# dh = DAVHandler("http://127.0.0.1:5190/testcaldav/meals.ics/", None, None)
# add_event(self, uid, event_name, start_timestamp):
dh.add_event("test-caldav", 123247, "Test5", 1447716529, 2)
Esempio n. 2
0
    def post(self):
        """
        Set a new reservation on the service and returns the ID assigned to that reservations.
        ---
        tags:
            - Reservations API
        parameters:
            - in: body
              name: reservation
              schema:
                type: object
                required:
                  - itemID
                  - quantity
                  - clientID
                  - username
                  - timestamp
                properties:
                  itemID:
                    type: integer
                    description: item ID for identification
                  quantity:
                    type: integer
                    description: quantity to be reserved
                  clientID:
                    type: integer
                    description: ID of the client that wants to make the reservation
                  username:
                    type: string
                    description: username of the user that wants to make the reservation
                  timestamp:
                    type: integer
                    description: the date tha the reservations is scheduled.

        responses:
            200:
              description: Returns the reservation ID that was generated.
              schema:
                type: object
                required:
                    - reservationID
                properties:
                  reservationID:
                    type: integer
                    description: The reservation ID generated
            401:
              description: Invalid itemID
              schema:
                type: string

            402:
              description: Invalid stock
              schema:
                type: string

        """
        if database_exists(DATABASE) is False:
            db.create_all()
        in_data = request.get_json(force=True)
        stock = Stock.query.filter_by(itemID=in_data['itemID']).first()
        if stock is None:
            return "401 Invalid itemID"
        if stock.stockQuantity < in_data['quantity']:
            return "402 Invalid stock"
        res = Reservations(stock.itemID,
                           in_data['quantity'],
                           in_data['clientID'],
                           in_data['username'],
                           in_data['timestamp'])

        db.session.add(res)
        stock.stockQuantity -= in_data['quantity']
        db.session.commit()

        reservation = Reservations.query.filter_by(itemID=stock.itemID, clientID=in_data['clientID']).first()
        dh = DAVHandler("http://127.0.0.1:5190/",
                        CALDAV_ADMIN_USER,
                        CALDAV_ADMIN_PASSWD,
                        )
        dh.add_event(reservation.username,
                     reservation.reservationID,
                     stock.itemName,
                     in_data['timestamp'],
                     in_data['quantity'])

        dh.add_event(stock.provider_name,
                     reservation.reservationID,
                     stock.itemName,
                     in_data['timestamp'],
                     in_data['quantity'])

        return {"reservationID": reservation.reservationID}