-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 644] Add a GET /opportunity/:opportunity-id endpoint (#660)
[Issue 644] Add a GET /opportunity/:opportunity-id endpoint --------- Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
- Loading branch information
1 parent
eab68da
commit c9503dd
Showing
5 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Any, Never | ||
|
||
from apiflask import abort | ||
from apiflask.types import ResponseHeaderType | ||
|
||
|
||
def raise_flask_error( # type: ignore | ||
status_code: int, | ||
message: str | None = None, | ||
detail: Any = None, | ||
headers: ResponseHeaderType | None = None, | ||
# TODO - when we work on validation error responses, we'll want to take in those here | ||
) -> Never: | ||
# Wrapper around the abort method which makes an error during API processing | ||
# work properly when APIFlask generates a response. | ||
# mypy doesn't realize this method never returns, so we define the same method | ||
# with a return type of Never. | ||
abort(status_code, message, detail, headers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from sqlalchemy import select | ||
|
||
import src.adapters.db as db | ||
from src.api.route_utils import raise_flask_error | ||
from src.db.models.opportunity_models import Opportunity | ||
|
||
|
||
def get_opportunity(db_session: db.Session, opportunity_id: int) -> Opportunity: | ||
# TODO - issue-642 - figure out if we want to filter by is_draft here as well | ||
|
||
opportunity: Opportunity | None = db_session.execute( | ||
select(Opportunity).where(Opportunity.opportunity_id == opportunity_id) | ||
).scalar_one_or_none() | ||
|
||
if opportunity is None: | ||
raise_flask_error(404, message=f"Could not find Opportunity with ID {opportunity_id}") | ||
|
||
return opportunity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters