mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-04-30 07:34:07 +02:00
remove unused service exceptions & allow equally named folders
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
This commit is contained in:
parent
8035142973
commit
05b7ed7994
docs/externalapi
lib/Controller
tests/Unit/Controller
@ -356,7 +356,6 @@ Status codes:
|
|||||||
* **200**: Folder was created successfully
|
* **200**: Folder was created successfully
|
||||||
* **400**: Folder creation error, check the error object:
|
* **400**: Folder creation error, check the error object:
|
||||||
* **code**: 1: folder name is empty
|
* **code**: 1: folder name is empty
|
||||||
* **409**: Folder with given name exists already
|
|
||||||
|
|
||||||
In case of an HTTP 200, the created or already existing folder is returned in full in the response, e.g.:
|
In case of an HTTP 200, the created or already existing folder is returned in full in the response, e.g.:
|
||||||
|
|
||||||
@ -392,7 +391,6 @@ Status codes:
|
|||||||
* **200**: Folder was created successfully
|
* **200**: Folder was created successfully
|
||||||
* **400**: Folder creation error, check the error object:
|
* **400**: Folder creation error, check the error object:
|
||||||
* **code**: 1: folder name is empty
|
* **code**: 1: folder name is empty
|
||||||
* **409**: Folder with given name exists already
|
|
||||||
* Other ownCloud errors, see [Response Format](#response-format)
|
* Other ownCloud errors, see [Response Format](#response-format)
|
||||||
|
|
||||||
In case of an HTTP 200, the changed or already existing folder is returned in full in the response, e.g.:
|
In case of an HTTP 200, the changed or already existing folder is returned in full in the response, e.g.:
|
||||||
|
@ -18,8 +18,6 @@ use \OCP\AppFramework\Http;
|
|||||||
use \OCA\News\Service\FolderServiceV2;
|
use \OCA\News\Service\FolderServiceV2;
|
||||||
use \OCA\News\Service\ItemServiceV2;
|
use \OCA\News\Service\ItemServiceV2;
|
||||||
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
|
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
|
||||||
use \OCA\News\Service\Exceptions\ServiceConflictException;
|
|
||||||
use \OCA\News\Service\Exceptions\ServiceValidationException;
|
|
||||||
|
|
||||||
class FolderApiV2Controller extends ApiController
|
class FolderApiV2Controller extends ApiController
|
||||||
{
|
{
|
||||||
@ -79,10 +77,6 @@ class FolderApiV2Controller extends ApiController
|
|||||||
$response = null;
|
$response = null;
|
||||||
try {
|
try {
|
||||||
$response = $this->folderService->rename($this->getUserId(), $folderId, $name);
|
$response = $this->folderService->rename($this->getUserId(), $folderId, $name);
|
||||||
} catch (ServiceValidationException $ex) {
|
|
||||||
return $this->errorResponseV2($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
|
|
||||||
} catch (ServiceConflictException $ex) {
|
|
||||||
return $this->errorResponseV2($ex, Http::STATUS_CONFLICT);
|
|
||||||
} catch (ServiceNotFoundException $ex) {
|
} catch (ServiceNotFoundException $ex) {
|
||||||
return $this->errorResponseV2($ex, Http::STATUS_NOT_FOUND);
|
return $this->errorResponseV2($ex, Http::STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@ use OCA\News\Service\ItemServiceV2;
|
|||||||
use \OCP\AppFramework\Http;
|
use \OCP\AppFramework\Http;
|
||||||
|
|
||||||
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
|
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
|
||||||
use \OCA\News\Service\Exceptions\ServiceConflictException;
|
|
||||||
use \OCA\News\Service\Exceptions\ServiceValidationException;
|
|
||||||
|
|
||||||
use \OCA\News\Db\Folder;
|
use \OCA\News\Db\Folder;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
@ -96,21 +94,6 @@ class FolderApiV2ControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testCreateAlreadyExists()
|
|
||||||
{
|
|
||||||
$this->folderService->expects($this->once())
|
|
||||||
->method('purgeDeleted')
|
|
||||||
->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
|
|
||||||
$this->folderService->expects($this->once())
|
|
||||||
->method('create')
|
|
||||||
->will($this->throwException(new ServiceConflictException('exists')));
|
|
||||||
|
|
||||||
$response = $this->folderAPI->create('hi');
|
|
||||||
|
|
||||||
$this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testCreateInvalidFolderName()
|
public function testCreateInvalidFolderName()
|
||||||
{
|
{
|
||||||
$msg = 'exists';
|
$msg = 'exists';
|
||||||
@ -118,9 +101,6 @@ class FolderApiV2ControllerTest extends TestCase
|
|||||||
$this->folderService->expects($this->once())
|
$this->folderService->expects($this->once())
|
||||||
->method('purgeDeleted')
|
->method('purgeDeleted')
|
||||||
->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
|
->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
|
||||||
$this->folderService->expects($this->once())
|
|
||||||
->method('create')
|
|
||||||
->will($this->throwException(new ServiceValidationException($msg)));
|
|
||||||
|
|
||||||
$response = $this->folderAPI->create('hi');
|
$response = $this->folderAPI->create('hi');
|
||||||
|
|
||||||
@ -209,42 +189,15 @@ class FolderApiV2ControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testUpdateExists()
|
|
||||||
{
|
|
||||||
$folderId = 23;
|
|
||||||
$folderName = 'test';
|
|
||||||
|
|
||||||
$this->folderService->expects($this->once())
|
|
||||||
->method('rename')
|
|
||||||
->will(
|
|
||||||
$this->throwException(
|
|
||||||
new ServiceConflictException($this->msg)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->folderAPI->update($folderId, $folderName);
|
|
||||||
|
|
||||||
$this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testUpdateInvalidFolderName()
|
public function testUpdateInvalidFolderName()
|
||||||
{
|
{
|
||||||
$folderId = 23;
|
$folderId = 23;
|
||||||
$folderName = '';
|
$folderName = '';
|
||||||
|
|
||||||
$this->folderService->expects($this->once())
|
|
||||||
->method('rename')
|
|
||||||
->will(
|
|
||||||
$this->throwException(
|
|
||||||
new ServiceValidationException($this->msg)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->folderAPI->update($folderId, $folderName);
|
$response = $this->folderAPI->update($folderId, $folderName);
|
||||||
|
|
||||||
$data = $response->getData();
|
$data = $response->getData();
|
||||||
$this->assertEquals($this->msg, $data['error']['message']);
|
$this->assertEquals($this->msg, $data['error']['message']);
|
||||||
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user