FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
UserController.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************
3  Copyright (C) 2018 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***************************************************************/
25 
30 
36 {
45  public function getUsers($request, $response, $args)
46  {
47  $id = null;
48  if (isset($args['id'])) {
49  $id = intval($args['id']);
50  if (! $this->dbHelper->doesIdExist("users", "user_pk", $id)) {
51  $returnVal = new Info(404, "UserId doesn't exist", InfoType::ERROR);
52  return $response->withJson($returnVal->getArray(), $returnVal->getCode());
53  }
54  }
55  $users = $this->dbHelper->getUsers($id);
56  if ($id !== null) {
57  $users = $users[0];
58  }
59  return $response->withJson($users, 200);
60  }
61 
70  public function deleteUser($request, $response, $args)
71  {
72  $id = intval($args['id']);
73  $returnVal = null;
74  if ($this->dbHelper->doesIdExist("users","user_pk", $id)) {
75  $this->dbHelper->deleteUser($id);
76  $returnVal = new Info(202, "User will be deleted", InfoType::INFO);
77  } else {
78  $returnVal = new Info(404, "UserId doesn't exist", InfoType::ERROR);
79  }
80  return $response->withJson($returnVal->getArray(), $returnVal->getCode());
81  }
82 }
Base controller for REST calls.
deleteUser($request, $response, $args)
Info model to contain general error and return values.
Definition: Info.php:29