44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
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 {
|
|
|
|
@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));
|
|
}
|
|
|
|
}
|