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 ;
@@ -815,13 +819,77 @@ public function indexViewColumns(int $viewId): DataResponse {
815819 }
816820 }
817821
822+ /**
823+ * Get all relation data for a table
824+ *
825+ * @param int $tableId Table ID
826+ * @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{}>
827+ *
828+ * 200: Relation data returned
829+ * 403: No permissions
830+ * 404: Not found
831+ */
832+ #[NoAdminRequired]
833+ #[NoCSRFRequired]
834+ #[CORS ]
835+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_TABLE , idParam: 'tableId ' )]
836+ public function indexTableRelations (int $ tableId ): DataResponse {
837+ try {
838+ return new DataResponse ($ this ->relationService ->getRelationsForTable ($ tableId ));
839+ } catch (PermissionError $ e ) {
840+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
841+ $ message = ['message ' => $ e ->getMessage ()];
842+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
843+ } catch (InternalError $ e ) {
844+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
845+ $ message = ['message ' => $ e ->getMessage ()];
846+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
847+ } catch (NotFoundError $ e ) {
848+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
849+ $ message = ['message ' => $ e ->getMessage ()];
850+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
851+ }
852+ }
853+
854+ /**
855+ * Get all relation data for a view
856+ *
857+ * @param int $viewId View ID
858+ * @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{}>
859+ *
860+ * 200: Relation data returned
861+ * 403: No permissions
862+ * 404: Not found
863+ */
864+ #[NoAdminRequired]
865+ #[NoCSRFRequired]
866+ #[CORS ]
867+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_VIEW , idParam: 'viewId ' )]
868+ public function indexViewRelations (int $ viewId ): DataResponse {
869+ try {
870+ return new DataResponse ($ this ->relationService ->getRelationsForView ($ viewId ));
871+ } catch (PermissionError $ e ) {
872+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
873+ $ message = ['message ' => $ e ->getMessage ()];
874+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
875+ } catch (InternalError $ e ) {
876+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
877+ $ message = ['message ' => $ e ->getMessage ()];
878+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
879+ } catch (NotFoundError $ e ) {
880+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
881+ $ message = ['message ' => $ e ->getMessage ()];
882+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
883+ }
884+ }
885+
818886 /**
819887 * Create a column
820888 *
821889 * @param int|null $tableId Table ID
822890 * @param int|null $viewId View ID
823891 * @param string $title Title
824- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
892+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
825893 * @param string|null $subtype Column sub type
826894 * @param bool $mandatory Is the column mandatory
827895 * @param string|null $description Description
@@ -1589,7 +1657,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
15891657 *
15901658 * @param int $tableId Table ID
15911659 * @param string $title Title
1592- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
1660+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
15931661 * @param string|null $subtype Column sub type
15941662 * @param bool $mandatory Is the column mandatory
15951663 * @param string|null $description Description
0 commit comments