1919use OCA \Tables \Service \FederationService ;
2020use OCA \Tables \Service \RowService ;
2121use OCA \Tables \Service \TableService ;
22+ use OCA \Tables \Service \ViewService ;
2223use OCP \AppFramework \Http ;
24+ use OCP \AppFramework \Http \Attribute \ApiRoute ;
2325use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
2426use OCP \AppFramework \Http \DataResponse ;
2527use OCP \IL10N ;
@@ -38,6 +40,7 @@ public function __construct(
3840 string $ userId ,
3941 protected RowService $ rowService ,
4042 private TableService $ tableService ,
43+ private ViewService $ viewService ,
4144 private FederationService $ federationService ,
4245 ) {
4346 parent ::__construct ($ request , $ logger , $ n , $ userId );
@@ -59,6 +62,7 @@ public function __construct(
5962 */
6063 #[NoAdminRequired]
6164 #[RequirePermission(permission: Application::PERMISSION_CREATE , typeParam: 'nodeCollection ' )]
65+ #[ApiRoute(verb: 'POST ' , url: '/api/2/{nodeCollection}/{nodeId}/rows ' , requirements: ['nodeCollection ' => '(tables|views) ' , 'nodeId ' => '(\d+) ' ])]
6266 public function createRow (string $ nodeCollection , int $ nodeId , mixed $ data ): DataResponse {
6367 if (is_string ($ data )) {
6468 $ data = json_decode ($ data , true );
@@ -71,12 +75,16 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
7175 $ tableId = $ viewId = null ;
7276 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
7377 $ tableId = $ nodeId ;
74- $ table = $ this ->tableService ->find ( $ nodeId , true );
75- if ( $ table-> isFederated ()) {
78+ if ( $ this ->tableService ->isFederated ( $ tableId )) {
79+ $ table = $ this -> tableService -> find ( $ nodeId , true );
7680 return new DataResponse ($ this ->federationService ->createRow ($ table , $ data ));
7781 }
7882 } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
7983 $ viewId = $ nodeId ;
84+ if ($ this ->viewService ->isFederated ($ viewId )) {
85+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
86+ return new DataResponse ($ this ->federationService ->createRow ($ view , $ data ));
87+ }
8088 }
8189
8290 $ newRowData = new RowDataInput ();
@@ -113,6 +121,7 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
113121 */
114122 #[NoAdminRequired]
115123 #[RequirePermission(permission: Application::PERMISSION_UPDATE , typeParam: 'nodeCollection ' )]
124+ #[ApiRoute(verb: 'PUT ' , url: '/api/2/{nodeCollection}/{nodeId}/rows/{rowId} ' , requirements: ['nodeCollection ' => '(tables|views) ' , 'nodeId ' => '(\d+) ' ])]
116125 public function updateRow (string $ nodeCollection , int $ nodeId , int $ rowId , mixed $ data ): DataResponse {
117126 if (is_string ($ data )) {
118127 $ data = json_decode ($ data , true );
@@ -121,12 +130,19 @@ public function updateRow(string $nodeCollection, int $nodeId, int $rowId, mixed
121130 return $ this ->handleBadRequestError (new BadRequestError ('Cannot update row: data input is invalid. ' ));
122131 }
123132 $ iNodeType = ConversionHelper::stringNodeType2Const ($ nodeCollection );
124- $ viewId = $ iNodeType === Application:: NODE_TYPE_VIEW ? $ nodeId : null ;
133+ $ tableId = $ viewId = null ;
125134 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
126- $ table = $ this ->tableService ->find ($ nodeId , true );
127- if ($ table ->isFederated ()) {
135+ $ tableId = $ nodeId ;
136+ if ($ this ->tableService ->isFederated ($ tableId )) {
137+ $ table = $ this ->tableService ->find ($ nodeId , true );
128138 return new DataResponse ($ this ->federationService ->updateRow ($ table , $ rowId , $ data ));
129139 }
140+ } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
141+ $ viewId = $ nodeId ;
142+ if ($ this ->viewService ->isFederated ($ viewId )) {
143+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
144+ return new DataResponse ($ this ->federationService ->updateRow ($ view , $ rowId , $ data ));
145+ }
130146 }
131147 try {
132148 return new DataResponse ($ this ->rowService ->updateSet ($ rowId , $ viewId , $ data , $ this ->userId , null )->jsonSerialize ());
@@ -154,17 +170,25 @@ public function updateRow(string $nodeCollection, int $nodeId, int $rowId, mixed
154170 */
155171 #[NoAdminRequired]
156172 #[RequirePermission(permission: Application::PERMISSION_DELETE , typeParam: 'nodeCollection ' )]
173+ #[ApiRoute(verb: 'DELETE ' , url: '/api/2/{nodeCollection}/{nodeId}/rows/{rowId} ' , requirements: ['nodeCollection ' => '(tables|views) ' , 'nodeId ' => '(\d+) ' ])]
157174 public function deleteRow (string $ nodeCollection , int $ nodeId , int $ rowId ): DataResponse {
158175 $ iNodeType = ConversionHelper::stringNodeType2Const ($ nodeCollection );
176+ $ tableId = $ viewId = null ;
159177 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
160- $ table = $ this ->tableService ->find ($ nodeId , true );
161- if ($ table ->isFederated ()) {
178+ $ tableId = $ nodeId ;
179+ if ($ this ->tableService ->isFederated ($ tableId )) {
180+ $ table = $ this ->tableService ->find ($ nodeId , true );
162181 return new DataResponse ($ this ->federationService ->deleteRow ($ table , $ rowId ));
163182 }
183+ } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
184+ $ viewId = $ nodeId ;
185+ if ($ this ->viewService ->isFederated ($ viewId )) {
186+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
187+ return new DataResponse ($ this ->federationService ->deleteRow ($ view , $ rowId ));
188+ }
164189 }
165190 try {
166- $ viewId = $ iNodeType === Application::NODE_TYPE_VIEW ? $ nodeId : null ;
167- return new DataResponse ($ this ->rowService ->delete ($ rowId , $ viewId , $ this ->userId )->jsonSerialize ());
191+ return new DataResponse ($ this ->rowService ->delete ($ rowId , $ viewId , $ this ->userId , $ tableId )->jsonSerialize ());
168192 } catch (NotFoundError $ e ) {
169193 return $ this ->handleNotFoundError ($ e );
170194 } catch (PermissionError $ e ) {
0 commit comments