Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
potage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mathieu
potage
Commits
72155699
Commit
72155699
authored
Jun 16, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complète le CRUD OffreLegumes
parent
d90b5477
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
14 deletions
+139
-14
src/APIBundle/Controller/OffreLegumesAPIController.php
src/APIBundle/Controller/OffreLegumesAPIController.php
+82
-8
src/APIBundle/Resources/config/routing.yml
src/APIBundle/Resources/config/routing.yml
+26
-2
src/PotageBundle/Entity/OffreLegumes.php
src/PotageBundle/Entity/OffreLegumes.php
+4
-1
src/PotageBundle/Repository/OffreLegumesRepository.php
src/PotageBundle/Repository/OffreLegumesRepository.php
+25
-1
src/PotageBundle/Resources/config/routing.yml
src/PotageBundle/Resources/config/routing.yml
+1
-1
src/PotageBundle/Resources/views/OffreLegumes/ajaxDisplay.html.twig
...Bundle/Resources/views/OffreLegumes/ajaxDisplay.html.twig
+1
-1
No files found.
src/APIBundle/Controller/OffreLegumesAPIController.php
View file @
72155699
...
...
@@ -3,31 +3,105 @@
namespace
APIBundle\Controller
;
use
APIBundle\Form\OffreLegumesAPIType
;
use
PotageBundle\Entity\OffreLegumes
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
OffreLegumesAPIController
extends
MasterAPIController
{
/**
* @param
$id
* @
return \Symfony\Component\HttpFoundation\Respons
e
* @
throws \Doctrine\ORM\NonUniqueResultException
* @param
Request $request
* @
param $id_offr
e
* @
return \Symfony\Component\HttpFoundation\JsonResponse
*/
public
function
readAction
(
$id
)
public
function
createAction
(
Request
$request
,
$id_offre
)
{
$legume
=
new
OffreLegumes
(
$id_offre
);
$form
=
$this
->
createForm
(
OffreLegumesAPIType
::
class
,
$legume
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$em
->
persist
(
$legume
);
$em
->
flush
();
return
$this
->
api
(
$legume
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @param $id_offre
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
readAction
(
$id_offre
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
// Récupère l'ordre de tri
$sorted
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForAPIRead
(
$id
)
->
getSorted
();
$sorted
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForAPIRead
(
$id
_offre
)
->
getSorted
();
if
(
!
empty
(
$sorted
))
{
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForSortedRead
(
$id
,
$sorted
);
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForSortedRead
(
$id
_offre
,
$sorted
);
}
else
{
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForRead
(
$id
);
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForRead
(
$id
_offre
);
}
return
$this
->
api
(
$legumes
);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
updateAction
(
Request
$request
,
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$legume
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findOneForUpdate
(
$id
);
if
(
$legume
===
null
)
{
return
$this
->
api
(
'Not found'
,
Response
::
HTTP_NOT_FOUND
);
}
$form
=
$this
->
createForm
(
OffreLegumesAPIType
::
class
,
$legume
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
->
flush
();
return
$this
->
api
(
$legume
);
}
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
();
$legume
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findOneForDelete
(
$id
);
if
(
$legume
!==
null
)
{
$em
->
remove
(
$legume
);
$em
->
flush
();
}
return
$this
->
api
([]);
}
}
src/APIBundle/Resources/config/routing.yml
View file @
72155699
...
...
@@ -116,13 +116,37 @@ api_offre_delete:
## CRUD OffreLegumesAPI
api_offre_legumes_read
:
path
:
/offre/{id}/legumes
path
:
/offre/{id
_offre
}/legumes
requirements
:
id
:
\d+
id
_offre
:
\d+
defaults
:
_controller
:
APIBundle:OffreLegumesAPI:read
methods
:
[
GET
]
api_offre_legumes_create
:
path
:
/offre/{id_offre}/legumes/ajouter
requirements
:
id_offre
:
\d+
defaults
:
_controller
:
APIBundle:OffreLegumesAPI:create
methods
:
[
POST
]
api_offre_legumes_update
:
path
:
/offre/legume/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:OffreLegumesAPI:update
methods
:
[
POST
]
api_offre_legumes_delete
:
path
:
/offre/legume/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:OffreLegumesAPI:delete
methods
:
[
DELETE
]
## CRUD LettreAPI
...
...
src/PotageBundle/Entity/OffreLegumes.php
View file @
72155699
...
...
@@ -159,9 +159,12 @@ class OffreLegumes
/**
* OffreLegumes constructor.
*
* @param $id_offre
*/
public
function
__construct
()
public
function
__construct
(
$id_offre
)
{
$this
->
offre
=
$id_offre
;
$this
->
isPromo
=
false
;
$this
->
fruit
=
false
;
$this
->
revente
=
false
;
...
...
src/PotageBundle/Repository/OffreLegumesRepository.php
View file @
72155699
...
...
@@ -62,5 +62,29 @@ class OffreLegumesRepository extends \Doctrine\ORM\EntityRepository
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForUpdate
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'ol'
)
->
where
(
'ol.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForDelete
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'ol'
)
->
where
(
'ol.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
src/PotageBundle/Resources/config/routing.yml
View file @
72155699
...
...
@@ -3,7 +3,7 @@ potage_homepage:
defaults
:
_controller
:
PotageBundle:Default:index
### les routes des
fonction
s qui interrogent l'APIBundle
### les routes des
page
s qui interrogent l'APIBundle
potage_legume_ajax_display
:
path
:
/admin/legumes
...
...
src/PotageBundle/Resources/views/OffreLegumes/ajaxDisplay.html.twig
View file @
72155699
...
...
@@ -130,7 +130,7 @@
let
sortable
=
grid
.
querySelector
(
'
div#sortable
'
);
sortable
.
innerHTML
=
null
;
let
URL
=
Routing
.
generate
(
'
api_offre_legumes_read
'
,
{
'
id
'
:
id_offre
});
let
URL
=
Routing
.
generate
(
'
api_offre_legumes_read
'
,
{
'
id
_offre
'
:
id_offre
});
AJAX
(
'
GET
'
,
URL
,
function
(
request
)
{
...
...
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