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
6e4a3910
Commit
6e4a3910
authored
Jul 26, 2018
by
Mat
Browse files
API optimisation: readUtilisateurs et readGroupes groups
parent
70f93d33
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/APIBundle/Controller/GroupeAPIController.php
View file @
6e4a3910
...
...
@@ -40,7 +40,7 @@ class GroupeAPIController extends MasterAPIController
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$groupes
=
$em
->
getRepository
(
'PotageBundle:Groupe'
)
->
findAllForAPIRead
();
return
$this
->
api
(
$groupes
);
return
$this
->
api
(
$groupes
,
200
,
array
(
'readGroupes'
)
);
}
...
...
src/APIBundle/Controller/UtilisateurAPIController.php
View file @
6e4a3910
...
...
@@ -49,7 +49,7 @@ class UtilisateurAPIController extends MasterAPIController
->
getRepository
(
'PotageBundle:Utilisateur'
)
->
findAllForAPIReadPaginate
(
$paginate
,
$start
,
$column
,
$order
);
return
$this
->
api
(
$utilisateurs
);
return
$this
->
api
(
$utilisateurs
,
200
,
array
(
'readUtilisateurs'
)
);
}
...
...
src/PotageBundle/Entity/Depot.php
View file @
6e4a3910
...
...
@@ -3,6 +3,8 @@
namespace
PotageBundle\Entity
;
use
Doctrine\ORM\Mapping
as
ORM
;
use
JMS\Serializer\Annotation
as
Serializer
;
/**
* Depot
...
...
@@ -19,6 +21,7 @@ class Depot
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readGroupes"})
*/
private
$id
;
...
...
@@ -32,24 +35,28 @@ class Depot
/**
* @var string
* @ORM\Column(name="localisation", type="string", length=100)
* @Serializer\Groups({"readGroupes"})
*/
private
$localisation
;
/**
* @var integer
* @ORM\Column(name="id_responsable", type="integer", length=3)
* @Serializer\Groups({"readGroupes"})
*/
private
$responsable
;
/**
* @var integer
* @ORM\Column(name="jour_panier", type="integer", length=1)
* @Serializer\Groups({"readGroupes"})
*/
private
$jourPanier
;
/**
* @var
* @ORM\Column(name="heure_panier", type="time")
* @Serializer\Groups({"readGroupes"})
*/
private
$heurePanier
;
...
...
src/PotageBundle/Entity/Groupe.php
View file @
6e4a3910
...
...
@@ -22,7 +22,7 @@ class Groupe
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
* @Serializer\Groups({"readLettres"
, "readUtilisateurs", "readGroupes"
})
*/
private
$id
;
...
...
@@ -35,6 +35,7 @@ class Groupe
/**
* @var
* @ORM\OneToOne(targetEntity="PotageBundle\Entity\Depot", mappedBy="groupe")
* @Serializer\Groups({"readGroupes"})
*/
private
$depot
;
...
...
@@ -48,13 +49,14 @@ class Groupe
* @var string
*
* @ORM\Column(name="nom", type="string", length=100)
* @Serializer\Groups({"readLettres"})
* @Serializer\Groups({"readLettres"
, "readUtilisateurs", "readGroupes"
})
*/
private
$nom
;
/**
* @Gedmo\Slug(fields={"nom"})
* @ORM\Column(length=128, unique=true)
* @Serializer\Groups({"readGroupes"})
*/
private
$slug
;
...
...
@@ -62,6 +64,7 @@ class Groupe
* @var string
*
* @ORM\Column(name="description", type="text")
* @Serializer\Groups({"readGroupes"})
*/
private
$description
;
...
...
@@ -70,6 +73,7 @@ class Groupe
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
* @Serializer\Groups({"readGroupes"})
*/
private
$createdAt
;
...
...
@@ -77,6 +81,7 @@ class Groupe
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Serializer\Groups({"readGroupes"})
*/
private
$updatedAt
;
...
...
src/PotageBundle/Entity/User.php
View file @
6e4a3910
...
...
@@ -4,6 +4,7 @@ namespace PotageBundle\Entity;
use
Doctrine\ORM\Mapping
as
ORM
;
use
FOS\UserBundle\Model\User
as
BaseUser
;
use
JMS\Serializer\Annotation
as
Serializer
;
/**
* User
...
...
@@ -19,9 +20,16 @@ class User extends BaseUser
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readUtilisateurs"})
*/
protected
$id
;
/**
* @var string
* @Serializer\Groups({"readUtilisateurs"})
*/
protected
$username
;
/**
* @var
* @ORM\OneToOne(targetEntity="PotageBundle\Entity\Utilisateur", mappedBy="user")
...
...
src/PotageBundle/Entity/Utilisateur.php
View file @
6e4a3910
...
...
@@ -2,7 +2,7 @@
namespace
PotageBundle\Entity
;
use
JMS\Serializer\Annotation
\MaxDepth
;
use
JMS\Serializer\Annotation
as
Serializer
;
use
Symfony\Component\Validator\Constraints
as
Assert
;
use
Doctrine\Common\Collections\ArrayCollection
;
use
Doctrine\Common\Collections\Collection
;
...
...
@@ -23,6 +23,7 @@ class Utilisateur
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$id
;
...
...
@@ -30,6 +31,7 @@ class Utilisateur
* @var
* @ORM\OneToOne(targetEntity="PotageBundle\Entity\User", inversedBy="utilisateur")
* @ORM\JoinColumn(name="id_fosuser", referencedColumnName="id")
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$user
;
...
...
@@ -40,7 +42,7 @@ class Utilisateur
* joinColumns={@ORM\JoinColumn(name="id_groupe", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_utilisateur", referencedColumnName="id")}
* )
* @
MaxDepth(3
)
* @
Serializer\Groups({"readUtilisateurs"}
)
*/
private
$groupes
;
...
...
@@ -59,18 +61,21 @@ class Utilisateur
* message = "L'adresse mail {{ value }} n'est pas valide",
* checkMX = false
* )
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$email
;
/**
* @var string
* @ORM\Column(name="nom", type="string", length=100)
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$nom
;
/**
* @var string
* @ORM\Column(name="prenom", type="string", length=100)
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$prenom
;
...
...
@@ -78,6 +83,7 @@ class Utilisateur
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$createdAt
;
...
...
@@ -85,6 +91,7 @@ class Utilisateur
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Serializer\Groups({"readUtilisateurs"})
*/
private
$updatedAt
;
...
...
src/PotageBundle/Resources/views/Groupe/ajaxDisplay.js
View file @
6e4a3910
...
...
@@ -38,8 +38,9 @@ function buildRowGroupe(jsonRow)
let
td3
=
document
.
createElement
(
'
td
'
);
td3
.
innerHTML
=
jsonRow
.
description
+
'
<br>
'
+
jsonRow
.
utilisateurs
.
length
+
'
abonné
'
+
(
jsonRow
.
utilisateurs
.
length
>
1
?
'
s
'
:
''
);
// + jsonRow.utilisateurs.length + ' abonné'
// + (jsonRow.utilisateurs.length > 1 ? 's': '')
;
tr
.
appendChild
(
td3
);
...
...
src/PotageBundle/Resources/views/Utilisateur/ajaxDisplay.js
View file @
6e4a3910
...
...
@@ -83,7 +83,7 @@ function buildRowUtilisateur(jsonRow)
tr
.
appendChild
(
td4
);
let
td6
=
document
.
createElement
(
'
td
'
);
td6
.
textContent
=
jsonRow
.
user
.
username
;
td6
.
textContent
=
jsonRow
.
user
?
jsonRow
.
user
.
username
:
''
;
tr
.
appendChild
(
td6
);
let
td5
=
document
.
createElement
(
'
td
'
);
...
...
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