2323use OCA \Tables \ResponseDefinitions ;
2424use OCA \Tables \Service \ColumnService ;
2525use OCA \Tables \Service \ImportService ;
26+ use OCA \Tables \Service \RelationService ;
2627use OCA \Tables \Service \RowService ;
2728use OCA \Tables \Service \ShareService ;
2829use OCA \Tables \Service \TableService ;
@@ -57,6 +58,7 @@ class Api1Controller extends ApiController {
5758 private RowService $ rowService ;
5859 private ImportService $ importService ;
5960 private ViewService $ viewService ;
61+ private RelationService $ relationService ;
6062 private ViewMapper $ viewMapper ;
6163 private IL10N $ l10N ;
6264
@@ -77,6 +79,7 @@ public function __construct(
7779 RowService $ rowService ,
7880 ImportService $ importService ,
7981 ViewService $ viewService ,
82+ RelationService $ relationService ,
8083 ViewMapper $ viewMapper ,
8184 V1Api $ v1Api ,
8285 LoggerInterface $ logger ,
@@ -90,6 +93,7 @@ public function __construct(
9093 $ this ->rowService = $ rowService ;
9194 $ this ->importService = $ importService ;
9295 $ this ->viewService = $ viewService ;
96+ $ this ->relationService = $ relationService ;
9397 $ this ->viewMapper = $ viewMapper ;
9498 $ this ->userId = $ userId ;
9599 $ this ->v1Api = $ v1Api ;
@@ -803,13 +807,77 @@ public function indexViewColumns(int $viewId): DataResponse {
803807 }
804808 }
805809
810+ /**
811+ * Get all relation data for a table
812+ *
813+ * @param int $tableId Table ID
814+ * @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{}>
815+ *
816+ * 200: Relation data returned
817+ * 403: No permissions
818+ * 404: Not found
819+ */
820+ #[NoAdminRequired]
821+ #[NoCSRFRequired]
822+ #[CORS ]
823+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_TABLE , idParam: 'tableId ' )]
824+ public function indexTableRelations (int $ tableId ): DataResponse {
825+ try {
826+ return new DataResponse ($ this ->relationService ->getRelationsForTable ($ tableId ));
827+ } catch (PermissionError $ e ) {
828+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
829+ $ message = ['message ' => $ e ->getMessage ()];
830+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
831+ } catch (InternalError $ e ) {
832+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
833+ $ message = ['message ' => $ e ->getMessage ()];
834+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
835+ } catch (NotFoundError $ e ) {
836+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
837+ $ message = ['message ' => $ e ->getMessage ()];
838+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
839+ }
840+ }
841+
842+ /**
843+ * Get all relation data for a view
844+ *
845+ * @param int $viewId View ID
846+ * @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{}>
847+ *
848+ * 200: Relation data returned
849+ * 403: No permissions
850+ * 404: Not found
851+ */
852+ #[NoAdminRequired]
853+ #[NoCSRFRequired]
854+ #[CORS ]
855+ #[RequirePermission(permission: Application::PERMISSION_READ , type: Application::NODE_TYPE_VIEW , idParam: 'viewId ' )]
856+ public function indexViewRelations (int $ viewId ): DataResponse {
857+ try {
858+ return new DataResponse ($ this ->relationService ->getRelationsForView ($ viewId ));
859+ } catch (PermissionError $ e ) {
860+ $ this ->logger ->warning ('A permission error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
861+ $ message = ['message ' => $ e ->getMessage ()];
862+ return new DataResponse ($ message , Http::STATUS_FORBIDDEN );
863+ } catch (InternalError $ e ) {
864+ $ this ->logger ->error ('An internal error or exception occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
865+ $ message = ['message ' => $ e ->getMessage ()];
866+ return new DataResponse ($ message , Http::STATUS_INTERNAL_SERVER_ERROR );
867+ } catch (NotFoundError $ e ) {
868+ $ this ->logger ->info ('A not found error occurred: ' . $ e ->getMessage (), ['exception ' => $ e ]);
869+ $ message = ['message ' => $ e ->getMessage ()];
870+ return new DataResponse ($ message , Http::STATUS_NOT_FOUND );
871+ }
872+ }
873+
806874 /**
807875 * Create a column
808876 *
809877 * @param int|null $tableId Table ID
810878 * @param int|null $viewId View ID
811879 * @param string $title Title
812- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
880+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
813881 * @param string|null $subtype Column sub type
814882 * @param bool $mandatory Is the column mandatory
815883 * @param string|null $description Description
@@ -1572,7 +1640,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
15721640 *
15731641 * @param int $tableId Table ID
15741642 * @param string $title Title
1575- * @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
1643+ * @param 'text'|'number'|'datetime'|'select'|'usergroup'|'relation' $type Column main type
15761644 * @param string|null $subtype Column sub type
15771645 * @param bool $mandatory Is the column mandatory
15781646 * @param string|null $description Description
0 commit comments