Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
be05c941
Commit
be05c941
authored
6 years ago
by
Pegane Nestor
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #7345 ExternalInfos webservice
parent
a29b68ee
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/Test/ResControllerTest.php
+103
-0
103 additions, 0 deletions
core/Test/ResControllerTest.php
rest/index.php
+1
-0
1 addition, 0 deletions
rest/index.php
src/app/resource/controllers/ResController.php
+30
-0
30 additions, 0 deletions
src/app/resource/controllers/ResController.php
with
134 additions
and
0 deletions
core/Test/ResControllerTest.php
+
103
−
0
View file @
be05c941
...
...
@@ -117,6 +117,109 @@ class ResControllerTest extends TestCase
$this
->
assertSame
(
'COU'
,
$res
[
'status'
]);
}
public
function
testUpdateExternalInfos
(){
$resController
=
new
\Resource\controllers\ResController
();
// UPDATE STATUS
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'PUT'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
//ALL OK
$aArgs
=
[
'externalInfos'
=>
[
[
'res_id'
=>
self
::
$id
,
'external_id'
=>
"BB981212IIYZ"
,
'external_link'
=>
"https://publik.nancy.fr/res/BB981212BB65"
]
],
'status'
=>
"GRCSENT"
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
updateExternalInfos
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'success'
,
$responseBody
->
success
);
// EXTERNAL INFOS EMPTY AND RES ID IS NOT INTEGER
$aArgs
=
[
'externalInfos'
=>
[
[
'res_id'
=>
"res_id"
,
'external_id'
=>
""
,
'external_link'
=>
""
]
],
'status'
=>
"GRCSENT"
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
updateExternalInfos
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'Bad Request'
,
$responseBody
->
errors
);
// DOCUMENT DOES NOT EXIST
$aArgs
=
[
'externalInfos'
=>
[
[
'res_id'
=>
123456789
,
'external_id'
=>
"BB981212IIYZ"
,
'external_link'
=>
"https://publik.nancy.fr/res/BB981212BB65"
]
],
'status'
=>
'GRCSENT'
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
updateExternalInfos
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
_DOCUMENT_NOT_FOUND
,
$responseBody
->
errors
);
//MISSING EXTERNAL INFO
$aArgs
=
[
'externalInfos'
=>
[
[
'res_id'
=>
123456789
,
'external_id'
=>
"BB981212IIYZ"
,
'external_link'
=>
"https://publik.nancy.fr/res/BB981212BB65"
]
],
'status'
=>
NULL
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
updateExternalInfos
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'Bad Request'
,
$responseBody
->
errors
);
//MISSING STATUS
$aArgs
=
[
'externalInfos'
=>
NULL
,
'status'
=>
"GRCSENT"
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
updateExternalInfos
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'Bad Request'
,
$responseBody
->
errors
);
}
public
function
testDelete
()
{
// DELETE
...
...
This diff is collapsed.
Click to expand it.
rest/index.php
+
1
−
0
View file @
be05c941
...
...
@@ -243,6 +243,7 @@ $app->put('/res/resource/status', \Resource\controllers\ResController::class . '
$app
->
post
(
'/res/list'
,
\Resource\controllers\ResController
::
class
.
':getList'
);
$app
->
get
(
'/res/{resId}/lock'
,
\Resource\controllers\ResController
::
class
.
':isLock'
);
$app
->
get
(
'/res/{resId}/notes/count'
,
\Resource\controllers\ResController
::
class
.
':getNotesCountForCurrentUserById'
);
$app
->
put
(
'/res/externalInfos'
,
\Resource\controllers\ResController
::
class
.
':updateExternalInfos'
);
//statuses
$app
->
get
(
'/statuses'
,
\Status\controllers\StatusController
::
class
.
':get'
);
...
...
This diff is collapsed.
Click to expand it.
src/app/resource/controllers/ResController.php
+
30
−
0
View file @
be05c941
...
...
@@ -162,6 +162,36 @@ class ResController
}
//EXTERNAL INFOS
public
function
updateExternalInfos
(
Request
$request
,
Response
$response
){
$data
=
$request
->
getParams
();
if
(
empty
(
$data
[
'externalInfos'
])){
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
if
(
empty
(
$data
[
'status'
])){
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
$externalInfos
=
$data
[
'externalInfos'
];
foreach
(
$externalInfos
as
$mail
){
$check
=
Validator
::
intType
()
->
validate
(
$mail
[
'res_id'
]);
$check
=
$check
&&
Validator
::
StringType
()
->
notEmpty
()
->
validate
(
$mail
[
'external_id'
]);
$check
=
$check
&&
Validator
::
StringType
()
->
notEmpty
()
->
validate
(
$mail
[
'external_link'
]);
if
(
!
$check
){
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
$document
=
ResModel
::
getById
([
'resId'
=>
$mail
[
'res_id'
],
'select'
=>
[
'res_id'
]]);
if
(
empty
(
$document
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
_DOCUMENT_NOT_FOUND
]);
}
if
(
!
ResController
::
hasRightByResId
([
'resId'
=>
$document
[
'res_id'
],
'userId'
=>
$GLOBALS
[
'userId'
]]))
{
return
$response
->
withStatus
(
403
)
->
withJson
([
'errors'
=>
'Document out of perimeter'
]);
}
ResModel
::
update
([
'set'
=>
[
'external_id'
=>
$mail
[
'external_id'
]
,
'external_link'
=>
$mail
[
'external_link'
],
'status'
=>
$data
[
'status'
]],
'where'
=>
[
'res_id = ?'
],
'data'
=>
[
$document
[
'res_id'
]]]);
}
return
$response
->
withJson
([
'success'
=>
'success'
]);
}
public
function
isLock
(
Request
$request
,
Response
$response
,
array
$aArgs
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment