forked from Support/sp-hydra-veil-gui
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from gui.v2.presenters.data.profile_data import convert_to_dto
|
|
from core.services.profiles.update_profile import update_profile
|
|
from core.controllers.ProfileController import ProfileController
|
|
from gui.v2.infrastructure.take_plumbing_action import take_action
|
|
from gui.v2.infrastructure.setup_observers import profile_observer
|
|
from core.utils.type_checker import type_checker
|
|
|
|
from typing import Callable
|
|
|
|
def create_profile(potential_data: dict, ui_caller: Callable):
|
|
"""Pass the data through the plumbing, to the controller to create a profile."""
|
|
take_action(
|
|
action=ProfileController.create,
|
|
ui_caller=ui_caller,
|
|
potential_data=potential_data,
|
|
profile_observer=profile_observer
|
|
)
|
|
|
|
@type_checker
|
|
def edit_profile(profile_id: int, location_down: bool, potential_data: dict, ui_caller: Callable):
|
|
"""Pass the data through the plumbing, to edit a profile."""
|
|
take_action(
|
|
action=update_profile,
|
|
ui_caller=ui_caller,
|
|
profile_id=profile_id,
|
|
new_choices=potential_data,
|
|
server_location_change=location_down
|
|
)
|
|
|
|
def get_all_profiles(ui_caller: Callable):
|
|
take_action(
|
|
action=ProfileController.get_all_serialized,
|
|
ui_caller=ui_caller
|
|
)
|
|
|
|
def format_to_dtos(all_profile_data: dict) -> dict:
|
|
"""Convert a dict with multiple profiles into a dict with DTOs"""
|
|
converted_dict = {}
|
|
for key, original_dict in all_profile_data.items():
|
|
converted_data = convert_to_dto(original_dict)
|
|
converted_dict[key] = converted_data
|
|
|
|
return converted_dict
|
|
|
|
|
|
def get_one_serialized_profile(profile_id: int, ui_caller: Callable):
|
|
"""Fetch from core a single serialized DTO for one profile id"""
|
|
take_action(
|
|
action=ProfileController.get_ONE_serialized,
|
|
profile_id=profile_id,
|
|
ui_caller=ui_caller
|
|
)
|
|
|
|
|