package fr.eni.demo.controller; import fr.eni.demo.bll.ClientService; import fr.eni.demo.bo.Adresse; import fr.eni.demo.bo.Client; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api/clients") @RequiredArgsConstructor public class ClientController { private final ClientService clientService; // Ajouter un client @PostMapping public ResponseEntity> create(@RequestBody Client client) { clientService.add(client); Map response = new HashMap<>(); response.put("message", "Client created successfully"); response.put("status", true); response.put("data", new HashMap<>()); return ResponseEntity.ok(response); } // Chercher des clients par nom @GetMapping("/name/{name}") public ResponseEntity> findByEmail(@PathVariable String name) { List result = clientService.findByName(name); Map response = new HashMap<>(); response.put("message", "List of Clients found"); response.put("status", true); response.put("data", result); return ResponseEntity.ok(response); } // Chercher des clients par nom @GetMapping("/{id}") public ResponseEntity> findByEmail(@PathVariable Long id) { Client result = clientService.findById(id); Map response = new HashMap<>(); response.put("message", "Client found"); response.put("status", true); response.put("data", result); return ResponseEntity.ok(response); } // Modifier un client @PutMapping("/{id}") public ResponseEntity> fullUpdate(@PathVariable Long id, @RequestBody Client client, @RequestBody Adresse adresse) { clientService.fullUpdate(id, client, adresse); Map response = new HashMap<>(); response.put("message", "Client updated successfully"); response.put("status", true); response.put("data", new HashMap<>()); return ResponseEntity.ok(response); } // Modifier l'address d'un client @PutMapping("/address/{id}") public ResponseEntity> updateAddress(@PathVariable Long id, @RequestBody Adresse adresse) { clientService.updateLocation(id, adresse); Map response = new HashMap<>(); response.put("message", "Client address updated successfully"); response.put("status", true); response.put("data", new HashMap<>()); return ResponseEntity.ok(response); } }