Skip to content

Commit

Permalink
[JPA] Le spring client doit retourner un ResponseEntity (pour gérer l…
Browse files Browse the repository at this point in the history
…es différentes erreurs)
  • Loading branch information
gideruette committed Dec 12, 2024
1 parent dd1f781 commit ebcabe4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ private void WriteEndpoint(JavaWriter fw, Endpoint endpoint, string tag)
}
}

fw.WriteLine(1, $"{(endpoint.IsMultipart ? "<K, V> " : string.Empty)}{returnType} {endpoint.NameCamel}({string.Join(", ", methodParams)});");
fw.AddImport("org.springframework.http.ResponseEntity");
fw.WriteLine(1, $"{(endpoint.IsMultipart ? "<K, V> " : string.Empty)}ResponseEntity<{returnType}> {endpoint.NameCamel}({string.Join(", ", methodParams)});");
}

private void WriteImports(IEnumerable<Endpoint> endpoints, JavaWriter fw, string tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -33,7 +34,7 @@ public interface ProfilClient {
*/
@PreAuthorize("hasRole('CREATE')")
@PostExchange(value = "/")
ProfilRead addProfil(@RequestBody @Valid ProfilWrite profil);
ResponseEntity<ProfilRead> addProfil(@RequestBody @Valid ProfilWrite profil);

/**
* Charge le détail d'un Profil.
Expand All @@ -42,15 +43,15 @@ public interface ProfilClient {
*/
@PreAuthorize("hasRole('READ')")
@GetExchange(value = "/{proId}")
ProfilRead getProfil(@PathVariable("proId") Integer proId);
ResponseEntity<ProfilRead> getProfil(@PathVariable("proId") Integer proId);

/**
* Liste tous les Profils.
* @return Profils matchant les critères
*/
@PreAuthorize("hasRole('READ')")
@GetExchange(value = "/")
List<ProfilItem> getProfils();
ResponseEntity<List<ProfilItem>> getProfils();

/**
* Sauvegarde un Profil.
Expand All @@ -60,5 +61,5 @@ public interface ProfilClient {
*/
@PreAuthorize("hasRole('UPDATE')")
@PutExchange(value = "/{proId}")
ProfilRead updateProfil(@PathVariable("proId") Integer proId, @RequestBody @Valid ProfilWrite profil);
ResponseEntity<ProfilRead> updateProfil(@PathVariable("proId") Integer proId, @RequestBody @Valid ProfilWrite profil);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.LocalDate;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -37,15 +38,15 @@ public interface UtilisateurClient {
*/
@PreAuthorize("hasRole('CREATE')")
@PostExchange(value = "/")
UtilisateurRead addUtilisateur(@RequestBody @Valid UtilisateurWrite utilisateur);
ResponseEntity<UtilisateurRead> addUtilisateur(@RequestBody @Valid UtilisateurWrite utilisateur);

/**
* Supprime un utilisateur.
* @param utiId Id de l'utilisateur
*/
@PreAuthorize("hasRole('DELETE')")
@DeleteExchange(value = "/{utiId}")
void deleteUtilisateur(@PathVariable("utiId") Integer utiId);
ResponseEntity<void> deleteUtilisateur(@PathVariable("utiId") Integer utiId);

/**
* Charge le détail d'un utilisateur.
Expand All @@ -54,7 +55,7 @@ public interface UtilisateurClient {
*/
@PreAuthorize("hasRole('READ')")
@GetExchange(value = "/{utiId}")
UtilisateurRead getUtilisateur(@PathVariable("utiId") Integer utiId);
ResponseEntity<UtilisateurRead> getUtilisateur(@PathVariable("utiId") Integer utiId);

/**
* Recherche des utilisateurs.
Expand All @@ -70,7 +71,7 @@ public interface UtilisateurClient {
*/
@PreAuthorize("hasRole('READ')")
@GetExchange(value = "/")
List<UtilisateurItem> searchUtilisateur(@RequestParam(value = "nom", required = true) String nom, @RequestParam(value = "prenom", required = true) String prenom, @RequestParam(value = "email", required = true) String email, @RequestParam(value = "dateNaissance", required = false) LocalDate dateNaissance, @RequestParam(value = "adresse", required = false) String adresse, @RequestParam(value = "actif", required = true) Boolean actif, @RequestParam(value = "profilId", required = true) Integer profilId, @RequestParam(value = "typeUtilisateurCode", required = true) TypeUtilisateurCode typeUtilisateurCode);
ResponseEntity<List<UtilisateurItem>> searchUtilisateur(@RequestParam(value = "nom", required = true) String nom, @RequestParam(value = "prenom", required = true) String prenom, @RequestParam(value = "email", required = true) String email, @RequestParam(value = "dateNaissance", required = false) LocalDate dateNaissance, @RequestParam(value = "adresse", required = false) String adresse, @RequestParam(value = "actif", required = true) Boolean actif, @RequestParam(value = "profilId", required = true) Integer profilId, @RequestParam(value = "typeUtilisateurCode", required = true) TypeUtilisateurCode typeUtilisateurCode);

/**
* Sauvegarde un utilisateur.
Expand All @@ -80,5 +81,5 @@ public interface UtilisateurClient {
*/
@PreAuthorize("hasRole('UPDATE')")
@PutExchange(value = "/{utiId}")
UtilisateurRead updateUtilisateur(@PathVariable("utiId") Integer utiId, @RequestBody @Valid UtilisateurWrite utilisateur);
ResponseEntity<UtilisateurRead> updateUtilisateur(@PathVariable("utiId") Integer utiId, @RequestBody @Valid UtilisateurWrite utilisateur);
}
2 changes: 1 addition & 1 deletion samples/model/jpa.topmodel.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

version: 2.2.1
custom:
../../../TopModel.Generator.Jpa: 9c152aa27af0b426e7267c2ebe36ef62
../../../TopModel.Generator.Jpa: 8f78520bb47d1d3ea1f64a5489e0fb77
generatedFiles:
- ../generators/jpa/src/main/javagen/topmodel/jpa/sample/demo/api/client/securite/profil/ProfilClient.java
- ../generators/jpa/src/main/javagen/topmodel/jpa/sample/demo/api/client/securite/utilisateur/UtilisateurClient.java
Expand Down

0 comments on commit ebcabe4

Please sign in to comment.