"""ReviewType. This is just a model sample. It depends on which database you want to use but basically make sure this file only contains methods and classes that are related to this model. """ from oto import response from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy import String from content_review.connectors import mysql class ReviewType(mysql.BaseModel): """ReviewType Model.""" __tablename__ = 'review_type' review_type_id = Column('id', Integer, primary_key=True, key='id') name = Column('name', String) description = Column('description', String) DEFAULT_FIELDS = { ReviewType.review_type_id, ReviewType.name, ReviewType.description } def get_review_types(flipped_dict=False): """Get all review types. Args: flipped_dict (bool): If true it returns named object with id as value Returns: response.Response: containing dict of review types or error. """ with mysql.db_session() as session: rows = session.query(*DEFAULT_FIELDS).all() response_data = {} if rows: if flipped_dict: for row in rows: response_data[row.name] = row.review_type_id else: response_data = [row._asdict() for row in rows] return response.Response(response_data) return response.create_not_found_response()