2525use OCA \Tables \ResponseDefinitions ;
2626use OCA \Tables \Service \ColumnService ;
2727use OCA \Tables \Service \ImportService ;
28+ use OCA \Tables \Service \RelationService ;
2829use OCA \Tables \Service \RowService ;
2930use OCA \Tables \Service \ShareService ;
3031use OCA \Tables \Service \TableService ;
@@ -60,6 +61,7 @@ class Api1Controller extends ApiController {
6061 private RowService $ rowService ;
6162 private ImportService $ importService ;
6263 private ViewService $ viewService ;
64+ private RelationService $ relationService ;
6365 private ViewMapper $ viewMapper ;
6466 private IL10N $ l10N ;
6567
@@ -80,6 +82,7 @@ public function __construct(
8082 RowService $ rowService ,
8183 ImportService $ importService ,
8284 ViewService $ viewService ,
85+ RelationService $ relationService ,
8386 ViewMapper $ viewMapper ,
8487 V1Api $ v1Api ,
8588 LoggerInterface $ logger ,
@@ -93,6 +96,7 @@ public function __construct(
9396 $ this ->rowService = $ rowService ;
9497 $ this ->importService = $ importService ;
9598 $ this ->viewService = $ viewService ;
99+ $ this ->relationService = $ relationService ;
96100 $ this ->viewMapper = $ viewMapper ;
97101 $ this ->userId = $ userId ;
98102 $ this ->v1Api = $ v1Api ;
@@ -816,13 +820,77 @@ public function indexViewColumns(int $viewId): DataResponse {
816820 }
817821 }
818822
823+ /**
824+ * Get all relation data for a table
825+ *
826+ * @param int $tableId Table ID
827+ * @return DataResponse<Http::STATUS_OK, array<string, array<string, array{id: int, label: string}>>, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
828+ *
829+ * 200: Relation data returned
830+ * 403: No permissions
831+ * 404: Not found
832+ */
833+ #[NoAdminRequired]
834+ #[NoCSRFRequired]
835+ #[CORS ]
836+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_TABLE , idParam: 'tableId ' )]
837+ public function indexTableRelations (int $ tableId ): DataResponse {
838+ try {
839+ return new DataResponse ($ this ->relationService ->getRelationsForTable ($ tableId ));
840+ } catch (PermissionError $ e ) {
841+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
842+ $ message = ['message ' => $ e ->getMessage ()];
843+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
844+ } catch (InternalError $ e ) {
845+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
846+ $ message = ['message ' => $ e ->getMessage ()];
847+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
848+ } catch (NotFoundError $ e ) {
849+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
850+ $ message = ['message ' => $ e ->getMessage ()];
851+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
852+ }
853+ }
854+
855+ /**
856+ * Get all relation data for a view
857+ *
858+ * @param int $viewId View ID
859+ * @return DataResponse<Http::STATUS_OK, array<string, array<string, array{id: int, label: string}>>, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
860+ *
861+ * 200: Relation data returned
862+ * 403: No permissions
863+ * 404: Not found
864+ */
865+ #[NoAdminRequired]
866+ #[NoCSRFRequired]
867+ #[CORS ]
868+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_VIEW , idParam: 'viewId ' )]
869+ public function indexViewRelations (int $ viewId ): DataResponse {
870+ try {
871+ return new DataResponse ($ this ->relationService ->getRelationsForView ($ viewId ));
872+ } catch (PermissionError $ e ) {
873+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
874+ $ message = ['message ' => $ e ->getMessage ()];
875+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
876+ } catch (InternalError $ e ) {
877+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
878+ $ message = ['message ' => $ e ->getMessage ()];
879+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
880+ } catch (NotFoundError $ e ) {
881+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
882+ $ message = ['message ' => $ e ->getMessage ()];
883+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
884+ }
885+ }
886+
819887 /**
820888 * Create a column
821889 *
822890 * @param int|null $tableId Table ID
823891 * @param int|null $viewId View ID
824892 * @param string $title Title
825- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
893+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
826894 * @param string|null $subtype Column sub type
827895 * @param bool $mandatory Is the column mandatory
828896 * @param string|null $description Description
@@ -1600,7 +1668,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
16001668 *
16011669 * @param int $tableId Table ID
16021670 * @param string $title Title
1603- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
1671+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
16041672 * @param string|null $subtype Column sub type
16051673 * @param bool $mandatory Is the column mandatory
16061674 * @param string|null $description Description
0 commit comments