Merge branch 'main' into facture

This commit is contained in:
Olivier PARPAILLON
2025-07-16 10:05:28 +02:00
4 changed files with 163 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
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<Map<String, Object>> create(@RequestBody Client client) {
clientService.add(client);
Map<String, Object> 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<Map<String, Object>> findByEmail(@PathVariable String name) {
List<Client> result = clientService.findByName(name);
Map<String, Object> 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<Map<String, Object>> findByEmail(@PathVariable Long id) {
Client result = clientService.findById(id);
Map<String, Object> 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<Map<String, Object>> fullUpdate(@PathVariable Long id, @RequestBody Client client, @RequestBody Adresse adresse) {
clientService.fullUpdate(id, client, adresse);
Map<String, Object> 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("/{id}")
public ResponseEntity<Map<String, Object>> updateAddress(@PathVariable Long id, @RequestBody Adresse adresse) {
clientService.updateLocation(id, adresse);
Map<String, Object> response = new HashMap<>();
response.put("message", "Client address updated successfully");
response.put("status", true);
response.put("data", new HashMap<>());
return ResponseEntity.ok(response);
}
}

View File

@@ -0,0 +1,36 @@
package fr.eni.demo.controller;
import fr.eni.demo.bll.ClientService;
import fr.eni.demo.bll.LocationService;
import fr.eni.demo.bo.Client;
import fr.eni.demo.bo.Location;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/location")
@RequiredArgsConstructor
public class LocationController {
private final LocationService locationService;
// Ajouter une location
@PostMapping
public ResponseEntity<Map<String, Object>> create(@RequestBody Location location) {
locationService.add(location);
Map<String, Object> response = new HashMap<>();
response.put("message", "Location added");
response.put("status", true);
response.put("data", new HashMap<>());
return ResponseEntity.ok(response);
}
}

View File

@@ -0,0 +1,45 @@
package fr.eni.demo.controller;
import fr.eni.demo.bll.StockService;
import fr.eni.demo.bo.Stock;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@RestController
@RequestMapping("/api/stock")
@RequiredArgsConstructor
public class StockController {
private final StockService stockService;
// Ajouter un stock
@PostMapping
public ResponseEntity<Map<String, Object>> create(@RequestBody Stock stock) {
stockService.add(stock);
Map<String, Object> response = new HashMap<>();
response.put("message", "Stock added");
response.put("status", true);
response.put("data", new HashMap<>());
return ResponseEntity.ok(response);
}
// Chercher des clients par nom
@GetMapping("/{id}")
public ResponseEntity<Map<String, Object>> findById(@PathVariable Long id) {
Optional<Stock> result = stockService.findById(id);
Map<String, Object> response = new HashMap<>();
response.put("message", "List of Clients found");
response.put("status", true);
response.put("data", result);
return ResponseEntity.ok(response);
}
}

View File

@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
@Repository @Repository
public interface ClientRepository extends JpaRepository<Client, Long> { public interface ClientRepository extends JpaRepository<Client, Long> {