All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.processpuzzle.fitnesse.connect.testbed.service.CarService Maven / Gradle / Ivy

There is a newer version: 1.1.13
Show newest version
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 ) {
      return this.carRepository.findById( id );
   }

   @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