Skip to content

Commit

Permalink
Move /api/dev/asset to /api/v3_0 (#392)
Browse files Browse the repository at this point in the history
* move asset API from dev to v3

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* link asset API in v3 docs

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* point asset crud tests to new asset API location

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* simplify asset view

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* upgrade asset legacy table, so it is not in the way of a sensor getting deleted (asset gets also deleted)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* fix mock address for testing asset view responds

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* updating the list of add commands, which needed two deletions and two additions

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add a changelog entry for API work (can also become multiple)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* fix get_assets test: now the Supplier has two assets again (after sensor tests landed)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* docs: update the state of the data model transition

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* update API changelog

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* remove double fixture

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* Instantiate schemas outside of endpoint logic to minimize response time

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Forbid rather than ignore: id is dump_only and account_id is excluded from patching

Signed-off-by: F.N. Claessen <felix@seita.nl>

* No trailing slash is a RESTful recommendation

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Synchronize documentation

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Fix API listing for v3_0

Signed-off-by: F.N. Claessen <felix@seita.nl>

Co-authored-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
nhoening and Flix6x committed Mar 23, 2022
1 parent 5a3e592 commit e2f56df
Show file tree
Hide file tree
Showing 22 changed files with 317 additions and 157 deletions.
1 change: 1 addition & 0 deletions documentation/api/change_log.rst
Expand Up @@ -11,6 +11,7 @@ v3.0-0 | 2022-03-22

- Added REST endpoint for listing sensors: `/sensors` (GET).
- Added REST endpoint for managing sensor data: `/sensors/data` (GET, POST).
- Added REST endpoint for managing assets: `/assets` (GET, POST, PATCH, DELETE).
- [**Breaking change**] Switched to plural resource names for REST endpoints: `/users/<id>` (GET, PATCH) and `/users/<id>/password-reset` (PATCH).
- [**Breaking change**] Deprecated the following endpoints:

Expand Down
4 changes: 2 additions & 2 deletions documentation/api/v3_0.rst
Expand Up @@ -7,14 +7,14 @@ Summary
-------

.. qrefflask:: flexmeasures.app:create(env="documentation")
:modules: flexmeasures.api.v3_0.implementations.sensors, flexmeasures.api.v3_0.implementations.users
:modules: flexmeasures.api.v3_0.assets, flexmeasures.api.v3_0.sensors, flexmeasures.api.v3_0.users
:order: path
:include-empty-docstring:

API Details
-----------

.. autoflask:: flexmeasures.app:create(env="documentation")
:modules: flexmeasures.api.v3_0.implementations.sensors, flexmeasures.api.v3_0.implementations.users
:modules: flexmeasures.api.v3_0.assets, flexmeasures.api.v3_0.sensors, flexmeasures.api.v3_0.users
:order: path
:include-empty-docstring:
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -31,6 +31,7 @@ Infrastructure / Support
* Plugins can import common FlexMeasures classes (like ``Asset`` and ``Sensor``) from a central place, using ``from flexmeasures import Asset, Sensor`` [see `PR #354 <http://www.github.com/FlexMeasures/flexmeasures/pull/354>`_]
* Adapt CLI command for entering some initial structure (``flexmeasures add structure``) to new datamodel [see `PR #349 <http://www.github.com/FlexMeasures/flexmeasures/pull/349>`_]
* Align documentation requirements with pip-tools [see `PR #384 <http://www.github.com/FlexMeasures/flexmeasures/pull/384>`_]
* Beginning API v3.0 - more REST-like, supporting assets, users and sensor data [see `PR #390 <http://www.github.com/FlexMeasures/flexmeasures/pull/390>`_ and `PR #392 <http://www.github.com/FlexMeasures/flexmeasures/pull/392>`_]


v0.8.0 | January 24, 2022
Expand Down
4 changes: 2 additions & 2 deletions documentation/cli/commands.rst
Expand Up @@ -30,11 +30,11 @@ of which some are referred to in this documentation.
``flexmeasures add asset-type`` Create a new asset type.
``flexmeasures add asset`` Create a new asset.
``flexmeasures add sensor`` Add a new sensor.
``flexmeasures add weather-sensor`` Add a weather sensor.
``flexmeasures add external-weather-forecasts`` Collect weather forecasts from the DarkSky API.
``flexmeasures add beliefs`` Load beliefs from file.
``flexmeasures add forecasts`` Create forecasts.
``flexmeasures add schedule`` Create a charging schedule.
``flexmeasures add holidays`` Add holiday annotations to accounts and/or assets.
``flexmeasures add annotation`` Add annotation to accounts, assets and/or sensors.
``flexmeasures add toy-account`` Create a toy account, for tutorials and trying things.
================================================= =======================================

Expand Down
6 changes: 3 additions & 3 deletions documentation/dev/note-on-datamodel-transition.rst
Expand Up @@ -70,11 +70,11 @@ Here is a brief list:
- |uncheck_| `Deprecate old database models <https://github.com/FlexMeasures/flexmeasures/projects/11>`_: We are deprecating the Power, Price and Weather tables in favour of the TimedBelief table, and deprecating the Asset, Market and WeatherSensor tables in favour of the Sensor and GeneralizedAsset tables. We are doing this to clean up the code and database structure.


The state of the transition (January 2022, v0.8.0)
The state of the transition (March 2022, v0.9.0)
---------------------------------------------------

Project 9 was implemented, which moved a lot of structure over, as well as actual data and some UI (dashboard, assets). We believe that was the hardest part.
Project 9 was implemented with the release of v0.8.0. This work moved a lot of structure over, as well as actual data and some UI (dashboard, assets). We believe that was the hardest part.

We are now close to being able to deprecate the old database models and route the API to the new model (see project 11). The API for assets is still in place, but the new one is already working (at /api/dev/generic_assets) and is powering what is shown in the UI.
We are now working on deprecating the old database models (see project 11). As part of that move, we decided to begin the work on a new API version (v3) which supports only the new data model (and is more REST-like). The new APIs for assets and sensor data had already been working before (at /api/dev) and had been powering what is shown in the UI since v0.8.0.

We take care to support people on the old data model so the transition will be as smooth as possible, as we said above. One part of this is that the ``flexmeasures db upgrade`` command copies your data to the new model. Also, creating new data (e.g. old-style assets) creates new-style data (e.g. assets/sensors) automatically. However, some edge cases are not supported in this way. For instance, edited asset meta data might have to be re-entered later. Feel free to contact us to discuss the transition if needed.
2 changes: 0 additions & 2 deletions flexmeasures/api/dev/__init__.py
Expand Up @@ -5,9 +5,7 @@ def register_at(app: Flask):
"""This can be used to register FlaskViews."""

from flexmeasures.api.dev.sensors import SensorAPI
from flexmeasures.api.dev.assets import AssetAPI

dev_api_prefix = "/api/dev"

SensorAPI.register(app, route_prefix=dev_api_prefix)
AssetAPI.register(app, route_prefix=dev_api_prefix)
101 changes: 0 additions & 101 deletions flexmeasures/api/dev/assets.py

This file was deleted.

9 changes: 0 additions & 9 deletions flexmeasures/api/dev/tests/utils.py

This file was deleted.

2 changes: 2 additions & 0 deletions flexmeasures/api/v3_0/__init__.py
Expand Up @@ -2,6 +2,7 @@

from flexmeasures.api.v3_0.sensors import SensorAPI
from flexmeasures.api.v3_0.users import UserAPI
from flexmeasures.api.v3_0.assets import AssetAPI


def register_at(app: Flask):
Expand All @@ -11,3 +12,4 @@ def register_at(app: Flask):

SensorAPI.register(app, route_prefix=v3_0_api_prefix)
UserAPI.register(app, route_prefix=v3_0_api_prefix)
AssetAPI.register(app, route_prefix=v3_0_api_prefix)

0 comments on commit e2f56df

Please sign in to comment.