Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 3 - PB/MVP/src/backend/adapter/_in/web/ask_chatbot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
from domain.chat.chat_id import ChatId
from datetime import datetime, timezone

"""
This class is the controller for the use case AskChatbotUseCase. It receives the user's message and the chatId and returns a MessageResponse.
Attributes:
useCase (AskChatbotUseCase): The use case for asking the chatbot.
"""
class AskChatbotController:
def __init__(self, askChatbotUseCase: AskChatbotUseCase):
self.askChatbotUseCase = askChatbotUseCase

def askChatbot(self, message: str, chatId: int = None) -> MessageResponse:
"""
Receives the user's message and the chatId and returns a MessageResponse.
Args:
message (str): The user's message.
chatId (int): The chat's id.
Returns:
MessageResponse: the response of the operation.
"""
userMessage = Message(
message,
datetime.now(timezone.utc),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
from typing import List
from application.port._in.change_configuration_use_case import ChangeConfigurationUseCase
#from .configuration_service import ConfigurationService
from domain.configuration.configuration_operation_response import ConfigurationOperationResponse
from domain.configuration.llm_model_configuration import LLMModelType

"""
This class is the controller for the use case ChangeConfigurationUseCase. It receives the new LLM model and returns a ConfigurationOperationResponse.
Attributes:
useCase (ChangeConfigurationUseCase): The use case for changing the configuration.
"""

class ChangeConfigurationController:
def __init__(self, changeConfigurationUseCase: ChangeConfigurationUseCase): #configurationService: ConfigurationService
def __init__(self, changeConfigurationUseCase: ChangeConfigurationUseCase):
self.useCase = changeConfigurationUseCase

def changeLLMModel(self, LLModel: str) -> ConfigurationOperationResponse:
"""
Receives the new LLM model and returns a ConfigurationOperationResponse.
Args:
LLModel (str): The new LLM model.
Returns:
ConfigurationOperationResponse: the response of the operation.
"""
try:
LLMModelChoice = LLMModelType[LLModel.upper()]
return self.useCase.changeLLMModel(LLMModelChoice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
from domain.document.document_operation_response import DocumentOperationResponse
from domain.document.document_id import DocumentId

"""
This class is the controller for the use case ConcealDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse.
Attributes:
useCase (ConcealDocumentsUseCase): The use case for concealing documents.
"""
class ConcealDocumentsController:
def __init__(self, concealDocumentsUseCase: ConcealDocumentsUseCase):
self.useCase = concealDocumentsUseCase

def concealDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:

def concealDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:
"""
Receives the documents' ids and returns a list of DocumentOperationResponse.
Args:
documentsIds (List[str]): The documents' ids.
Returns:
List[DocumentOperationResponse]: the response of the operation.
"""
return self.useCase.concealDocuments([DocumentId(documentId) for documentId in documentsIds])
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
from typing import List
from domain.chat.chat_id import ChatId

"""
This class is the controller for the use case DeleteChatsUseCase. It receives the chats' ids and returns a list of ChatOperationResponse.
Attributes:
useCase (DeleteChatsUseCase): The use case for deleting chats.
"""
class DeleteChatsController:
def __init__(self, deleteChatUseCase: DeleteChatsUseCase):
self.useCase = deleteChatUseCase

def deleteChats(self, chatsIdsList: List[int]) -> List[ChatOperationResponse]:
"""
Receives the chats' ids and returns a list of ChatOperationResponse.
Args:
chatsIdsList (List[int]): The chats' ids.
Returns:
List[ChatOperationResponse]: the response of the operation.
"""
return self.useCase.deleteChats([ChatId(chatId) for chatId in chatsIdsList])
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
from domain.document.document_operation_response import DocumentOperationResponse
from domain.document.document_id import DocumentId

"""
This class is the controller for the use case DeleteDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse.
Attributes:
useCase (DeleteDocumentsUseCase): The use case for deleting documents.
"""
class DeleteDocumentsController:
def __init__(self, deleteDocumentsUseCase: DeleteDocumentsUseCase):
self.useCase = deleteDocumentsUseCase

def deleteDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:


def deleteDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:
"""
Receives the documents' ids and returns a list of DocumentOperationResponse.
Args:
documentsIds (List[str]): The documents' ids.
Returns:
List[DocumentOperationResponse]: the response of the operation.
"""
return self.useCase.deleteDocuments([DocumentId(documentId) for documentId in documentsIds])
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
from domain.document.document_operation_response import DocumentOperationResponse
from domain.document.document_id import DocumentId

"""
This class is the controller for the use case EmbedDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse.
Attributes:
useCase (EmbedDocumentsUseCase): The use case for embedding documents.
"""
class EmbedDocumentsController:
def __init__(self, embedDocumentsUseCase: EmbedDocumentsUseCase):
self.useCase = embedDocumentsUseCase

def embedDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:
"""
Receives the documents' ids and returns a list of DocumentOperationResponse.
Args:
documentsIds (List[str]): The documents' ids.
Returns:
List[DocumentOperationResponse]: the response of the operation.
"""
return self.useCase.embedDocuemnts([DocumentId(documentId) for documentId in documentsIds])
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
from domain.document.document_operation_response import DocumentOperationResponse
from domain.document.document_id import DocumentId

"""
This class is the controller for the use case EnableDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse.
Attributes:
useCase (EnableDocumentsUseCase): The use case for enabling documents.
"""
class EnableDocumentsController:
def __init__(self, enableDocumentsUseCase: EnableDocumentsUseCase):
self.useCase = enableDocumentsUseCase

def enableDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:

def enableDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]:
"""
Receives the documents' ids and returns a list of DocumentOperationResponse.
Args:
documentsIds (List[str]): The documents' ids.
Returns:
List[DocumentOperationResponse]: the response of the operation.
"""
return self.useCase.enableDocuments([DocumentId(documentId) for documentId in documentsIds])
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
from domain.chat.chat import Chat
from domain.chat.chat_id import ChatId


"""
This class is the controller for the use case GetChatMessagesUseCase. It receives the chat's id and returns the chat's messages.
Attributes:
useCase (GetChatMessagesUseCase): The use case for getting the chat's messages.
"""
class GetChatMessagesController:
def __init__(self, useCase: GetChatMessagesUseCase):
self.useCase = useCase
def __init__(self, getChatMessagesUseCase: GetChatMessagesUseCase):
self.useCase = getChatMessagesUseCase

def getChatMessages(self, chatId: int)->Chat:
def getChatMessages(self, chatId: int) -> Chat:
"""
Receives the chat's id and returns the chat's messages.
Args:
chatId (int): The chat's id.
Returns:
Chat: the chat containing the messages required.
"""
return self.useCase.getChatMessages(ChatId(chatId))
18 changes: 14 additions & 4 deletions 3 - PB/MVP/src/backend/adapter/_in/web/get_chats_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
from domain.chat.chat_filter import ChatFilter
from domain.chat.chat_preview import ChatPreview



"""
This class is the controller for the use case GetChatsUseCase. It receives the search filter and returns a list of ChatPreview.
Attributes:
useCase (GetChatsUseCase): The use case for getting chats.
"""
class GetChatsController:
def __init__(self, getChatsUseCase:GetChatsUseCase):
def __init__(self, getChatsUseCase: GetChatsUseCase):
self.useCase = getChatsUseCase

def getChats(self, searchFilter:str)-> List[ChatPreview]:
"""
Receives the search filter and returns a list of ChatPreview.
Args:
searchFilter (str): The search filter.
Returns:
List[ChatPreview]: the list of ChatPreview that match the search filter.
"""
filter = ChatFilter(searchFilter)
return self.useCase.getChats(filter)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
from application.port._in.get_configuration_use_case import GetConfigurationUseCase
from domain.configuration.configuration import Configuration

"""
This class is the controller for the use case GetConfigurationUseCase. It returns the current configuration.
Attributes:
useCase (GetConfigurationUseCase): The use case for getting the configuration.
"""
class GetConfigurationController:
def __init__(self, getConfigurationUseCase: GetConfigurationUseCase):
self.useCase = getConfigurationUseCase

def getConfiguration(self) -> Configuration:
"""
Returns the current configuration.
Returns:
Configuration: the current configuration.
"""
return self.useCase.getConfiguration()
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
from application.port._in.get_configuration_options_use_case import GetConfigurationOptionsUseCase
from domain.configuration.configuration_options import ConfigurationOptions

"""
This class is the controller for the use case GetConfigurationOptionsUseCase. It returns the current configuration options.
Attributes:
useCase (GetConfigurationOptionsUseCase): The use case for getting the configuration options.
"""
class GetConfigurationOptionsController:
def __init__(self, getConfigurationOptionsUseCase: GetConfigurationOptionsUseCase):
self.useCase = getConfigurationOptionsUseCase

def getConfigurationOptions(self) -> ConfigurationOptions:
"""
Returns the current configuration options.
Returns:
ConfigurationOptions: the current configuration options.
"""
return self.useCase.getConfigurationOptions()
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
from domain.document.document import Document
from domain.document.document_id import DocumentId


"""
This class is the controller for the use case GetDocumentsContentUseCase. It receives the document's id and returns the document's content.
Attributes:
useCase (GetDocumentsContentUseCase): The use case for getting the document's content.
"""
class GetDocumentContentController:
def __init__(self, getDocumentContentUseCase: GetDocumentsContentUseCase):
self.useCase = getDocumentContentUseCase

def getDocumentContent(self, documentId: str) -> Document:
"""
Receives the document's id and returns the document's content.
Args:
documentId (str): The document's id.
Returns:
Document: the Document containg the relative content.
"""
document = self.useCase.getDocumentsContent([DocumentId(documentId)])
return document[0]
21 changes: 16 additions & 5 deletions 3 - PB/MVP/src/backend/adapter/_in/web/get_documents_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

from application.port._in.get_documents_use_case import GetDocumentsUseCase
from domain.document.document_filter import DocumentFilter
from domain.document.document_id import DocumentId
from domain.document.light_document import LightDocument
from domain.exception.exception import ElaborationException
from api_exceptions import APIElaborationException


"""
This class is the controller for the use case GetDocumentsUseCase. It receives the search filter and returns a list of LightDocument.
Attributes:
useCase (GetDocumentsUseCase): The use case for getting documents.
"""
class GetDocumentsController:
def __init__(self, getDocumentsUseCase: GetDocumentsUseCase):
self.useCase = getDocumentsUseCase

def getDocuments(self, searchFilter: str) -> List[LightDocument]:
"""
Receives the search filter and returns a list of LightDocument.
Args:
searchFilter (str): The search filter.
Returns:
List[LightDocument]: the list of LightDocument that match the search filter.
"""
try:
return self.useCase.getDocuments(DocumentFilter(searchFilter))
# TODO: Catch specific exceptions (custom exception per Exception("Il numero di documenti e di status non corrisponde.") in GetDocumentsFacadeService)
except Exception as e:
return []
except ElaborationException as e:
raise APIElaborationException(e.message)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

"""
This module contains the NewDocument dataclass, which represents a new document to be uploaded to the system.
Attributes:
documentId (str): The document's id.
type (str): The document's type.
size (float): The document's size.
content (bytes): The document's content.
"""
@dataclass
class NewDocument:
Expand All @@ -22,6 +27,11 @@ class NewDocument:
content: bytes

def toDocument(self) -> Document:
"""
Converts the NewDocument to a Document.
Returns:
Document: The Document object.
"""
documentType = DocumentType.PDF if self.type.upper() == "PDF" else DocumentType.DOCX
return Document(
DocumentStatus(Status.ENABLED),
Expand Down
13 changes: 13 additions & 0 deletions 3 - PB/MVP/src/backend/adapter/_in/web/rename_chat_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
from domain.chat.chat_operation_response import ChatOperationResponse
from application.port._in.rename_chat_use_case import RenameChatUseCase

"""
This class is the controller for the use case RenameChatUseCase. It receives the chat's id and the new title and returns a ChatOperationResponse.
Attributes:
useCase (RenameChatUseCase): The use case for renaming a chat.
"""
class RenameChatController:
def __init__(self, renameChatUseCase: RenameChatUseCase):
self.useCase = renameChatUseCase

def renameChat(self, chatId: int, title: str) -> ChatOperationResponse:
"""
Receives the chat's id and the new title and returns a ChatOperationResponse.
Args:
chatId (int): The chat's id.
title (str): The new title.
Returns:
ChatOperationResponse: the response of the operation.
"""
self.useCase.renameChat(ChatId(chatId), title)
Loading