PROCESSED ADN REJECTED TAB TOO with their own specific conditions
parent
4bd02cefb0
commit
9f6926b1e1
|
|
@ -2,6 +2,7 @@ from fastapi import APIRouter,Depends, Query
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from db_setup import get_session
|
from db_setup import get_session
|
||||||
|
from inbox.enums import Candidate_application_Status
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from inbox.views import Email
|
from inbox.views import Email
|
||||||
from users.permissions import PermissionTag, require_permission
|
from users.permissions import PermissionTag, require_permission
|
||||||
|
|
@ -115,6 +116,7 @@ async def get_inbox_read_status(
|
||||||
@router.get("/inbox/all-applications")
|
@router.get("/inbox/all-applications")
|
||||||
async def get_all_applications(
|
async def get_all_applications(
|
||||||
record_id: str | None = Query(None),
|
record_id: str | None = Query(None),
|
||||||
|
application_status: Candidate_application_Status = Query(default=Candidate_application_Status.CLOSED),
|
||||||
isread: bool = Query(default=True),
|
isread: bool = Query(default=True),
|
||||||
search: str | None = Query(None),
|
search: str | None = Query(None),
|
||||||
top: int | None = Query(None),
|
top: int | None = Query(None),
|
||||||
|
|
@ -124,6 +126,9 @@ async def get_all_applications(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
service=Email(session=session)
|
service=Email(session=session)
|
||||||
|
if application_status == Candidate_application_Status.PROCESS or application_status==Candidate_application_Status.REJECTED:
|
||||||
|
items=await service.get_all_applications(top, skip, search, application_status=application_status)
|
||||||
|
total=await service.count_inbox_messages(search, application_status=application_status)
|
||||||
if isread==False:
|
if isread==False:
|
||||||
items=await service.get_all_applications(top, skip, search, isread=False)
|
items=await service.get_all_applications(top, skip, search, isread=False)
|
||||||
total=await service.count_inbox_messages(search, isread=False)
|
total=await service.count_inbox_messages(search, isread=False)
|
||||||
|
|
|
||||||
|
|
@ -196,15 +196,21 @@ class Inbox_Messages(SQLModel, table=True):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_inbox_messages(
|
async def get_inbox_messages(
|
||||||
cls, session: AsyncSession, top: int | None, skip: int, search: str | None, isread: bool=True
|
cls, session: AsyncSession, top: int | None, skip: int, search: str | None, isread: bool=True, application_status: Candidate_application_Status=Candidate_application_Status.CLOSED
|
||||||
):
|
):
|
||||||
statement = select(cls).order_by(cls.message_received_time.desc())
|
statement = select(cls).order_by(cls.message_received_time.desc())
|
||||||
if search:
|
if search:
|
||||||
statement = statement.where(cls._search_filter(search))
|
statement = statement.where(cls._search_filter(search))
|
||||||
|
|
||||||
|
if application_status == Candidate_application_Status.PROCESS or application_status==Candidate_application_Status.REJECTED:
|
||||||
|
statement = statement.where(cls.application_status==application_status)
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
statement = statement.offset(skip)
|
statement = statement.offset(skip)
|
||||||
|
|
||||||
if top is not None:
|
if top is not None:
|
||||||
statement = statement.limit(top)
|
statement = statement.limit(top)
|
||||||
|
|
||||||
if isread==False:
|
if isread==False:
|
||||||
statement = statement.where(cls.message_read==False)
|
statement = statement.where(cls.message_read==False)
|
||||||
result = await session.execute(statement)
|
result = await session.execute(statement)
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,19 @@ async def fetch_message_read_status(message_id, token=None):
|
||||||
|
|
||||||
|
|
||||||
def resolve_attachment_path(path_str:str) -> Path:
|
def resolve_attachment_path(path_str:str) -> Path:
|
||||||
"""Prefer stored path; fall back to basename under decoded_attachments."""
|
"""Prefer stored path; fall back to basename under decoded_attachments.
|
||||||
path=Path(path_str.strip())
|
|
||||||
|
Stored paths may be Windows absolutes written by the host API. The Taskiq
|
||||||
|
worker runs in Linux, where ``Path(r"D:\\...\\file.pdf").name`` is the
|
||||||
|
whole string (backslash is not a separator), so normalize separators before
|
||||||
|
taking the basename for the mounted attachments dir.
|
||||||
|
"""
|
||||||
|
raw=path_str.strip()
|
||||||
|
path=Path(raw)
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
return path
|
return path
|
||||||
fallback=_ATTACHMENTS_DIR/path.name
|
basename=Path(raw.replace("\\","/")).name
|
||||||
|
fallback=_ATTACHMENTS_DIR/basename
|
||||||
if fallback.is_file():
|
if fallback.is_file():
|
||||||
return fallback
|
return fallback
|
||||||
return path
|
return path
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import httpx,os
|
import httpx,os
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
from backend.inbox.enums import Candidate_application_Status
|
||||||
from inbox.models import Inbox_Messages
|
from inbox.models import Inbox_Messages
|
||||||
from inbox.file_decoder import decode_attachment
|
from inbox.file_decoder import decode_attachment
|
||||||
from inbox.serializers import serialize_application, serialize_message
|
from inbox.serializers import serialize_application, serialize_message
|
||||||
|
|
@ -91,7 +92,10 @@ class Email:
|
||||||
item["files"]=files
|
item["files"]=files
|
||||||
return item
|
return item
|
||||||
|
|
||||||
async def get_all_applications(self,top,skip,search=None,isread:bool=True):
|
async def get_all_applications(self,top,skip,search=None,isread:bool=True,application_status:Candidate_application_Status=Candidate_application_Status.CLOSED):
|
||||||
|
|
||||||
|
if application_status == Candidate_application_Status.PROCESS or application_status==Candidate_application_Status.REJECTED:
|
||||||
|
messages=await Inbox_Messages.get_inbox_messages(self.session,top,skip,search,application_status=application_status)
|
||||||
if isread==False:
|
if isread==False:
|
||||||
messages=await Inbox_Messages.get_inbox_messages(self.session,top,skip,search,isread)
|
messages=await Inbox_Messages.get_inbox_messages(self.session,top,skip,search,isread)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue