-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCarRentalController.java
43 lines (35 loc) · 1.11 KB
/
CarRentalController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.univ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@RestController
public class CarRentalController {
CarRepository carRepository;
@Autowired
public CarRentalController(CarRepository carRepository){
this.carRepository = carRepository;
Car ferrari = new Car();
ferrari.setPlateNumber("11AA22");
ferrari.setModel("Ferrari");
ferrari.setPrice(1000);
ferrari.setRented(false);
carRepository.save(ferrari);
}
@CrossOrigin(origins = "http://localhost:4200")
@GetMapping("/cars")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Iterable<Car> listOfCars(){
return carRepository.findAll();
}
@CrossOrigin(origins = "http://localhost:4200")
@PutMapping("/cars/{plateNumber}")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Car rent(@PathVariable(name="plateNumber") String plateNumber, @RequestParam(name="louer", required=true) boolean louer) {
Car car = carRepository.findByPlateNumber(plateNumber);
car.setRented(louer);
System.out.println(car);
return car;
}
}