Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projet-cdaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Quentin Vrel
projet-cdaw
Commits
cc6ef9bc
Commit
cc6ef9bc
authored
Nov 25, 2020
by
Zohten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added delete
parent
d186a97c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
3 deletions
+41
-3
UserController.class.php
BackEnd/src/controller/UserController.class.php
+31
-2
User.class.php
BackEnd/src/model/User.class.php
+5
-1
User.sql.php
BackEnd/src/sql/User.sql.php
+5
-0
No files found.
BackEnd/src/controller/UserController.class.php
View file @
cc6ef9bc
...
...
@@ -37,6 +37,11 @@ class UserController extends Controller
$body
=
$this
->
request
->
getData
();
return
$this
->
addUser
(
$body
);
break
;
case
'DELETE'
:
if
(
$uriParams
)
{
return
$this
->
deleteUser
(
$uriParams
[
0
]);
}
break
;
}
$message
=
json_encode
([
"message"
=>
"unsupported parameters or method in users"
]);
return
Response
::
errorResponse
(
$message
);
...
...
@@ -114,8 +119,9 @@ class UserController extends Controller
protected
function
updateUser
(
$array
)
{
// Auth with token phase
if
(
$this
->
authUser
(
$array
[
'id'
])
->
getCode
()
!=
200
){
return
authError
;
$authResponse
=
$this
->
authUser
(
$id
);
if
(
$authResponse
->
getCode
()
!=
200
){
return
$authResponse
;
}
// Update phase
...
...
@@ -126,4 +132,27 @@ class UserController extends Controller
return
$response
;
}
/**
* (DELETE) Delete a specific user in USER table based on id
*
* @param int $id id of the User
* @return Response
*/
protected
function
deleteUser
(
$id
)
{
// Auth with token phase
$authResponse
=
$this
->
authUser
(
$id
);
if
(
$authResponse
->
getCode
()
!=
200
){
return
$authResponse
;
}
// Update phase
User
::
deleteRow
(
$id
);
$message
=
json_encode
([
"message"
=>
'User succesfully deleted!'
]);
$response
=
Response
::
okResponse
(
$message
);
return
$response
;
}
}
BackEnd/src/model/User.class.php
View file @
cc6ef9bc
...
...
@@ -22,10 +22,14 @@ class User extends Model
public
static
function
addRow
(
$array
)
{
//print_r($array); die();
$stm
=
parent
::
exec
(
'USER_CREATE'
,
$array
);
}
public
static
function
deleteRow
(
$id
)
{
$stm
=
parent
::
exec
(
'USER_DELETE'
,
[
'id'
=>
$id
]);
}
public
static
function
updateUser
(
$array
)
{
$stm
=
parent
::
exec
(
'USER_UPDATE'
,
$array
);
...
...
BackEnd/src/sql/User.sql.php
View file @
cc6ef9bc
...
...
@@ -31,3 +31,8 @@ User::addSqlQuery(
'USER_UPDATE'
,
'UPDATE MJ_USER SET MAIL = :email WHERE ID_USER = :id'
);
User
::
addSqlQuery
(
'USER_DELETE'
,
'DELETE FROM MJ_USER WHERE ID_USER=:id'
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment