(20241203) Mails sync'ing, listing, and fetching done.

This commit is contained in:
2024-12-03 16:01:08 +05:30
parent 3b5a1fc92f
commit bef8f6ef0d
8 changed files with 137 additions and 223 deletions
+17 -14
View File
@@ -90,7 +90,7 @@ import datetime
# Related to Quart:
mail_retrieve_bp = Blueprint("mail_retrieve", __name__)
mail_list_bp = Blueprint("mail_list", __name__)
# *****************************************************************************************************************
@@ -110,7 +110,7 @@ mail_retrieve_bp = Blueprint("mail_retrieve", __name__)
# *****************************************************************************************************************
@mail_retrieve_bp.record_once
@mail_list_bp.record_once
def init(blueprint_setup_state):
# This gets called when the blueprint is registered.
@@ -121,7 +121,7 @@ def init(blueprint_setup_state):
# ---------------------------------------------------------------------------------------------------------------------
@mail_retrieve_bp.route("/list/account/id", methods = ["GET"])
@mail_list_bp.route("/list/account/id", methods = ["GET"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@get_session_info(key = "X-Session-Token", session_coro = "get_session")
@@ -137,19 +137,19 @@ def init(blueprint_setup_state):
@log_chain_to_mongo(attr_name = "logs_mongo")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@validate_input(
header_validator = lambda x: MailGetRequestHeaders(**x).model_dump(),
data_validator = lambda x: MailGetRequestData(**x)
header_validator = lambda x: MailListRequestHeaders(**x).model_dump(),
data_validator = lambda x: MailListByAccountIdRequestData(**x)
)
@handle_cancelled_request()
async def get_one_mail(
inbound_headers: dict | MailGetRequestHeaders = None,
inbound_data: dict | MailGetRequestData = None,
async def list_mails_for_account_id(
inbound_headers: dict | MailListRequestHeaders = None,
inbound_data: dict | MailListByAccountIdRequestData = None,
inbound_files: dict = None,
**kwargs
):
"""
Use this endpoint when the user wants to fetch one mail.
Use this endpoint when the user wants to fetch the list of mails.
:param inbound_headers: auto-extracted by the decorators.
:param inbound_data: auto-extracted by the decorators.
:param inbound_files: auto-extracted by the decorators.
@@ -165,16 +165,19 @@ async def get_one_mail(
)
# Get the mail:
mail_data = await current_app.mail_retrieve_model.get_mail(
mails_list = await current_app.mail_retrieve_model.list_for_account_identifier(
mongo_conn = current_app.data_mongo,
mail_identifier = inbound_data.mailId
account_identifier = inbound_data.accountId,
limit = inbound_data.count,
skip = inbound_data.fromCount
)
# Done here:
return ResponseModel(
status_code = StatusCodes.OK if mail_data else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if mail_data else HttpCodes.NOT_FOUND,
data = mail_data
status_code = StatusCodes.OK if mails_list else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if mails_list else HttpCodes.NOT_FOUND,
data = mails_list,
message = f"{len(mails_list) if mails_list else 0} mail(s) found"
)