13
13
from robot_server .errors .error_responses import ErrorBody , ErrorDetails
14
14
from robot_server .service .json_api .request import RequestModel
15
15
from robot_server .service .json_api .response import SimpleBody , SimpleEmptyBody
16
+ from robot_server .service .notifications .publishers .client_data_publisher import (
17
+ ClientDataPublisher ,
18
+ get_client_data_publisher ,
19
+ )
16
20
17
21
router = fastapi .APIRouter ()
18
22
@@ -62,9 +66,13 @@ class ClientDataKeyDoesNotExist(ErrorDetails):
62
66
async def put_client_data ( # noqa: D103
63
67
key : Key ,
64
68
request_body : RequestModel [ClientData ],
65
- store : ClientDataStore = fastapi .Depends (get_client_data_store ),
69
+ store : Annotated [ClientDataStore , fastapi .Depends (get_client_data_store )],
70
+ client_data_publisher : Annotated [
71
+ ClientDataPublisher , fastapi .Depends (get_client_data_publisher )
72
+ ],
66
73
) -> SimpleBody [ClientData ]:
67
74
store .put (key , request_body .data )
75
+ await client_data_publisher .publish_client_data (key )
68
76
return SimpleBody .construct (data = store .get (key ))
69
77
70
78
@@ -104,7 +112,10 @@ async def get_client_data( # noqa: D103
104
112
)
105
113
async def delete_client_data ( # noqa: D103
106
114
key : Key ,
107
- store : ClientDataStore = fastapi .Depends (get_client_data_store ),
115
+ store : Annotated [ClientDataStore , fastapi .Depends (get_client_data_store )],
116
+ client_data_publisher : Annotated [
117
+ ClientDataPublisher , fastapi .Depends (get_client_data_publisher )
118
+ ],
108
119
) -> SimpleEmptyBody :
109
120
try :
110
121
store .delete (key )
@@ -113,6 +124,7 @@ async def delete_client_data( # noqa: D103
113
124
fastapi .status .HTTP_404_NOT_FOUND
114
125
) from e
115
126
else :
127
+ await client_data_publisher .publish_client_data (key )
116
128
return SimpleEmptyBody .construct ()
117
129
118
130
@@ -125,4 +137,8 @@ async def delete_all_client_data( # noqa: D103
125
137
store : ClientDataStore = fastapi .Depends (get_client_data_store ),
126
138
) -> SimpleEmptyBody :
127
139
store .delete_all ()
140
+ # FIXME(mm, 2024-07-24): We need to notify MQTT subscribers to
141
+ # `robot-server/client/{key}` (for all values of `key`).
142
+ # We can do it like RunsPublisher and drive the notifications from the underlying
143
+ # store instead of driving notifications from these endpoint functions.
128
144
return SimpleEmptyBody .construct ()
0 commit comments