diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index 2952f522..d4507419 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -204,6 +204,7 @@ - New endpoint `/stock/shoppinglist/add-overdue-products` to add all currently in-stock but overdue products to a shopping list (thanks @m-byte) - New endpoint `/stock/shoppinglist/add-expired-products` to add all currently in-stock but expired products to a shopping list - New endpoints GET/POST/PUT `/users/{userId}/permissions` for the new user permissions feature mentioned above +- New endpoint '/user` to get the currently authenticated user - The stock journal (entity `stock_log`) is now also available via the endpoint `/objects/{entity}` (=> `/objects/stock_log`) - Performance improvements of the `/stock/products/*` endpoints (thanks @fipwmaqzufheoxq92ebc) - The endpoint `/stock/products/{productId}/locations` now also has an optional query parameter `include_sub_products` to optionally also return locations of sub products of the given product diff --git a/controllers/UsersApiController.php b/controllers/UsersApiController.php index 280b647a..e09dba35 100644 --- a/controllers/UsersApiController.php +++ b/controllers/UsersApiController.php @@ -126,6 +126,18 @@ class UsersApiController extends BaseApiController } } + public function CurrentUser(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { + try + { + return $this->ApiResponse($response, $this->getUsersService()->GetUsersAsDto()->where('id', GROCY_USER_ID)); + } + catch (\Exception $ex) + { + return $this->GenericErrorResponse($response, $ex->getMessage()); + } + } + public function ListPermissions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { try diff --git a/grocy.openapi.json b/grocy.openapi.json index 8ca8be24..7d4273b1 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -26,7 +26,7 @@ "name": "User management" }, { - "name": "User settings" + "name": "Current user" }, { "name": "Stock" @@ -1153,11 +1153,44 @@ } } }, + "/user": { + "get": { + "summary": "Returns the currently authenticated user", + "tags": [ + "Current user" + ], + "responses": { + "200": { + "description": "A user object", + "content": { + "application/json": { + "schema": { + "type": "object", + "items": { + "$ref": "#/components/schemas/UserDto" + } + } + } + } + }, + "400": { + "description": "The operation was not successful", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error400" + } + } + } + } + } + } + }, "/user/settings": { "get": { "summary": "Returns all settings of the currently logged in user", "tags": [ - "User settings" + "Current user" ], "responses": { "200": { @@ -1188,7 +1221,7 @@ "get": { "summary": "Returns the given setting of the currently logged in user", "tags": [ - "User settings" + "Current user" ], "parameters": [ { @@ -1227,7 +1260,7 @@ "put": { "summary": "Sets the given setting of the currently logged in user", "tags": [ - "User settings" + "Current user" ], "requestBody": { "description": "A valid UserSetting object", diff --git a/routes.php b/routes.php index f1a912e3..e101b730 100644 --- a/routes.php +++ b/routes.php @@ -171,6 +171,7 @@ $app->group('/api', function (RouteCollectorProxy $group) { $group->put('/users/{userId}/permissions', '\Grocy\Controllers\UsersApiController:SetPermissions'); // User + $group->get('/user', '\Grocy\Controllers\UsersApiController:CurrentUser'); $group->get('/user/settings', '\Grocy\Controllers\UsersApiController:GetUserSettings'); $group->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting'); $group->put('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting');