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
7 changes: 5 additions & 2 deletions src/api/endpoints/annotate/all/get/queries/agency/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ class GetAgencySuggestionsQueryBuilder(QueryBuilderBase):

def __init__(
self,
url_id: int
url_id: int,
location_id: int | None = None
):
super().__init__()
self.url_id = url_id
self.location_id = location_id

async def run(self, session: AsyncSession) -> AgencyAnnotationResponseOuterInfo:
requester = GetAgencySuggestionsRequester(
session,
url_id=self.url_id
url_id=self.url_id,
location_id=self.location_id
)

user_suggestions: list[AgencyAnnotationUserSuggestion] = \
Expand Down
44 changes: 40 additions & 4 deletions src/api/endpoints/annotate/all/get/queries/agency/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
SuggestionsWithHighestConfidenceCTE
from src.db.helpers.session import session_helper as sh
from src.db.models.impl.agency.sqlalchemy import Agency
from src.db.models.impl.link.agency_location.sqlalchemy import LinkAgencyLocation
from src.db.models.impl.link.user_suggestion_not_found.agency.sqlalchemy import LinkUserSuggestionAgencyNotFound
from src.db.models.impl.url.suggestion.agency.user import UserUrlAgencySuggestion
from src.db.templates.requester import RequesterBase


class GetAgencySuggestionsRequester(RequesterBase):

def __init__(self, session: AsyncSession, url_id: int):
def __init__(

Check warning on line 20 in src/api/endpoints/annotate/all/get/queries/agency/requester.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/all/get/queries/agency/requester.py#L20 <107>

Missing docstring in __init__
Raw output
./src/api/endpoints/annotate/all/get/queries/agency/requester.py:20:1: D107 Missing docstring in __init__
self,
session: AsyncSession,
url_id: int,
location_id: int
):
super().__init__(session)
self.url_id = url_id
self.location_id = location_id

async def get_user_agency_suggestions(self) -> list[AgencyAnnotationUserSuggestion]:
query = (
Expand All @@ -31,7 +38,22 @@
Agency,
Agency.agency_id == UserUrlAgencySuggestion.agency_id
)
.where(

)

if self.location_id is not None:
query = (
query.join(
LinkAgencyLocation,
LinkAgencyLocation.agency_id == UserUrlAgencySuggestion.agency_id
)
.where(
LinkAgencyLocation.location_id == self.location_id
)
)

query = (
query.where(
UserUrlAgencySuggestion.url_id == self.url_id
)
.group_by(
Expand Down Expand Up @@ -64,11 +86,25 @@
cte.confidence,
Agency.name.label("agency_name"),
)
.outerjoin(
.join(
Agency,
Agency.agency_id == cte.agency_id
)
.where(
)

if self.location_id is not None:
query = (
query.join(
LinkAgencyLocation,
LinkAgencyLocation.agency_id == cte.agency_id
)
.where(
LinkAgencyLocation.location_id == self.location_id
)
)

query = (
query.where(
cte.url_id == self.url_id
)
.order_by(
Expand Down
16 changes: 16 additions & 0 deletions src/api/endpoints/annotate/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from fastapi import APIRouter, Depends, Query

from src.api.dependencies import get_async_core
from src.api.endpoints.annotate.all.get.models.agency import AgencyAnnotationResponseOuterInfo
from src.api.endpoints.annotate.all.get.models.response import GetNextURLForAllAnnotationResponse
from src.api.endpoints.annotate.all.get.queries.agency.core import GetAgencySuggestionsQueryBuilder
from src.api.endpoints.annotate.all.post.models.request import AllAnnotationPostInfo
from src.core.core import AsyncCore
from src.security.dtos.access_info import AccessInfo
Expand Down Expand Up @@ -59,4 +61,18 @@
batch_id=batch_id,
user_id=access_info.user_id,
url_id=anno_url_id
)

@annotate_router.get("/suggestions/agencies/{url_id}")
async def get_agency_suggestions(

Check warning on line 67 in src/api/endpoints/annotate/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/routes.py#L67 <103>

Missing docstring in public function
Raw output
./src/api/endpoints/annotate/routes.py:67:1: D103 Missing docstring in public function
url_id: int,
async_core: AsyncCore = Depends(get_async_core),
access_info: AccessInfo = Depends(get_access_info),

Check warning on line 70 in src/api/endpoints/annotate/routes.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/api/endpoints/annotate/routes.py#L70 <100>

Unused argument 'access_info'
Raw output
./src/api/endpoints/annotate/routes.py:70:5: U100 Unused argument 'access_info'
location_id: int | None = Query(default=None)
) -> AgencyAnnotationResponseOuterInfo:
return await async_core.adb_client.run_query_builder(
GetAgencySuggestionsQueryBuilder(
url_id=url_id,
location_id=location_id
)
)