ReservationService.ReservationAPI package
Submodules
ReservationService.ReservationAPI.app module
ReservationService.ReservationAPI.checkin module
ReservationService.ReservationAPI.config module
ReservationService.ReservationAPI.noshow module
ReservationService.ReservationAPI.reservation module
ReservationService.ReservationAPI.service module
- class ReservationService.ReservationAPI.service.Service(*args, **kwargs)
Bases:
object- init_model(tables)
- static init_orm(model_config)
- query_api(api_name, request_method, request_params={}, headers={'Connection': 'keep-alive', 'Content-Type': 'application/json'}, body=None)
method used for api queries — api_name: registered api name in api_config request_method: “get”, “post”, “put”, “delete” request_params: request parameters headers: request headers body: request body — USAGE: api_config = { “api_name1”: “http:api1:5000/path/to/api”, “api_name2”: “http:api2:5000/path/to/api”, }
- query_db(query, args=(), retval=False)
method used for sql database queries — query: sql query args: sql query arguments retval: True for SELECT | FALSE for INSERT, DELETE, etc
- query_model(model_name)
Method used for orm database queries — USAGE: with self.query_model(<TABLE NAME>) as (conn, <TABLE>):
res = conn.execute(…)
— model_name: table name
- ReservationService.ReservationAPI.service.default_validator(col_type, val)
- ReservationService.ReservationAPI.service.insert_into_dict(dest, keys, vals)
- ReservationService.ReservationAPI.service.validate(self, data, optional=False, drop=False, exclude=[])
Validator method for request body. Injected into sqlalchemy Model. — USAGE: with self.query_model(<TABLE NAME>) as (conn, <TABLE>):
verified_json_body, status = <TABLE>.validate(<REQUEST BODY>) if status:
# validation success
- else:
# validation fail
— data: json dict — Returns dict of validated values mapped to model.
- ReservationService.ReservationAPI.service.validator(*args)
Decorator which decorates validation functions. — USAGE:
# single value validator @validator(“Reservation.user”) def reservation_date_validator(user): # example validator
- if user is cond:
return True
return False
# multiple value validator @validator(“Reservation.start_date”, “Reservation.end_date”) def reservation_date_validator(start_date, end_date): # example validator
- if start_date is cond and end_date is cond:
return True
return False
ReservationService.ReservationAPI.utils module
- ReservationService.ReservationAPI.utils.check_date_constraints(user_type, reservation_date)
This function checks if a user is authorized to make a reservation based on their user type and the reservation date constraints.
- Parameters:
user_type – The type of user making the reservation. It could be a regular user, a premium
user, or an admin user :param reservation_date: The date for which the reservation is being made. It should be in the format of ‘YYYY-MM-DD’ :return: a boolean value. It returns True if the reservation date is within the date constraints for the user type, and False otherwise.
- ReservationService.ReservationAPI.utils.check_start_end_time(new_reservation, room)
This function checks the validity of a reservation’s start and end times, ensuring they are within open hours and the start time is earlier than the end time.
- Parameters:
new_reservation – A dictionary containing information about a new reservation, including the
start time and end time.
- Returns:
either a string indicating an error message if the reservation’s start_time is later than
the end_time or if the reservation is not within the open hours, or it returns None if the reservation’s start_time and end_time are valid and within the open hours.
- ReservationService.ReservationAPI.utils.check_time_conflict(reservation_dict, connection=None, model=None, reservation_id=None)
This function checks for time conflicts between a new reservation and existing reservations in a database.
checks time conflict by checking for date, room, and start_time or end_time in between new_reservation
reservation_id is only used with PATCH
returns true if confilts exist, else false.
- ReservationService.ReservationAPI.utils.create_confirmation_email(reservation, room, creator, sender, title='[회의실 예약 시스템] 회의실 예약이 완료되었습니다. ', template_name='template.txt')
This function generates an email confirmation for a new reservation in a meeting room booking system.
- Parameters:
reservation – a dictionary containing information about the reservation, such as the
reservation date, start and end times, members attending, and reservation code :param room: The room parameter is a dictionary containing information about the reserved room, including its name, address, and other details :param creator: A dictionary containing the name and email of the person who created the reservation :param sender: The email address that sends out the alert emails :param title: The title of the email that will be sent out as a confirmation for the reservation, defaults to [회의실 예약 시스템] 회의실 예약이 완료되었습니다. (optional) :param template_name: The name of the file containing the email body template, defaults to template.txt (optional) :return: a dictionary with keys “title”, “text”, “sender”, and “receivers”. The values for these keys are generated based on the input parameters and the contents of a template file. The “title” key contains the email title, “text” contains the email body, “sender” contains the email address that sends out the alert emails, and “receivers” contains
- ReservationService.ReservationAPI.utils.is_admin(auth_info)
The function checks if the user is an admin based on their authentication information.
- Parameters:
auth_info – It is a dictionary containing information about the user’s authentication status.
It includes information such as the user’s ID, username, and the type of account (e.g. regular user or administrator).
- Returns:
a boolean value indicating whether the user is an admin or not. If the user is an admin,
the function returns True, otherwise it returns False.
- ReservationService.ReservationAPI.utils.is_authorized(auth_info, reservation)
check if user is authorized to change reservation - returns True if user is creator of reservation or admin - returns False otherwise
- ReservationService.ReservationAPI.utils.is_valid_token(response)
The function checks if a token is valid by verifying if the “status” key is present in the authentication information dictionary.
- Parameters:
auth_info – The auth_info parameter is a dictionary that contains information about an
authentication token.
- Returns:
a boolean value. If the “status” key is not present in the input dictionary “auth_info”, it
returns False. Otherwise, it returns the value associated with the “status” key, which is expected to be a boolean value indicating whether the token is valid or not.
- ReservationService.ReservationAPI.utils.protected()
This is a Python decorator function that protects endpoints requiring authorization by checking for a valid token. :return: A decorator function named “protected” is being returned. This decorator function takes in another function as an argument and returns a new function that wraps the original function with additional functionality to protect endpoints that require authorization. The new function checks if the user has a valid token and sets the “auth_info” attribute of the object before calling the original function. If the user is not authenticated, it returns a JSON
- ReservationService.ReservationAPI.utils.serialize(row)
The function serializes a row by converting it into a dictionary and then into a JSON object with string representation of non-serializable values.
- Parameters:
row – The parameter “row” is likely a dictionary or a row object from a database query result.
- Returns:
The function serialize is returning a dictionary that is created by converting the input
row into a JSON string using json.dumps, and then converting that JSON string back into a dictionary using json.loads. The default=str argument is used to ensure that any non-serializable values in the row dictionary are converted to strings before being serialized.
- ReservationService.ReservationAPI.utils.validate_members(members)
The function validates a list of members by checking if each member has valid keys and a valid email address.
- Parameters:
members – The parameter “members” is expected to be a list of dictionaries, where each
dictionary represents a member and contains two keys: “name” and “email”. The function validates that each member dictionary has exactly these two keys and that the email value is a valid email address format. If any of these :return: a boolean value. It returns True if the input members is a list of dictionaries where each dictionary has keys “name” and “email”, and the value of “email” is a valid email address. It returns False otherwise.