
com.processpuzzle.fitnesse.connect.testbed.service.CarService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse-connect-testbed-backend Show documentation
Show all versions of fitnesse-connect-testbed-backend Show documentation
Test server for integration tests
package com.processpuzzle.fitnesse.connect.testbed.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.ExposesResourceFor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.processpuzzle.fitnesse.connect.testbed.application.RestApiController;
import com.processpuzzle.fitnesse.connect.testbed.domain.Car;
import com.processpuzzle.fitnesse.connect.testbed.integration.CarRepository;
//@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@RestApiController( "cars" )
@ExposesResourceFor( Car.class )
public class CarService {
private final CarRepository carRepository;
@Autowired public CarService( CarRepository carRepository ) {
this.carRepository = carRepository;
}
@PostMapping( produces = MediaType.APPLICATION_JSON_VALUE ) public Car add( @RequestBody Car newCar ) {
return carRepository.save( newCar );
}
@DeleteMapping( path = "/{id}" ) void delete( @PathVariable Long id ) {
this.carRepository.delete( id );
}
@GetMapping( value = "", produces = MediaType.APPLICATION_JSON_VALUE ) public Iterable findAll() {
return this.carRepository.findAll();
}
@GetMapping( path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE ) Car findById( @PathVariable Long id ) {
Car foundCar = this.carRepository.findById( id );
if( foundCar == null ){
throw new CarNotFoundException( id );
}
return foundCar;
}
@GetMapping( path = "/make/{make}", produces = MediaType.APPLICATION_JSON_VALUE ) Iterable findByMake( @PathVariable String make ) {
return carRepository.findByMakeIgnoringCase( make );
}
@PutMapping( path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE ) public Car update( @PathVariable Long id, @RequestBody Car car ) {
return carRepository.save( car );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy