Example #1
0
    def updateReservation(self, reservation_id, json):
        reservation_dao = ReservationDAO()
        resourceReservation_dao = ResourceReservationDAO()
        if not reservation_dao.getReservationById(reservation_id):
            return jsonify(Error="Reservation not found."), 404
        else:
            customer_id = json["customer_id"]
            request_id = json["request_id"]
            reservation_date = json["reservation_date"]
            reservation_status = json["reservation_status"]
            resources = json["resources"]

            if customer_id and reservation_date and reservation_status and resources:
                reservation_dao.update(reservation_id, customer_id, request_id,
                                       reservation_date, reservation_status)

                for resource in resources:
                    resourceReservation_dao.update(
                        reservation_id, resource["resource_id"],
                        resource["reservation_quantity"])

                result = self.build_reservation_attributes(
                    reservation_id, customer_id, request_id, reservation_date,
                    reservation_status, resources)
                return jsonify(Reservation=result), 200
            else:
                return jsonify(
                    Error="Unexpected attributes in put request"), 400
Example #2
0
    def insertReservation(self, json):
        customer_id = json["customer_id"]
        request_id = json["request_id"]
        reservation_date = json["reservation_date"]
        reservation_status = json["reservation_status"]
        resources = json["resources"]

        if customer_id and reservation_date and reservation_status and resources:
            reservation_dao = ReservationDAO()
            resourceReservation_dao = ResourceReservationDAO()
            reservation_id = reservation_dao.insert(customer_id, request_id,
                                                    reservation_date,
                                                    reservation_status)

            for resource in resources:
                resourceReservation_dao.insert(
                    reservation_id, resource["resource_id"],
                    resource["reservation_quantity"])

            if request_id:
                request_dao = RequestDAO()
                request = request_dao.getRequestById(request_id)
                request_dao.update(request_id, request[0][1], request[0][2],
                                   request[0][3], request[0][4], "Accepted")

            result = self.build_reservation_attributes(reservation_id,
                                                       customer_id, request_id,
                                                       reservation_date,
                                                       reservation_status,
                                                       resources)
            return jsonify(Reservation=result), 201

        else:
            return jsonify(Error="Unexpected attributes in post request"), 400
Example #3
0
 def getReservationById(self, reservation_id):
     dao = ReservationDAO()
     row = dao.getReservationById(reservation_id)
     if not row:
         return jsonify(Error="Reservation Not Found"), 404
     else:
         reservation = self.fixDict(row)
         return jsonify(Reservation=reservation)
Example #4
0
 def deleteReservation(self, reservation_id):
     reservation_dao = ReservationDAO()
     resourceReservation_dao = ResourceReservationDAO()
     if not reservation_dao.getReservationById(reservation_id):
         return jsonify(Error="Reservation not found."), 404
     else:
         resourceReservation_dao.delete(reservation_id)
         reservation_dao.delete(reservation_id)
         return jsonify(DeleteStatus="OK"), 200
Example #5
0
 def getReservationsByCustomerId(self, customer_id):
     customer_dao = CustomerDAO()
     if not customer_dao.getCustomerById(customer_id):
         return jsonify(Error="Customer not found."), 404
     else:
         reservation_list = []
         dao = ReservationDAO()
         reservation_list = dao.getReservationsByCustomerId(customer_id)
         result_list = self.fixDict(reservation_list)
         return jsonify(Reservations=result_list)
Example #6
0
 def getResourcesByReservationId(self, reservation_id):
     reservation_dao = ReservationDAO()
     if not reservation_dao.getReservationById(reservation_id):
         return jsonify(Error="Reservation Not Found"), 404
     else:
         resources_list = []
         result_list = []
         resources_list = reservation_dao.getResourcesByReservationId(
             reservation_id)
         for row in resources_list:
             result = ResourceHandler().build_resource_dict(row)
             result_list.append(result)
         return jsonify(Resources=result_list)
Example #7
0
 def searchReservations(self, args):
     reservation_date = args.get("reservation_date")
     reservation_status = args.get("reservation_status")
     dao = ReservationDAO()
     reservation_list = []
     if (len(args) == 1) and reservation_date:
         reservation_list = dao.getReservationsByDate(reservation_date)
     elif (len(args) == 1) and reservation_status:
         reservation_list = dao.getReservationsByStatus(reservation_status)
     elif (len(args) == 2) and reservation_date and reservation_status:
         reservation_list = dao.getReservationsByDateAndStatus(
             reservation_date, reservation_status)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = self.fixDict(reservation_list)
     return jsonify(Reservations=result_list)
Example #8
0
 def getAllReservations(self):
     dao = ReservationDAO()
     reservation_list = dao.getAllReservations()
     result_list = self.fixDict(reservation_list)
     return jsonify(Reservations=result_list)