File tree Expand file tree Collapse file tree 11 files changed +447
-8
lines changed
data/data_wrappers/mcc_wrappers Expand file tree Collapse file tree 11 files changed +447
-8
lines changed Original file line number Diff line number Diff line change 1- from fastapi import APIRouter , Depends
2- from sqlmodel import Session , select
1+ from fastapi import APIRouter
32
43from gs .backend .api .v1 .mcc .models .responses import MainCommandsResponse
5- from gs .backend .data .database .engine import get_db_session
6- from gs .backend .data .tables .main_tables import MainCommand
4+ from gs .backend .data .data_wrappers .mcc_wrappers .main_command_wrapper import get_all_main_commands
75
86main_commands_router = APIRouter (tags = ["MCC" , "Main Commands" ])
97
108
119@main_commands_router .get ("/" )
12- async def get_main_commands (db_session : Session = Depends ( get_db_session ) ) -> MainCommandsResponse :
10+ async def get_main_commands () -> MainCommandsResponse :
1311 """
14- @brief Gets the main commands that are available for the MCC
12+ Gets the main commands that are available for the MCC
13+
14+ :return: list of all commands
1515 """
16- main_commands_query = select (MainCommand )
17- items = list (db_session .exec (main_commands_query ).all ())
16+ items = get_all_main_commands ()
1817 return MainCommandsResponse (data = items )
Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from uuid import UUID
3+
4+ from sqlmodel import select
5+
6+ from gs .backend .data .database .engine import get_db_session
7+ from gs .backend .data .tables .transactional_tables import Commands
8+
9+
10+ def get_all_commands () -> list [Commands ]:
11+ """
12+ Get all data wrapper for Commands
13+
14+ :return: a list of all commands
15+ """
16+ with get_db_session () as session :
17+ commands = list (session .exec (select (Commands )).all ())
18+ return commands
19+
20+
21+ def create_commands (command_data : dict [str , Any ]) -> Commands :
22+ """
23+ Post data wrapper for Commands
24+
25+ :param command_data: the JSON object of the command to be created
26+ :return: the newly created command
27+ """
28+ with get_db_session () as session :
29+ command = Commands (** command_data )
30+ session .add (command )
31+ session .commit ()
32+ session .refresh (command )
33+ return command
34+
35+
36+ def delete_commands_by_id (command_id : UUID ) -> Commands :
37+ """
38+ Delete data wrapper for Commands
39+
40+ :param command_id: UUID of command to be deleted
41+ :return: the deleted command
42+ """
43+ with get_db_session () as session :
44+ command = session .get (Commands , command_id )
45+ if not command :
46+ raise ValueError ("Command not found." )
47+ session .delete (command )
48+ session .commit ()
49+ return command
Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from uuid import UUID
3+
4+ from sqlmodel import select
5+
6+ from gs .backend .data .database .engine import get_db_session
7+ from gs .backend .data .tables .transactional_tables import CommsSession
8+
9+
10+ def get_all_comms_sessions () -> list [CommsSession ]:
11+ """
12+ Get all data wrapper for CommsSession
13+
14+ :return: a list of all sessions
15+ """
16+ with get_db_session () as session :
17+ sessions = list (session .exec (select (CommsSession )).all ())
18+ return sessions
19+
20+
21+ def create_comms_session (session_data : dict [str , Any ]) -> CommsSession :
22+ """
23+ Post data wrapper for CommsSession
24+
25+ :param session_data: the JSON object of the comms_session to be created
26+ :return: the newly created comms_session
27+ """
28+ with get_db_session () as session :
29+ comms_session = CommsSession (** session_data )
30+ session .add (comms_session )
31+ session .commit ()
32+ session .refresh (comms_session )
33+ return comms_session
34+
35+
36+ def delete_telemetry_by_id (session_id : UUID ) -> CommsSession :
37+ """
38+ Delete data wrapper for CommsSession
39+
40+ :param session_id: UUID of session to be deleted
41+ :return: the deleted session
42+ """
43+ with get_db_session () as session :
44+ comms_session = session .get (CommsSession , session_id )
45+ if not comms_session :
46+ raise ValueError ("Comms session not found." )
47+ session .delete (comms_session )
48+ session .commit ()
49+ return comms_session
Original file line number Diff line number Diff line change 1+ from typing import Any
2+
3+ from sqlmodel import select
4+
5+ from gs .backend .data .database .engine import get_db_session
6+ from gs .backend .data .tables .main_tables import MainCommand
7+
8+
9+ def get_all_main_commands () -> list [MainCommand ]:
10+ """
11+ Get all data wrapper for MainCommand
12+
13+ :return: a list of all main_commands
14+ """
15+ with get_db_session () as session :
16+ commands = list (session .exec (select (MainCommand )).all ())
17+ return commands
18+
19+
20+ def create_main_command (command_data : dict [str , Any ]) -> MainCommand :
21+ """
22+ Post data wrapper for MainCommand
23+
24+ :param command_data: the JSON object of the main_command to be created
25+ :return: the newly created main_command
26+ """
27+ with get_db_session () as session :
28+ command = MainCommand (** command_data )
29+ session .add (command )
30+ session .commit ()
31+ session .refresh (command )
32+ return command
33+
34+
35+ def delete_main_command_by_id (command_id : int ) -> MainCommand :
36+ """
37+ Delete data wrapper for MainCommand
38+
39+ :param command_id: id of main_command to be deleted
40+ :return: the deleted main_command
41+ """
42+ with get_db_session () as session :
43+ command = session .get (MainCommand , command_id )
44+ if not command :
45+ raise ValueError ("Main command not found." )
46+ session .delete (command )
47+ session .commit ()
48+ return command
Original file line number Diff line number Diff line change 1+ from typing import Any
2+
3+ from sqlmodel import select
4+
5+ from gs .backend .data .database .engine import get_db_session
6+ from gs .backend .data .tables .main_tables import MainTelemetry
7+
8+
9+ def get_all_main_telemetries () -> list [MainTelemetry ]:
10+ """
11+ Get all data wrapper for MainTelemetry
12+
13+ :return: a list of all main_telemetries
14+ """
15+ with get_db_session () as session :
16+ telemetries = list (session .exec (select (MainTelemetry )).all ())
17+ return telemetries
18+
19+
20+ def create_main_telemetry (telemetry_data : dict [str , Any ]) -> MainTelemetry :
21+ """
22+ Post data wrapper for MainTelemetry
23+
24+ :param command_data: the JSON object of the main_telemetry to be created
25+ :return: the newly created main_telemetry
26+ """
27+ with get_db_session () as session :
28+ telemetry = MainTelemetry (** telemetry_data )
29+ session .add (telemetry )
30+ session .commit ()
31+ session .refresh (telemetry )
32+ return telemetry
33+
34+
35+ def delete_main_telemetry_by_id (telemetry_id : int ) -> MainTelemetry :
36+ """
37+ Delete data wrapper for MainTelemetry
38+
39+ :param command_id: id of main_telemetry to be deleted
40+ :return: the deleted main_telemetry
41+ """
42+ with get_db_session () as session :
43+ telemetry = session .get (MainTelemetry , telemetry_id )
44+ if not telemetry :
45+ raise ValueError ("Main telemetry not found." )
46+ session .delete (telemetry )
47+ session .commit ()
48+ return telemetry
Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from uuid import UUID
3+
4+ from sqlmodel import select
5+
6+ from gs .backend .data .database .engine import get_db_session
7+ from gs .backend .data .tables .transactional_tables import PacketCommands
8+
9+
10+ def get_all_packet_commands () -> list [PacketCommands ]:
11+ """
12+ Get all data wrapper for PacketCommands
13+
14+ :return: a list of all packet_commands
15+ """
16+ with get_db_session () as session :
17+ commands = list (session .exec (select (PacketCommands )).all ())
18+ return commands
19+
20+
21+ def create_packet_command (command_data : dict [str , Any ]) -> PacketCommands :
22+ """
23+ Post data wrapper for PacketCommands
24+
25+ :param command_data: the JSON object of the packet_command to be created
26+ :return: the newly created packet_command
27+ """
28+ with get_db_session () as session :
29+ command = PacketCommands (** command_data )
30+ session .add (command )
31+ session .commit ()
32+ session .refresh (command )
33+ return command
34+
35+
36+ def delete_packet_command_by_id (command_id : UUID ) -> PacketCommands :
37+ """
38+ Delete data wrapper for PacketCommands
39+
40+ :param command_id: UUID of packet_command to be deleted
41+ :return: the deleted packet_command
42+ """
43+ with get_db_session () as session :
44+ command = session .get (PacketCommands , command_id )
45+ if not command :
46+ raise ValueError ("Packet command not found." )
47+ session .delete (command )
48+ session .commit ()
49+ return command
Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from uuid import UUID
3+
4+ from sqlmodel import select
5+
6+ from gs .backend .data .database .engine import get_db_session
7+ from gs .backend .data .tables .transactional_tables import PacketTelemetry
8+
9+
10+ def get_all_packet_telemetries () -> list [PacketTelemetry ]:
11+ """
12+ Get all data wrapper for PacketTelemetry
13+
14+ :return: a list of all packet_telemetries
15+ """
16+ with get_db_session () as session :
17+ telemetries = list (session .exec (select (PacketTelemetry )).all ())
18+ return telemetries
19+
20+
21+ def create_packet_telemetry (telemetry_data : dict [str , Any ]) -> PacketTelemetry :
22+ """
23+ Post data wrapper for PacketTelemetry
24+
25+ :param command_data: the JSON object of the packet_telemetry to be created
26+ :return: the newly created packet_telemetry
27+ """
28+ with get_db_session () as session :
29+ telemetry = PacketTelemetry (** telemetry_data )
30+ session .add (telemetry )
31+ session .commit ()
32+ session .refresh (telemetry )
33+ return telemetry
34+
35+
36+ def delete_packet_telemetry_by_id (telemetry_id : UUID ) -> PacketTelemetry :
37+ """
38+ Delete data wrapper for PacketTelemetry
39+
40+ :param command_id: UUID of packet_telemetry to be deleted
41+ :return: the deleted packet_telemetry
42+ """
43+ with get_db_session () as session :
44+ telemetry = session .get (PacketTelemetry , telemetry_id )
45+ if not telemetry :
46+ raise ValueError ("Packet telemetry not found." )
47+ session .delete (telemetry )
48+ session .commit ()
49+ return telemetry
Original file line number Diff line number Diff line change 1+ from typing import Any
2+ from uuid import UUID
3+
4+ from sqlmodel import select
5+
6+ from gs .backend .data .database .engine import get_db_session
7+ from gs .backend .data .tables .transactional_tables import Packet
8+
9+
10+ def get_all_packets () -> list [Packet ]:
11+ """
12+ Get all data wrapper for Packet
13+
14+ :return: a list of all packets
15+ """
16+ with get_db_session () as session :
17+ packets = list (session .exec (select (Packet )).all ())
18+ return packets
19+
20+
21+ def create_packet (packet_data : dict [str , Any ]) -> Packet :
22+ """
23+ Post data wrapper for Packet
24+
25+ :param packet_data: the JSON object of the packet to be created
26+ :return: the newly created packet
27+ """
28+ with get_db_session () as session :
29+ packet = Packet (** packet_data )
30+ session .add (packet )
31+ session .commit ()
32+ session .refresh (packet )
33+ return packet
34+
35+
36+ def delete_packet_by_id (packet_id : UUID ) -> Packet :
37+ """
38+ Delete data wrapper for Packet
39+
40+ :param packet_id: UUID of packet to be deleted
41+ :return: the deleted packet
42+ """
43+ with get_db_session () as session :
44+ packet = session .get (Packet , packet_id )
45+ if not packet :
46+ raise ValueError ("Packet not found." )
47+ session .delete (packet )
48+ session .commit ()
49+ return packet
You can’t perform that action at this time.
0 commit comments