Exemple #1
0
 def mark_user(self, user_id):
     user, status = get(f"{self.addr}/users/" + str(user_id))
     if status != 200 or user is None:
         return None, None
     user['is_positive'] = True
     user['positive_datetime'] = datetime.today().isoformat()
     return put(f"{self.addr}/users/" + str(user_id), json=user)
Exemple #2
0
    def edit_booking(self, booking_id, number_of_people=None, booking_datetime=None, entrance=False):

        """ Edit a booking.

        GET /bookings/{booking_id}?[entrance=true/false]

        Changes the number of people and/or the date of the booking. 
        Or marks the user's entry.

        The request to mark the entrance is made through the query parameter entrance (a boolean)

        Change requests are made through json objects with the following properties (both optional)
            - booking_datetime: the new requested datetime
            - number_of_people: the new requested number of people

        If one of the two fields is not set, the one already entered is recovered.
        If both are not entered the request is void (unless required to mark the entry()in this case the json is ignored).

        If entry is marked, other requests for changes are ignored (if the user has already entered the changes no longer make sense).
        Likewise, if the entry is marked, no more changes can be made.

        The booking must not have already passed, in the event of a change.

        Change of a booking may not always be possible (on the requested date there are no seats available, the restaurant is closed on that date ...)

        Status Codes:
            200 - OK
            400 - Wrong datetime or bad request (entry already marked)
            404 - Booking not found
            409 - Impossible to change the booking
            500 - Error in communicating with the restaurant service or problem with the database (try again)
        """

        booking = {
        }

        if number_of_people is not None:
            booking["number_of_people"] = number_of_people

        if booking_datetime is not None:
            booking["booking_datetime"] = booking_datetime

        url = self.addr + "/bookings/" + str(booking_id)

        if entrance:
            url += "?entrance=true"

        return put(url, booking)
Exemple #3
0
 def set_user_restaurant(self, user_id, rest_id):
     user,status = self.get_user(user_id)
     if user is None or status != 200:
         return None, 500
     if user['is_operator']:
         user = user.toDict()
         els = ["email", "firstname", "lastname", "phone", "dateofbirth", "password"]
         arr = []
         for k,v in user.items():
             if k not in els:
                 arr.append(k)
         for a in arr:
             del user[a]
         user['rest_id'] = rest_id
         return put(f"{self.addr}/users/{user_id}", json=user)
     else:
         return None, 400
Exemple #4
0
 def unmark_user(self, user_id):
     user, status = get(f"{self.addr}/users/" + str(user_id))
     if status != 200 or user is None:
         return None, None
     user['is_positive'] = False
     return put(f"{self.addr}/users/" + str(user_id), json=user)
Exemple #5
0
 def edit_user(self, user_id, userdata):
     return put(f"{self.addr}/users/"+str(user_id), json=userdata)
Exemple #6
0
 def edit_restaurants_table(self,rest_id, table_id, capacity):
     url = f"{self.addr}/restaurants/{rest_id}/tables/{table_id}"
     return put(url, json={"capacity":capacity})
Exemple #7
0
 def edit_restaurant(self, rest_id, json):
     return put(f"{self.addr}/restaurants/{rest_id}", json=json)