Conversation
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
|
CC @nhoening |
Documentation build overview
Show files changed (4 files in total): 📝 4 modified | ➕ 0 added | ➖ 0 deleted
|
|
Thank you for requesting a review. It looks like the scope of this PR may be mistaken? You are creating an endpoint to copy all assets under a given account*, rather than an endpoint to copy a given asset, including all assets under it. |
|
We can also discuss the test strategy. Joshua chose to implement a part of the solution, then tests for that, then the next part, test for that etc. I believe we suggested initially to have one test case that tests a complete successful copy, then work on making it pass.
|
| "20 \u00b0C", | ||
| "3 * 230V * 16A" | ||
| ] | ||
| "description": "Quantity string describing a fixed quantity." |
| ] | ||
| } | ||
| }, | ||
| "/api/v3_0/assets/copy": {}, |
There was a problem hiding this comment.
I'd expect the API endpoint to live under "/api/v3_0/assets/<id>/copy".
flexmeasures/api/v3_0/assets.py
Outdated
| "account_id": fields.Int(required=True), | ||
| "target_account_id": fields.Int(required=True), |
There was a problem hiding this comment.
- Please move these to a new
class CopyAssetSchema(ma.Schema). - I'd propose two arguments for the
"/api/v3_0/assets/<id>/copy"endpoint:- account_id = AccountIdField(data_key="account", required=False) # defaults to the account of the asset whose ID is part of the endpoint
- parent_id = AssetIdField(data_key="parent", required=Flase) # defaults to the parent of the asset whose ID is part of the endpoint
- The schema should also (
@post_load):- If an account is explicitly given and no parent is explicitly given, then set parent to None, so it becomes a top-level asset (i.e. no parent) in the explicitly stated account
- If a parent is explicitly stated and no account is explicitly given, then set the account to the account of the parent, so that the copied asset belongs to the same account as the parent.
- Document that, if an account and parent are both explicitly stated, this makes it possible to create a copied asset that belongs to a different account than its parent. This is fine.
- Finally, the endpoint should check for create-children permissions using both the account and parent as context.
There was a problem hiding this comment.
I think I may have gotten this wrong, the current function actually copies over everything (asset) in the account, but from your feedback, it Is suppose to only cover a single asset(and its children along with sensors) that was specified
There was a problem hiding this comment.
I'm a bit confused. Why do we need to specify an account and a parent?
We can get this info from the asset we want to copy by asset.parent_asset_id.
If we are going to pass the asset ID in the URL, why are we not just copying that specified ID? As you said, with those two parameters, I can specify things outside the account.
I imagine the copy button on the UI will be in each asset detail page. When it is clicked on, a modal may pop up in which you need to select a target account to copy to.
There was a problem hiding this comment.
I also don't understand why these two are required.
There was a problem hiding this comment.
Suppose I have in a client's account two assets both with no parent representing two houses A and B. House A has a child asset representing an EV charger. I also have a house under my own account, house C. Here are some use cases:
1. Extra charger on house A
Copy charger asset with default account and parent. The new charger lives under house A next to the existing charger.
2. Same charger on house B
Copy charger asset with parent set to house B. The new charger lives under house B, and belongs to the same account.
3. Copy charger to my account
Copy charger asset with account set to my account. The new charger lives under my account, without a parent.
4. Copy charger to my house C
Parent asset is set to house C. Account defaults to the account of house C. New charger lives under house C and belongs to my account.
There was a problem hiding this comment.
I see, i think i get it now
There was a problem hiding this comment.
ive made updates to this, what do you think @Flix6x
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Description
This PR introduces an API allowing users to copy assets from one account to another, using the original account's assets as templates. The feature is currently in progress and being developed incrementally.
##TODO
Look & Feel
None
How to test
Further Improvements
Related Items
This PR closes #1966
Sign-off