Skip to content

Commit

Permalink
Add GET endpoints to retrieve one resource for responses, table-descr…
Browse files Browse the repository at this point in the history
…iptions and questions
  • Loading branch information
jcjc712 committed Oct 6, 2023
1 parent 0c262e7 commit 8e4df00
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dataherald/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def answer_question(self, question_request: QuestionRequest) -> Response:
def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
pass

@abstractmethod
def get_question(self, question_id: str) -> Question:
pass

@abstractmethod
def create_database_connection(
self, database_connection_request: DatabaseConnectionRequest
Expand Down Expand Up @@ -76,7 +80,7 @@ def list_table_descriptions(
pass

@abstractmethod
def get_responses(self, question_id: str | None = None) -> list[Response]:
def get_table_description(self, table_description_id: str) -> TableDescription:
pass

@abstractmethod
Expand All @@ -93,6 +97,14 @@ def execute_sql_query(self, query: Query) -> tuple[str, dict]:
def create_response(self, query_request: CreateResponseRequest) -> Response:
pass

@abstractmethod
def get_responses(self, question_id: str | None = None) -> list[Response]:
pass

@abstractmethod
def get_response(self, response_id: str) -> Response:
pass

@abstractmethod
def delete_golden_record(self, golden_record_id: str) -> dict:
pass
Expand Down
15 changes: 15 additions & 0 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ def list_table_descriptions(

return table_descriptions

@override
def get_table_description(self, table_description_id: str) -> TableDescription:
scanner_repository = TableDescriptionRepository(self.storage)
return scanner_repository.find_by_id(table_description_id)

@override
def get_responses(self, question_id: str | None = None) -> list[Response]:
response_repository = ResponseRepository(self.storage)
Expand All @@ -277,6 +282,11 @@ def get_responses(self, question_id: str | None = None) -> list[Response]:
query = {"question_id": ObjectId(question_id)}
return response_repository.find_by(query)

@override
def get_response(self, response_id: str) -> Response:
response_repository = ResponseRepository(self.storage)
return response_repository.find_by_id(response_id)

@override
def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
question_repository = QuestionRepository(self.storage)
Expand All @@ -285,6 +295,11 @@ def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
query = {"db_connection_id": ObjectId(db_connection_id)}
return question_repository.find_by(query)

@override
def get_question(self, question_id: str) -> Question:
question_repository = QuestionRepository(self.storage)
return question_repository.find_by_id(question_id)

@override
def add_golden_records(
self, golden_records: List[GoldenRecordRequest]
Expand Down
33 changes: 33 additions & 0 deletions dataherald/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def __init__(self, settings: Settings):
tags=["Table descriptions"],
)

self.router.add_api_route(
"/api/v1/table-descriptions/{table_description_id}",
self.get_table_description,
methods=["GET"],
tags=["Table descriptions"],
)

self.router.add_api_route(
"/api/v1/golden-records/{golden_record_id}",
self.delete_golden_record,
Expand Down Expand Up @@ -123,6 +130,13 @@ def __init__(self, settings: Settings):
tags=["Questions"],
)

self.router.add_api_route(
"/api/v1/questions/{question_id}",
self.get_question,
methods=["GET"],
tags=["Questions"],
)

self.router.add_api_route(
"/api/v1/responses",
self.create_response,
Expand All @@ -137,6 +151,13 @@ def __init__(self, settings: Settings):
tags=["Responses"],
)

self.router.add_api_route(
"/api/v1/responses/{response_id}",
self.get_response,
methods=["GET"],
tags=["Responses"],
)

self.router.add_api_route(
"/api/v1/sql-query-executions",
self.execute_sql_query,
Expand Down Expand Up @@ -193,6 +214,10 @@ def answer_question(self, question_request: QuestionRequest) -> Response:
def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
return self._api.get_questions(db_connection_id)

def get_question(self, question_id: str) -> Question:
"""Get a question"""
return self._api.get_question(question_id)

def root(self) -> dict[str, int]:
return {"nanosecond heartbeat": self._api.heartbeat()}

Expand Down Expand Up @@ -235,10 +260,18 @@ def list_table_descriptions(
"""List table descriptions"""
return self._api.list_table_descriptions(db_connection_id, table_name)

def get_table_description(self, table_description_id: str) -> TableDescription:
"""Get description"""
return self._api.get_table_description(table_description_id)

def get_responses(self, question_id: str | None = None) -> list[Response]:
"""List responses"""
return self._api.get_responses(question_id)

def get_response(self, response_id: str) -> Response:
"""Get a response"""
return self._api.get_response(response_id)

def execute_sql_query(self, query: Query) -> tuple[str, dict]:
"""Executes a query on the given db_connection_id"""
return self._api.execute_sql_query(query)
Expand Down

0 comments on commit 8e4df00

Please sign in to comment.