Add Exo - 04-06-2025
This commit is contained in:
parent
08e3bb426d
commit
008669c50f
5 changed files with 94 additions and 25 deletions
|
|
@ -2,10 +2,7 @@ package fr.teamflash.archy.controller;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatusCode;
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -31,5 +28,10 @@ public class exempleController {
|
||||||
}
|
}
|
||||||
return new ResponseEntity(sum, HttpStatusCode.valueOf(200));
|
return new ResponseEntity(sum, HttpStatusCode.valueOf(200));
|
||||||
}
|
}
|
||||||
|
@GetMapping("details/{id}")
|
||||||
|
public ResponseEntity detail(@PathVariable("id") String ID){
|
||||||
|
return new ResponseEntity("Bonjour " + ID, HttpStatusCode.valueOf(200));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,44 @@
|
||||||
package fr.teamflash.archy.controller;
|
package fr.teamflash.archy.controller;
|
||||||
|
|
||||||
|
import fr.teamflash.archy.dto.userDTO;
|
||||||
|
import fr.teamflash.archy.dto.userDisplayDTO;
|
||||||
|
import fr.teamflash.archy.fonction.calcule;
|
||||||
|
import org.springframework.http.HttpStatusCode;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Period;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("user")
|
||||||
public class userController {
|
public class userController {
|
||||||
|
|
||||||
|
@PostMapping("add")
|
||||||
|
public ResponseEntity afficher (@RequestBody userDTO dto){
|
||||||
|
// calcule l'age
|
||||||
|
int age = Period.between(dto.getDate_naissance(), LocalDate.now()).getYears();
|
||||||
|
|
||||||
|
userDisplayDTO result = new userDisplayDTO();
|
||||||
|
result.setDisplay_name(dto.getPrenom() + " " + dto.getNom());
|
||||||
|
result.setAge(age);
|
||||||
|
return new ResponseEntity(result, HttpStatusCode.valueOf(200));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("info")
|
||||||
|
public ResponseEntity info(@RequestParam("name") String nom, @RequestParam("firstname") String prenom, @RequestParam("birthdate") LocalDate birthdate, @RequestParam("valeur") List<Integer> valeurs) {
|
||||||
|
int sum = calcule.somme(valeurs);
|
||||||
|
|
||||||
|
boolean admis = calcule.admis(valeurs);
|
||||||
|
|
||||||
|
int age = Period.between(birthdate, LocalDate.now()).getYears();
|
||||||
|
|
||||||
|
String fullName = nom + " " + prenom;
|
||||||
|
|
||||||
|
String respond = fullName + " " + age + " " + sum + " " + admis;
|
||||||
|
|
||||||
|
return new ResponseEntity(respond, HttpStatusCode.valueOf(200));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,32 @@ package fr.teamflash.archy.dto;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
public class userDTO {
|
public class userDTO {
|
||||||
private String name;
|
private String prenom;
|
||||||
private String firstName;
|
private String nom;
|
||||||
private LocalDate birthDate;
|
|
||||||
|
|
||||||
|
private LocalDate date_naissance;
|
||||||
|
|
||||||
|
public String getPrenom() {
|
||||||
public String getName() {
|
return prenom;
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setPrenom(String prenom) {
|
||||||
this.name = name;
|
this.prenom = prenom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getBirthDate() {
|
public String getNom() {
|
||||||
return birthDate;
|
return nom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBirthDate(LocalDate birthDate) {
|
public void setNom(String nom) {
|
||||||
this.birthDate = birthDate;
|
this.nom = nom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public LocalDate getDate_naissance() {
|
||||||
return firstName;
|
return date_naissance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
public void setDate_naissance(LocalDate date_naissance) {
|
||||||
this.firstName = firstName;
|
this.date_naissance = date_naissance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
package fr.teamflash.archy.dto;
|
package fr.teamflash.archy.dto;
|
||||||
|
|
||||||
public class userDisplayDTO {
|
public class userDisplayDTO {
|
||||||
private String displayName;
|
private String display_name;
|
||||||
private Integer age;
|
private Integer age;
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplay_name() {
|
||||||
return displayName;
|
return display_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayName(String name, String firstName) {
|
public void setDisplay_name(String display_name) {
|
||||||
this.displayName = name + " " + firstName;
|
this.display_name = display_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getAge() {
|
public Integer getAge() {
|
||||||
|
|
|
||||||
28
src/main/java/fr/teamflash/archy/fonction/calcule.java
Normal file
28
src/main/java/fr/teamflash/archy/fonction/calcule.java
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package fr.teamflash.archy.fonction;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class calcule {
|
||||||
|
public static int somme(List<Integer> valeurs) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < valeurs.size(); i++) {
|
||||||
|
sum += valeurs.get(i);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean admis(List<Integer> valeurs) {
|
||||||
|
// Vérifie que toutes les notes sont > 8
|
||||||
|
for (int note : valeurs) {
|
||||||
|
if (note <= 8) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcul de la moyenne
|
||||||
|
int somme = somme(valeurs);
|
||||||
|
double moyenne = (double) somme / valeurs.size();
|
||||||
|
|
||||||
|
return moyenne > 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue