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)
def get_restaurants_tables(self, rest_id, capacity=None): url = f"{self.addr}/restaurants/{rest_id}/tables?" if capacity is not None: url += "capacity=" + str(capacity) if url[-1] == "?": url = url[:-1] return get(url)
def get_bookings(self, user=None, rest=None, table=None, begin=None, end=None, begin_entrance=None, end_entrance=None, with_user=True): """ Return the list of bookings. GET /bookings?[user=U_ID&][rest=R_ID&][table=T_ID&][begin=BEGING_DT&][end=END_DT&][begin_entrance=BEGING_ENT_DT&][end_entrance=END_ENT_DT&][with_user=true/false] It's possible to filter the bookings thanks the query's parameters. The parameters can be overlapped in any way. All paramters are optional. - user: All the booking of a specific user (by id) - rest: All the booking of a specific restaurant (by id) - table: All the booking of a specific table (by id) - begin: All bookings from a certain date onwards (datetime ISO 8601 - Chapter 5.6) - end: All bookings up to a certain date onwards (datetime ISO 8601 - Chapter 5.6) - begin_entrance: All bookings from a certain entrance date onwards (datetime ISO 8601 - Chapter 5.6) - end_entrance: All bookings up to a certain entrance date onwards (datetime ISO 8601 - Chapter 5.6) - with_user: If true adds at each bookings the user information If begin and not end is specified, all those starting from begin are taken. Same thing for end. Status Codes: 200 - OK 400 - Wrong datetime format """ url = self.addr + "/bookings?" if user is not None: url += "user="******"&" if rest is not None: url += "rest=" + str(rest) + "&" if table is not None: url += "table=" + str(table) + "&" if begin is not None: url += "begin=" + str(begin) + "&" if end is not None: url += "end=" + str(end) + "&" if begin_entrance is not None: url += "begin_entrance=" + str(begin_entrance) + "&" if end_entrance is not None: url += "end_entrance=" + str(end_entrance) + "&" if with_user: url += "with_user=true" return get(url)
def get_a_booking(self, id, with_user=True): """ Return a specific booking (request by id) GET /bookings/{booking_id}?[with_user=true/false] - with_user: [optional] If true adds the user information Status Codes: 200 - OK 404 - Booking not found """ url = self.addr + "/bookings/" + str(id) if with_user: url += "?with_user=true" return get(url)
def get_restaurants(self, name=None, opening_time=None, open_day=None, cuisine_type=None, menu=None): url = f"{self.addr}/restaurants?" if name is not None: url += "name=" + str(name) + "&" if opening_time is not None: url += "opening_time=" + str(opening_time) + "&" if open_day is not None: url += "open_day=" + str(open_day) + "&" if cuisine_type is not None: url += "cuisine_type=" + str(cuisine_type) + "&" if menu is not None: url += "menu=" + str(menu) + "&" if url[-1] == "&": url = url[:-1] if url[-1] == "?": url = url[:-1] return get(url)
def get_users(self, ssn=None, phone=None, email=None, is_positive=None): url = self.addr + "/users" params = '?' if ssn is not None: params += 'ssn=' + str(ssn) + '&' if phone is not None: params += 'phone=' + str(phone) + '&' if email is not None: params += 'email=' + str(email) + '&' if is_positive is True: params += 'is_positive=True' elif is_positive is False: params += 'is_positive=False' return get(url + params)
def get_notification(self, notification_id: int): return get(f"{self.addr}/notifications/{notification_id}")
def get_notifications(self, user_id: int, read: int = None): base_url = f"{self.addr}/notifications?user_id={user_id}" if read is not None: base_url += f"&read={'true' if read else 'false'}" return get(base_url)
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)
def get_user_contacts(self, user_id, begin, end): return get(f"{self.addr}/users/{user_id}/contacts?begin={begin}&end={end}")
def get_positive_users(self): return get(f"{self.addr}/users?is_positive=True")
def get_user(self, user_id: int): return get(f"{self.addr}/users/{user_id}")
def get_restaurants_table(self,rest_id, table_id): url = f"{self.addr}/restaurants/{rest_id}/tables/{table_id}" return get(url)
def get_restaurant_rate(self, rest_id): return get(f"{self.addr}/restaurants/{rest_id}/rate")
def get_restaurant(self, rest_id): return get(f"{self.addr}/restaurants/{rest_id}")