Skip to content

Commit

Permalink
Add /user endpoint to get my profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrom committed May 13, 2024
1 parent 8773bfc commit 6948283
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/resto/core/RestoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class RestoRouter
// Landing page and conformance (see WFS 3.0)
array('GET', RestoRouter::ROUTE_TO_API, false, 'ServicesAPI::api'), // API page
array('GET', RestoRouter::ROUTE_TO_CONFORMANCE, false, 'ServicesAPI::conformance'), // Conform

// API for users
array('GET', '/user', true, 'UsersAPI::getMyProfile'), // Show my profile
array('GET', RestoRouter::ROUTE_TO_USERS, true, 'UsersAPI::getUsersProfiles'), // List users profiles
array('POST', RestoRouter::ROUTE_TO_USERS, false, 'UsersAPI::createUser'), // Create user
array('GET', RestoRouter::ROUTE_TO_USER, true, 'UsersAPI::getUserProfile'), // Show user profile
Expand Down
31 changes: 29 additions & 2 deletions app/resto/core/api/UsersAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,33 @@ public function getUsersProfiles($params)
);
}

/**
* Get my profile
*
* @OA\Get(
* path="/user",
* summary="Get my profile",
* tags={"User"},
* @OA\Response(
* response="200",
* description="User profile",
* @OA\JsonContent(ref="#/components/schemas/UserDisplayProfile")
* ),
* @OA\Response(
* response="401",
* description="Unauthorized",
* @OA\JsonContent(ref="#/components/schemas/UnauthorizedError")
* ),
* security={
* {"basicAuth":{}, "bearerAuth":{}, "queryAuth":{}}
* }
* )
*/
public function getMyProfile() {
$this->user->loadProfile();
return $this->user->profile;
}

/**
* Get user profile
*
Expand Down Expand Up @@ -213,9 +240,9 @@ public function getUsersProfiles($params)
*/
public function getUserProfile($params)
{

if ($this->user->profile['id'] === $params['userid']) {
$this->user->loadProfile();
return $this->user->profile;
return $this->getMyProfile();
}

return (new UsersFunctions($this->context->dbDriver))->getUserProfile(
Expand Down

0 comments on commit 6948283

Please sign in to comment.