mirror of
https://github.com/bec-project/bec_atlas.git
synced 2025-07-14 07:01:48 +02:00
feat(user_data): added scan user data
This commit is contained in:
@ -187,12 +187,13 @@ class DatasetUserData(AccessProfile):
|
|||||||
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
|
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
|
||||||
|
|
||||||
|
|
||||||
class ScanUserData(MongoBaseModel, AccessProfile):
|
class ScanUserData(BaseModel):
|
||||||
scan_id: str
|
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
rating: int | None = None
|
user_rating: int | None = None
|
||||||
comments: str | None = None
|
system_rating: int | None = None
|
||||||
preview: bytes | None = None
|
user_comments: str | None = None
|
||||||
|
system_comments: str | None = None
|
||||||
|
preview: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class DeviceConfig(AccessProfile):
|
class DeviceConfig(AccessProfile):
|
||||||
|
@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends, Query
|
|||||||
|
|
||||||
from bec_atlas.authentication import get_current_user
|
from bec_atlas.authentication import get_current_user
|
||||||
from bec_atlas.datasources.mongodb.mongodb import MongoDBDatasource
|
from bec_atlas.datasources.mongodb.mongodb import MongoDBDatasource
|
||||||
from bec_atlas.model.model import ScanStatusPartial, UserInfo
|
from bec_atlas.model.model import ScanStatusPartial, ScanUserData, UserInfo
|
||||||
from bec_atlas.router.base_router import BaseRouter
|
from bec_atlas.router.base_router import BaseRouter
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +29,13 @@ class ScanRouter(BaseRouter):
|
|||||||
response_model=ScanStatusPartial,
|
response_model=ScanStatusPartial,
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
)
|
)
|
||||||
|
self.router.add_api_route(
|
||||||
|
"/scans/user_data",
|
||||||
|
self.update_scan_user_data,
|
||||||
|
methods=["PATCH"],
|
||||||
|
description="Update the user data of a scan",
|
||||||
|
response_model=dict,
|
||||||
|
)
|
||||||
|
|
||||||
async def scans(
|
async def scans(
|
||||||
self,
|
self,
|
||||||
@ -66,7 +73,10 @@ class ScanRouter(BaseRouter):
|
|||||||
async def scans_with_id(
|
async def scans_with_id(
|
||||||
self,
|
self,
|
||||||
scan_id: str,
|
scan_id: str,
|
||||||
include_user_data: bool = False,
|
filter: str | None = None,
|
||||||
|
fields: list[str] = Query(default=None),
|
||||||
|
offset: int = 0,
|
||||||
|
limit: int = 100,
|
||||||
current_user: UserInfo = Depends(get_current_user),
|
current_user: UserInfo = Depends(get_current_user),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -76,3 +86,28 @@ class ScanRouter(BaseRouter):
|
|||||||
scan_id (str): The scan id
|
scan_id (str): The scan id
|
||||||
"""
|
"""
|
||||||
return self.db.find_one("scans", {"_id": scan_id}, ScanStatusPartial, user=current_user)
|
return self.db.find_one("scans", {"_id": scan_id}, ScanStatusPartial, user=current_user)
|
||||||
|
|
||||||
|
async def update_scan_user_data(
|
||||||
|
self,
|
||||||
|
scan_id: str,
|
||||||
|
user_data: ScanUserData,
|
||||||
|
current_user: UserInfo = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Update the user data of a scan in the database.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
scan_id (str): The scan id
|
||||||
|
user_data (dict): The user data to update
|
||||||
|
"""
|
||||||
|
out = self.db.patch(
|
||||||
|
"scans",
|
||||||
|
id=scan_id,
|
||||||
|
update={"user_data": user_data.model_dump(exclude_defaults=True)},
|
||||||
|
dtype=ScanStatusPartial,
|
||||||
|
user=current_user,
|
||||||
|
return_document=True,
|
||||||
|
)
|
||||||
|
if out is None:
|
||||||
|
return {"message": "Scan not found."}
|
||||||
|
return {"message": "Scan user data updated."}
|
||||||
|
Reference in New Issue
Block a user