Skip to content
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

split OGC Features and Tiles endpoints factories #32

Merged
merged 12 commits into from
Mar 16, 2023

Conversation

vincentsarago
Copy link
Member

@vincentsarago vincentsarago commented Feb 28, 2023

closes #6

This PR split the endpoint factory in two: OGCFeaturesFactory and OGCTilesFactory which should enable user to build either the tiles service or features service individually.

The main issue is for creating the OGC features landing and conformances endpoints. I've added two ways:

  • within the OGCFeaturesFactory, by using the full=True option, this will add the / (landing) and /conformance endpoints but only referencing the features endpoint (no links to the Tiles endpoints).

    from tipg.factory import OGCFeaturesFactory
    from fastapi import FastAPI
    
    app = FastAPI(
        openapi_url="/api",
        docs_url="/api.html",
    )
    features = OGCFeaturesFactory(full=True)
    app.include_router(features, tags=["OGC Features API"])
  • in main.py, to have both tiles and features endpoints conformances and links. It is likely that a user who will want to add both / (landing), /conformance with tiles and features endpoints in it's own application will have to re-write both endpoints in its code 🤷‍♂️

IMO it's really annoying that both / and /conformance are part of the features specification 😬

Screenshot 2023-02-28 at 9 47 15 AM

"urlpath": str(request.url.path),
"urlparams": str(request.url.query),
},
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we create a simple function that can be used outside the factories

@abc.abstractmethod
def conforms_to(self) -> List[str]:
"""Endpoints conformances."""
...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each Factory should explicitly tell what they are conform to

@vincentsarago
Copy link
Member Author

@bitner any of this make sense? 😄

tipg/main.py Outdated
app.include_router(ogc_features.router, tags=["OGC Features API"])

ogc_tiles = OGCTilesFactory(templates=templates)
app.include_router(ogc_tiles.router, tags=["OGC Tiles API"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create the endpoints using the 2 factories

tipg/main.py Outdated Show resolved Hide resolved
@vincentsarago
Copy link
Member Author

vincentsarago commented Mar 14, 2023

latest version of FastAPI/starlette changed something in url_for encode/starlette#2050 which breaks tipg (and other project where I use url_path_for 😬 ) 🤷

@vincentsarago

This comment was marked as resolved.

@bitner bitner self-requested a review March 14, 2023 13:20
supported_tms: TileMatrixSets = default_tms

ogc_features: OGCFeaturesFactory = field(init=False)
ogc_tiles: OGCTilesFactory = field(init=False)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This factory combines both OGCFeaturesFactory and OGCTilesFactory factories.

tipg/factory.py Outdated Show resolved Hide resolved
tipg/factory.py Outdated Show resolved Hide resolved
tipg/factory.py Outdated Show resolved Hide resolved
"""Register factory Routes."""
...

def register_common_routes(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can will be reused in the 3 factories if with_common=True is set

)

return data
self.router.include_router(self.ogc_features.router, tags=["OGC Features API"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now use include_router method (without the prefix)

)

return data
self.router.include_router(self.ogc_tiles.router, tags=["OGC Tiles API"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-160 lines 💥

@vincentsarago
Copy link
Member Author

vincentsarago commented Mar 15, 2023

last commit refactored a bit how we add the OGC common endpoints. It's now defined at the base class level.

To Do

  • add tests for each Factory

@vincentsarago
Copy link
Member Author

@bitner this is ready 🙏

tipg/factory.py Outdated
]

def register_routes(self): # noqa: C901
"""Register OGC Features endpoints."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Register OGC Tiles endpoints.""" ???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

tipg/factory.py Outdated Show resolved Hide resolved
@vincentsarago vincentsarago merged commit 69cd3d3 into main Mar 16, 2023
@vincentsarago vincentsarago deleted the splitEndpointFactories branch March 16, 2023 14:19
@vincentsarago vincentsarago mentioned this pull request Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

split Features and Tiles endpoints in the Factory
2 participants