-
Notifications
You must be signed in to change notification settings - Fork 0
Mongo persistence #7
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
11 commits
Select commit
Hold shift + click to select a range
fee98eb
removed errorDefinitions file, and placed into errors folder instead.…
3dd1518
changed all file, variable and class names. Updated dev packages to i…
f15feef
added typed-ast package to setup.cfg to pass lint check
90b6264
relocked pipfile and fixed issues to make lint pass
00285cd
made constants all caps (including enum members), more explicit retur…
727a5d2
added mongodb store, changed how objects are persisted so they can fa…
7cb89ca
Merge branch 'master' into mongoPersistence
rosesyrett dcaf84f
modified files to pass pre-commit checks and tests
d64540d
using motor to make store calls non blocking
8309507
abstracted the get_store functionality, took out side effects from st…
5d329a5
updated pipfile lock to include motor
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,10 +1,7 @@ | ||
| from . import config, server | ||
| from . import config, database, server | ||
| from ._version_git import __version__ | ||
|
|
||
| # __all__ defines the public API for the package. | ||
| # Each module also defines its own __all__. | ||
| __all__ = [ | ||
| "__version__", | ||
| "server", | ||
| "config", | ||
| ] | ||
|
|
||
| __all__ = ["__version__", "server", "config", "database"] |
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,5 @@ | ||
| import motor.motor_asyncio | ||
| from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase | ||
|
|
||
| client: AsyncIOMotorClient = motor.motor_asyncio.AsyncIOMotorClient() | ||
| database: AsyncIOMotorDatabase = client.test_db |
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
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 |
|---|---|---|
| @@ -1,52 +1,72 @@ | ||
| from typing import Dict, Union | ||
| from typing import Dict, Optional, Union | ||
|
|
||
| from fastapi import APIRouter, Body, Depends, Response | ||
| from fastapi import APIRouter, Body, Depends, Query, Response | ||
|
|
||
| from diffcalc_API.services import constraints as service | ||
| from diffcalc_API.stores.pickling import get_store | ||
| from diffcalc_API.stores.protocol import HklCalcStore | ||
| from diffcalc_API.stores.protocol import HklCalcStore, get_store | ||
|
|
||
| router = APIRouter(prefix="/constraints", tags=["constraints"]) | ||
|
|
||
|
|
||
| @router.get("/{name}") | ||
| async def get_constraints(name: str, store: HklCalcStore = Depends(get_store)): | ||
| content = await service.get_constraints(name, store) | ||
|
|
||
| async def get_constraints( | ||
| name: str, | ||
| store: HklCalcStore = Depends(get_store), | ||
| collection: Optional[str] = Query(default=None, example="B07"), | ||
| ): | ||
| content = await service.get_constraints(name, store, collection) | ||
| return Response(content=content, media_type="application/text") | ||
rosesyrett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @router.put("/{name}/set") | ||
| @router.post("/{name}") | ||
| async def set_constraints( | ||
| name: str, | ||
| constraints: Dict[str, Union[float, bool]] = Body( | ||
| example={"qaz": 0, "alpha": 0, "eta": 0} | ||
| ), | ||
| store: HklCalcStore = Depends(get_store), | ||
| collection: Optional[str] = Query(default=None, example="B07"), | ||
| ): | ||
| await service.set_constraints(name, constraints, store) | ||
| await service.set_constraints(name, constraints, store, collection) | ||
|
|
||
| return {"message": f"constraints updated (replaced) for crystal {name}"} | ||
| return { | ||
| "message": ( | ||
| f"constraints updated (replaced) for crystal {name} in " | ||
| + f"collection {collection}" | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| @router.patch("/{name}/unconstrain/{property}") | ||
| @router.delete("/{name}/{property}") | ||
| async def remove_constraint( | ||
| name: str, | ||
| property: str, | ||
| store: HklCalcStore = Depends(get_store), | ||
| collection: Optional[str] = Query(default=None, example="B07"), | ||
| ): | ||
| await service.remove_constraint(name, property, store) | ||
| await service.remove_constraint(name, property, store, collection) | ||
|
|
||
| return {"message": f"unconstrained {property} for crystal {name}. "} | ||
| return { | ||
| "message": ( | ||
| f"unconstrained {property} for crystal {name} in " | ||
| + f"collection {collection}. " | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| @router.patch("/{name}/constrain/{property}") | ||
| @router.patch("/{name}/{property}") | ||
| async def set_constraint( | ||
| name: str, | ||
| property: str, | ||
| value: Union[float, bool] = Body(...), | ||
| store: HklCalcStore = Depends(get_store), | ||
| collection: Optional[str] = Query(default=None, example="B07"), | ||
| ): | ||
| await service.set_constraint(name, property, value, store) | ||
| await service.set_constraint(name, property, value, store, collection) | ||
|
|
||
| return {"message": f"constrained {property} for crystal {name}. "} | ||
| return { | ||
| "message": ( | ||
| f"constrained {property} for crystal {name} in collection " | ||
| + f"{collection}. " | ||
| ) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.