Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
afd5bb4f
Commit
afd5bb4f
authored
Jun 16, 2018
by
Mat
Browse files
complète le CRUD Info
parent
167c2c86
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/APIBundle/Controller/InfoAPIController.php
View file @
afd5bb4f
...
...
@@ -44,17 +44,66 @@ class InfoAPIController extends MasterAPIController
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
readOneAction
(
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$info
=
$em
->
getRepository
(
'PotageBundle:Info'
)
->
findOneForAPIRead
(
$id
);
if
(
$info
===
null
)
{
return
$this
->
api
(
'Not found'
,
Response
::
HTTP_NOT_FOUND
);
}
return
$this
->
api
(
$info
);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
updateAction
(
Request
$request
,
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$info
=
$em
->
getRepository
(
'PotageBundle:Info'
)
->
findOneForAPIUpdate
(
$id
);
if
(
$info
===
null
)
{
return
$this
->
api
(
'Not found'
,
Response
::
HTTP_NOT_FOUND
);
}
$form
=
$this
->
createForm
(
InfoAPIType
::
class
,
$info
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
->
flush
();
return
$this
->
api
(
$info
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
deleteAction
(
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$info
=
$em
->
getRepository
(
'PotageBundle:Info'
)
->
findOneForAPIDelete
(
$id
);
if
(
$info
!==
null
)
{
$em
->
remove
(
$info
);
$em
->
flush
();
}
return
$this
->
api
([]);
}
}
src/APIBundle/Resources/config/routing.yml
100644 → 100755
View file @
afd5bb4f
...
...
@@ -201,6 +201,30 @@ api_info_create:
_controller
:
APIBundle:InfoAPI:create
methods
:
[
POST
]
api_info_read_one
:
path
:
/info/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:InfoAPI:readOne
methods
:
[
GET
]
api_info_update
:
path
:
/info/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:InfoAPI:update
methods
:
[
POST
]
api_info_delete
:
path
:
/info/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:InfoAPI:delete
methods
:
[
DELETE
]
## CRUD GroupeAPI
...
...
src/PotageBundle/Repository/InfoRepository.php
View file @
afd5bb4f
...
...
@@ -20,6 +20,46 @@ class InfoRepository extends \Doctrine\ORM\EntityRepository
->
orderBy
(
'i.id'
,
'DESC'
);
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForAPIRead
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'i'
)
->
where
(
'i.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForAPIUpdate
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'i'
)
->
where
(
'i.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForAPIDelete
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'i'
)
->
where
(
'i.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
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