async def save_favorite_with_user(favorite: Favorite, current_user: User = Depends( deps.get_current_user)): favorite.userId = current_user.userId favorite = add_tenant_id_to_model(favorite, current_user) save_favorite(favorite, current_user) return favorite
async def save_last_snapshot_with_user(last_snapshot: LastSnapshot, current_user: User = Depends( deps.get_current_user)): last_snapshot.userId = current_user.userId last_snapshot = add_tenant_id_to_model(last_snapshot, current_user) save_last_snapshot(last_snapshot, current_user) return last_snapshot
async def create_dashboard(name: str, current_user: User = Depends( deps.get_current_user)): dashboard = ConsoleDashboard() dashboard = add_tenant_id_to_model(dashboard, current_user) dashboard.name = name dashboard.userId = current_user.userId return create_dashboard_to_storage(dashboard)
async def save_console_subject(subject: ConsoleSpaceSubject, current_user: User = Depends( deps.get_current_user)): subject = add_tenant_id_to_model(subject, current_user) for report in subject.reports: subject.reportIds.append(report.reportId) subject.reports = [] return update_console_subject(subject)
async def save_report(subject_id: str, report: Report, current_user: User = Depends(deps.get_current_user)): report = add_tenant_id_to_model(report, current_user) report.reportId = get_surrogate_key() new_report = create_report(report) subject = load_console_subject_by_id(subject_id, current_user) subject.reportIds.append(new_report.reportId) update_console_subject(subject) return new_report
async def update_console_space(console_space: ConsoleSpace, current_user: User = Depends( deps.get_current_user)): console_space = add_tenant_id_to_model(console_space, current_user) new_subject_ids = [] for subject in console_space.subjects: new_subject_ids.append(subject.subjectId) console_space.subjectIds = new_subject_ids console_space.userId = current_user.userId return save_console_space(console_space)
async def save_console_space_graph(console_space_graph: ConnectedSpaceGraphics, current_user: User = Depends( deps.get_current_user)): console_space_graph = add_tenant_id_to_model(console_space_graph, current_user) old_console_space_graph = load_console_space_graph( console_space_graph.connectId, current_user) console_space_graph.userId = current_user.userId if old_console_space_graph is None: create_console_space_graph(console_space_graph) else: update_console_space_graph(console_space_graph) return console_space_graph
def copy_template_to_console_space(template_ids, console_space: ConsoleSpace, current_user): if template_ids: for template_id in template_ids.split(","): template_space = load_console_space_by_id(template_id, current_user) for subject_id in template_space.subjectIds: subject: ConsoleSpaceSubject = load_console_subject_by_id( subject_id, current_user) subject.subjectId = None subject = add_tenant_id_to_model(subject, current_user) new_report_ids = [] for report_id in subject.reportIds: report: Report = load_report_by_id(report_id, current_user) report = add_tenant_id_to_model(report, current_user) report = create_report(report) subject.reports.append(report) new_report_ids.append(report.reportId) subject.reportIds = new_report_ids subject = create_console_subject_to_storage(subject) console_space.subjectIds.append(subject.subjectId) console_space.subjects.append(subject) return console_space
async def create_console_subject(connect_id, subject: ConsoleSpaceSubject = Body(...), current_user: User = Depends( deps.get_current_user)): subject = add_tenant_id_to_model(subject, current_user) if check_fake_id(subject.subjectId): subject.subjectId = None console_space = load_console_space_by_id(connect_id, current_user) for report in subject.reports: report.reportId = get_surrogate_key() subject.reportIds.append(report.reportId) subject = create_console_subject_to_storage(subject) console_space.subjectIds.append(subject.subjectId) save_console_space(console_space) return subject else: raise Exception("id is not fake ID")
async def connect_to_space(space_id, name, template_ids=None, current_user: User = Depends( deps.get_current_user)): console_space = ConsoleSpace() console_space = add_tenant_id_to_model(console_space, current_user) console_space.topics = load_topic_list_by_space_id(space_id, current_user) console_space.spaceId = space_id console_space.name = name console_space.userId = current_user.userId console_space.lastVisitTime = datetime.now().replace(tzinfo=None) if template_ids: console_space = copy_template_to_console_space(template_ids, console_space, current_user) console_space = save_console_space(console_space) return console_space
async def save_dashboard(dashboard: ConsoleDashboard, current_user: User = Depends(deps.get_current_user)): dashboard.userId = current_user.userId dashboard = add_tenant_id_to_model(dashboard, current_user) return update_dashboard_to_storage(dashboard)
async def update_report(report: Report, current_user: User = Depends(deps.get_current_user)): report = add_tenant_id_to_model(report, current_user) save_subject_report(report) return report