-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add license information to the api #1482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f7901b2
added license info in get_feed
qcdyx 9185164
updated DatabaseCatalogAPI
qcdyx dcf6b6c
Merge branch 'main' into 1345-add-license-information-to-the-api
qcdyx c996d18
Merge branch 'main' into 1345-add-license-information-to-the-api
qcdyx 01fad67
updated endpoints
qcdyx a66420b
Added license API endpoint + feed license info
jcpitre a22871f
Merge branch 'main' into 1345-add-license-information-to-the-api
jcpitre 5857354
Changed types.ts. Adjusted limit for the licenses endpoint.
jcpitre da92b34
Removed an extra file committed by error.
jcpitre 2b98e07
gbfs types github action separation
Alessandro100 e91a2f9
Merge branch 'main' into 1345-add-license-information-to-the-api
jcpitre 1b21765
Modified licenses endpoint to return all data in rules.
jcpitre fc1ae95
Corrected the unit tests.
jcpitre afdb6a1
Returned [] of there are no rules.
jcpitre 26f8591
Updated types.ts
jcpitre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
56 changes: 56 additions & 0 deletions
56
.github/workflows/typescript-generator-gbfs-validator-types-check.yml
This file contains hidden or 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,56 @@ | ||
| name: Verify TypeScript GBFS Validator Types Generation | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "docs/GbfsValidator.yaml" | ||
|
|
||
| env: | ||
| NODE_VERSION: "18" | ||
|
|
||
| jobs: | ||
| generate-and-compare: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ env.NODE_VERSION }} | ||
| cache: 'yarn' | ||
| cache-dependency-path: 'web-app/yarn.lock' | ||
|
|
||
| - name: Cache Yarn dependencies | ||
| uses: actions/cache@v4 | ||
| id: yarn-cache | ||
| with: | ||
| path: | | ||
| **/node_modules | ||
| **/.eslintcache | ||
| key: ${{ runner.os }}-yarn-${{ hashFiles('web-app/yarn.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-yarn- | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: web-app | ||
| run: yarn install --frozen-lockfile --prefer-offline | ||
|
|
||
| - name: Generate TypeScript gbfs validator types | ||
| working-directory: web-app | ||
| run: yarn generate:gbfs-validator-types:output | ||
| env: | ||
| OUTPUT_PATH_TYPES: src/app/services/feeds/generated/gbfs-validator-types.ts | ||
|
|
||
| - name: Upload generated gbfs types | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: generated_types.ts | ||
| path: web-app/src/app/services/feeds/generated/gbfs-validator-types.ts | ||
|
|
||
| - name: Compare gbfs validator TypeScript types with existing types | ||
| working-directory: web-app | ||
| run: diff src/app/services/feeds/generated/gbfs-validator-types.ts src/app/services/feeds/gbfs-validator-types.ts || (echo "Gbfs Validator Types are different!" && exit 1) | ||
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| from typing import List, Optional | ||
|
|
||
| from feeds_gen.apis.licenses_api_base import BaseLicensesApi | ||
| from feeds_gen.models.license_with_rules import LicenseWithRules | ||
| from feeds_gen.models.license_base import LicenseBase | ||
| from shared.database.database import with_db_session | ||
| from shared.database_gen.sqlacodegen_models import License as LicenseOrm | ||
| from feeds.impl.error_handling import raise_http_error | ||
| from shared.db_models.license_with_rules_impl import LicenseWithRulesImpl | ||
| from shared.db_models.license_base_impl import LicenseBaseImpl | ||
|
|
||
|
|
||
| class LicensesApiImpl(BaseLicensesApi): | ||
| """ | ||
| Implementation for the Licenses API. | ||
| """ | ||
|
|
||
| @with_db_session | ||
| def get_license(self, id: str, db_session) -> LicenseWithRules: | ||
| """Return the license with the provided id.""" | ||
| try: | ||
| lic: Optional[LicenseOrm] = db_session.query(LicenseOrm).filter(LicenseOrm.id == id).one_or_none() | ||
| if not lic: | ||
| raise_http_error(404, f"License '{id}' not found") | ||
|
|
||
| return LicenseWithRulesImpl.from_orm(lic) | ||
| except Exception as e: | ||
| # Use raise_http_error to convert into an HTTPException with proper logging | ||
| raise_http_error(500, f"Error retrieving license: {e}") | ||
|
|
||
| @with_db_session | ||
| def get_licenses(self, limit: int, offset: int, db_session) -> List[LicenseBase]: | ||
| """Return a list of licenses (paginated).""" | ||
| try: | ||
| query = db_session.query(LicenseOrm).order_by(LicenseOrm.id) | ||
| if limit is not None: | ||
| query = query.limit(limit) | ||
| if offset is not None: | ||
| query = query.offset(offset) | ||
| results = query.all() | ||
|
|
||
| return [LicenseBaseImpl.from_orm(lic) for lic in results] | ||
| except Exception as e: | ||
| raise_http_error(500, f"Error retrieving licenses: {e}") |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from feeds_gen.models.license_base import LicenseBase | ||
| from pydantic import ConfigDict | ||
|
|
||
| from shared.database_gen.sqlacodegen_models import License as LicenseOrm | ||
|
|
||
|
|
||
| class LicenseBaseImpl(LicenseBase): | ||
| """Pydantic model hydratable directly from a License ORM row.""" | ||
|
|
||
| model_config = ConfigDict(from_attributes=True) | ||
|
|
||
| @classmethod | ||
| def from_orm(cls, license_orm: Optional[LicenseOrm]) -> Optional[LicenseBase]: | ||
| """Convert a SQLAlchemy License row into the base License model.""" | ||
| if not license_orm: | ||
| return None | ||
|
|
||
| return cls( | ||
| id=license_orm.id, | ||
| type=license_orm.type, | ||
| is_spdx=license_orm.is_spdx, | ||
| name=license_orm.name, | ||
| url=license_orm.url, | ||
| description=license_orm.description, | ||
| created_at=license_orm.created_at, | ||
| updated_at=license_orm.updated_at, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to @Alessandro100