-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #865 from nextcloud/feat/archive-favorites
feat: Add backend for table archive and favorite flag
- Loading branch information
Showing
22 changed files
with
787 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Controller; | ||
|
||
use Exception; | ||
use OCA\Tables\Errors\InternalError; | ||
use OCA\Tables\Errors\NotFoundError; | ||
use OCA\Tables\Errors\PermissionError; | ||
use OCA\Tables\ResponseDefinitions; | ||
use OCA\Tables\Service\FavoritesService; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\DB\Exception as DBException; | ||
use OCP\IL10N; | ||
use OCP\IRequest; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @psalm-import-type TablesTable from ResponseDefinitions | ||
*/ | ||
class ApiFavoriteController extends AOCSController { | ||
private FavoritesService $service; | ||
|
||
public function __construct( | ||
IRequest $request, | ||
LoggerInterface $logger, | ||
FavoritesService $service, | ||
IL10N $n, | ||
string $userId) { | ||
parent::__construct($request, $logger, $n, $userId); | ||
$this->service = $service; | ||
} | ||
|
||
/** | ||
* [api v2] Add a node (table or view) to user favorites | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param int $nodeType | ||
* @param int $nodeId | ||
* @return DataResponse<Http::STATUS_OK, array{}, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}> | ||
* | ||
* 200: Tables returned | ||
*/ | ||
public function create(int $nodeType, int $nodeId): DataResponse { | ||
try { | ||
$this->service->addFavorite($nodeType, $nodeId); | ||
return new DataResponse(); | ||
} catch (NotFoundError $e) { | ||
return $this->handleNotFoundError($e); | ||
} catch (PermissionError $e) { | ||
return $this->handlePermissionError($e); | ||
} catch (InternalError|DBException|Exception $e) { | ||
return $this->handleError($e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* [api v2] Remove a node (table or view) to from favorites | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param int $nodeType | ||
* @param int $nodeId | ||
* @return DataResponse<Http::STATUS_OK, array{}, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}> | ||
* | ||
* 200: Deleted table returned | ||
* 403: No permissions | ||
* 404: Not found | ||
*/ | ||
public function destroy(int $nodeType, int $nodeId): DataResponse { | ||
try { | ||
$this->service->removeFavorite($nodeType, $nodeId); | ||
return new DataResponse(); | ||
} catch (NotFoundError $e) { | ||
return $this->handleNotFoundError($e); | ||
} catch (PermissionError $e) { | ||
return $this->handlePermissionError($e); | ||
} catch (InternalError|DBException|Exception $e) { | ||
return $this->handleError($e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** @noinspection PhpUnused */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\Exception; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version000800Date20240222000000 extends SimpleMigrationStep { | ||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
* @throws Exception | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
if ($schema->hasTable('tables_tables')) { | ||
$table = $schema->getTable('tables_tables'); | ||
$table->addColumn('archived', Types::BOOLEAN, [ | ||
'default' => false, | ||
'notnull' => true, | ||
]); | ||
} | ||
|
||
if (!$schema->hasTable('tables_favorites')) { | ||
$table = $schema->createTable('tables_favorites'); | ||
$table->addColumn('id', Types::BIGINT, [ | ||
'notnull' => true, | ||
'autoincrement' => true, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('node_type', Types::SMALLINT, [ | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('node_id', Types::BIGINT, [ | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('user_id', Types::STRING, [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
$table->addIndex(['user_id'], 'idx_tables_fav_uid'); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.