Commit a82f469b authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Fix bugs and finish api doc generation

parent 61ec041b
......@@ -7,7 +7,7 @@ APP_NAME=doorcode
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=https://elock.cs.wallawalla.edu
DB_CONNECTION=doorcode
DB_DRIVER=pgsql
......
......@@ -65,6 +65,10 @@ class GroupsController extends ApiController
* This endpoint removes a group from the system.
*
* @authenticated
* @urlParam groupId required The id of the group to delete. Example: 7
*
* @response 400 {"status":"error","code":400,"message":"Cannot delete a default permission group"}
* @response 404 {"status":"error","code":404,"message":"Entity not found"}
*
* @param \Source\UseCases\Groups\DeleteGroup\DeleteGroupUseCase $useCase
* @param string $groupId
......@@ -81,6 +85,7 @@ class GroupsController extends ApiController
try {
$useCase->delete($groupId, $presenter);
} catch (DeleteFailedException $e) {
$this->setStatusCode(400);
return $this->respondWithError($e->getMessage());
}
......@@ -125,7 +130,9 @@ class GroupsController extends ApiController
* This endpoint gets a groups.
*
* @authenticated
* @urlParam groupId required The ID of the group to get all information from.
* @urlParam groupId required The ID of the group to get all information from. Example: 1
*
* @response 404 {"status":"error","code":404,"message":"Entity not found"}
*
* @param \Source\UseCases\Groups\GetGroup\GetGroupUseCase $useCase
* @param string $groupId
......@@ -154,6 +161,8 @@ class GroupsController extends ApiController
* @bodyParam title string required The new title of the group.
* @bodyParam description string required The new group description.
*
* @response 404 {"status":"error","code":404,"message":"Entity not found"}
*
* @param \Source\UseCases\Groups\UpdateGroup\UpdateGroupUseCase $useCase
* @param string $groupId
* @return \Illuminate\Http\JsonResponse
......
......@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Source\Authorization\Permissions;
use Source\Gateways\Tokens\TokensRepository;
use Source\UseCases\Tokens\GetToken\GetTokenUseCase;
use Source\UseCases\Tokens\GetTokens\GetTokensUseCase;
use Source\UseCases\Tokens\CreateToken\CreateTokenUseCase;
......
......@@ -40,7 +40,7 @@ class UsersController extends ApiController
*
* @authenticated
* @paginated
* @queryParam query The query to search on Example: admin
* @queryParam query The query to search on. Example: sheev
*
* @param \Source\UseCases\Users\GetUsers\GetUsersUseCase $getAllUsers
* @return \Illuminate\Http\JsonResponse
......@@ -105,7 +105,7 @@ class UsersController extends ApiController
* @bodyParam emplid string The users employee id. Example: 239990
* @bodyParam password string The users local application password. Example: This is a better password than 99%
* @bodyParam doorcode string The users doorcode used to access doors. Example: 177478
* @bodyParam expires_at date The users expiry date after which they will not be able to access doors or login.
* @bodyParam expires_at date The users expiry date after which they will not be able to access doors or login. Example: 2200-07-03
*
* @response 400
* {"status":"error","code":400,"message":"User already exists!"}
......@@ -156,7 +156,7 @@ class UsersController extends ApiController
* @bodyParam emplid string The users employee id. Example: 239990
* @bodyParam password string The users local application password. Example: This is a better password than 99%
* @bodyParam doorcode string The users doorcode used to access doors. Example: 177478
* @bodyParam expires_at date The users expiry date after which they will not be able to access doors or login.
* @bodyParam expires_at date The users expiry date after which they will not be able to access doors or login. Example: 2200-07-03
*
* @response 400
* {"status":"error","code":400,"message":"User with that email already exists."}
......@@ -236,6 +236,9 @@ class UsersController extends ApiController
* This route adds a user to a group
*
* @authenticated
* @urlParam userId required The user to add the group to. Example: 69
* @urlParam groupId required The group to add to the user. Example: 5
* @response 403 {"message":"You cannot modify your own admin privileges"}
*
* @param \Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupUseCase $useCase
* @param string $userId
......@@ -261,6 +264,9 @@ class UsersController extends ApiController
* This route removes a user from a group.
*
* @authenticated
* @urlParam userId required The user to remove the group from. Example: 69
* @urlParam groupId required The group to from from the user. Example: 5
* @response 403 {"message":"You cannot modify your own admin privileges"}
*
* @param \Source\UseCases\GroupUser\RemoveUserFromGroup\RemoveUserFromGroupUseCase $useCase
* @param string $userId
......@@ -285,10 +291,10 @@ class UsersController extends ApiController
*
* This endpoint gets all groups for a user.
*
* @urlParam userId required The ID of the user to get.
*
* @authenticated
* @paginated
* @urlParam userId required The ID of the user to get. Example: 420
* @response 404 {"status":"error","code":404,"message":"Entity not found"}
*
* @param \Source\UseCases\GroupUser\GetUserGroups\GetUserGroupsUseCase $useCase
* @param string $userId
......
......@@ -93,7 +93,7 @@ class Token
*/
public function hasIdOf(?string $id): bool
{
if (!$id) {
if ($id === null) {
return false;
}
......
......@@ -17,35 +17,35 @@ class LocalTokensRepository extends InMemoryTokensRepository
public function __construct()
{
$this->create(new Token(
0,
1,
LocalUsersRepository::getAdminUser()->getId(),
HashedSearchable::hash(config('app.key'), 'token_string_admin'),
'basic token'
));
$this->create(new Token(
0,
2,
LocalUsersRepository::getSemiPrivilegedUser()->getId(),
HashedSearchable::hash(config('app.key'), 'token_string_semi'),
'basic token'
));
$this->create(new Token(
0,
3,
LocalUsersRepository::getComputerScienceStudent()->getId(),
HashedSearchable::hash(config('app.key'), 'token_string_cs'),
'basic token'
));
$this->create(new Token(
0,
4,
LocalUsersRepository::getEngineeringLabAccessStudent()->getId(),
HashedSearchable::hash(config('app.key'), 'token_string_engr'),
'basic token'
));
$this->create(new Token(
0,
5,
LocalUsersRepository::getAdminUser()->getId(),
HashedSearchable::hash(config('app.key'), 'token_string_expired'),
'expired token',
......
......@@ -11,7 +11,7 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['token'] = $responseModel->getToken();
$this->viewModel['token'] = $this->formatToken($responseModel->getToken());
}
/** @inheritDoc */
......
......@@ -116,11 +116,11 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
$groups->setGroupToReturnOnGet(new Group(1, '', ''));
$this->handleTest('asdf');
$this->response->assertStatus(200);
$this->response->assertStatus(400);
$this->response->assertJson([
'message' => 'Unable to delete group.',
'status' => 'error',
'code' => 200,
'code' => 400,
]);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment