Skip to content

Commit 7c85ad0

Browse files
authored
Merge pull request #576 from Police-Data-Accessibility-Project/mc_506_pending_agency_edit
Add agency proposal edit logic
2 parents d060983 + 78923c4 commit 7c85ad0

File tree

25 files changed

+324
-21
lines changed

25 files changed

+324
-21
lines changed

src/api/endpoints/proposals/agencies/approve/__init__.py renamed to src/api/endpoints/proposals/agencies/by_id/__init__.py

File renamed without changes.

src/api/endpoints/proposals/agencies/get/__init__.py renamed to src/api/endpoints/proposals/agencies/by_id/approve/__init__.py

File renamed without changes.

src/api/endpoints/proposals/agencies/approve/query.py renamed to src/api/endpoints/proposals/agencies/by_id/approve/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy.exc import NoResultFound
44
from sqlalchemy.ext.asyncio import AsyncSession
55

6-
from src.api.endpoints.proposals.agencies.approve.response import ProposalAgencyApproveResponse
6+
from src.api.endpoints.proposals.agencies.by_id.approve.response import ProposalAgencyApproveResponse
77
from src.db.models.impl.agency.enums import JurisdictionType, AgencyType
88
from src.db.models.impl.agency.sqlalchemy import Agency
99
from src.db.models.impl.link.agency_location.sqlalchemy import LinkAgencyLocation

src/api/endpoints/proposals/agencies/approve/response.py renamed to src/api/endpoints/proposals/agencies/by_id/approve/response.py

File renamed without changes.

src/api/endpoints/proposals/agencies/reject/__init__.py renamed to src/api/endpoints/proposals/agencies/by_id/locations/__init__.py

File renamed without changes.

src/api/endpoints/proposals/agencies/by_id/locations/delete/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from sqlalchemy import delete
2+
from sqlalchemy.ext.asyncio import AsyncSession
3+
4+
from src.db.models.impl.link.agency_location.sqlalchemy import LinkAgencyLocation
5+
from src.db.models.impl.proposals.agency_.link__location import ProposalLinkAgencyLocation
6+
from src.db.queries.base.builder import QueryBuilderBase
7+
8+
9+
class DeleteProposalAgencyLocationQueryBuilder(QueryBuilderBase):
10+
11+
def __init__(
12+
self,
13+
agency_id: int,
14+
location_id: int,
15+
):
16+
super().__init__()
17+
self.agency_id = agency_id
18+
self.location_id = location_id
19+
20+
async def run(self, session: AsyncSession) -> None:
21+
statement = (
22+
delete(ProposalLinkAgencyLocation)
23+
.where(
24+
(ProposalLinkAgencyLocation.proposal_agency_id == self.agency_id)
25+
& (ProposalLinkAgencyLocation.location_id == self.location_id)
26+
)
27+
)
28+
29+
await session.execute(statement)
30+

src/api/endpoints/proposals/agencies/by_id/locations/get/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import Sequence
2+
3+
from sqlalchemy import select, RowMapping
4+
from sqlalchemy.ext.asyncio import AsyncSession
5+
6+
from src.api.endpoints.agencies.by_id.locations.get.response import AgencyGetLocationsResponse
7+
from src.api.endpoints.proposals.agencies.by_id.locations.get.response import ProposalAgencyGetLocationsOuterResponse
8+
from src.db.models.impl.link.agency_location.sqlalchemy import LinkAgencyLocation
9+
from src.db.models.impl.proposals.agency_.link__location import ProposalLinkAgencyLocation
10+
from src.db.models.views.location_expanded import LocationExpandedView
11+
from src.db.queries.base.builder import QueryBuilderBase
12+
13+
14+
class GetProposalAgencyLocationsQueryBuilder(QueryBuilderBase):
15+
16+
def __init__(
17+
self,
18+
agency_id: int,
19+
):
20+
super().__init__()
21+
self.agency_id = agency_id
22+
23+
async def run(self, session: AsyncSession) -> ProposalAgencyGetLocationsOuterResponse:
24+
query = (
25+
select(
26+
ProposalLinkAgencyLocation.location_id,
27+
LocationExpandedView.full_display_name
28+
)
29+
.where(
30+
ProposalLinkAgencyLocation.proposal_agency_id == self.agency_id
31+
)
32+
.join(
33+
LocationExpandedView,
34+
LocationExpandedView.id == ProposalLinkAgencyLocation.location_id
35+
)
36+
)
37+
38+
result: Sequence[RowMapping] = await self.sh.mappings(session, query=query)
39+
return ProposalAgencyGetLocationsOuterResponse(
40+
results=[AgencyGetLocationsResponse(**row) for row in result]
41+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pydantic import BaseModel
2+
3+
from src.api.endpoints.agencies.by_id.locations.get.response import AgencyGetLocationsResponse
4+
5+
6+
class ProposalAgencyGetLocationsOuterResponse(BaseModel):
7+
results: list[AgencyGetLocationsResponse]

0 commit comments

Comments
 (0)