lab 4 favor controller done
This commit is contained in:
parent
e57f9fc252
commit
5117a688fc
@ -1,4 +1,47 @@
|
||||
package ru.ulstu.is.sbapp.repair.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.Valid;
|
||||
import ru.ulstu.is.sbapp.repair.service.FavorService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/component")
|
||||
public class FavorController {
|
||||
private final FavorService favorService;
|
||||
public FavorController(FavorService favorService){
|
||||
this.favorService = favorService;
|
||||
}
|
||||
@PostMapping
|
||||
public FavorDTO addProduct(@RequestBody @Valid FavorDTO favorDTO) {
|
||||
return new FavorDTO(favorService.addFavor(favorDTO));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public FavorDTO updateProduct(@PathVariable Long id,@RequestBody @Valid FavorDTO favorDTO) {
|
||||
return new FavorDTO(favorService.updateFavor(id,favorDTO));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public FavorDTO removeProduct(@PathVariable Long id) {
|
||||
return new FavorDTO(favorService.deleteFavor(id));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public void removeAllProducts() {
|
||||
favorService.deleteAllFavor();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public FavorDTO findProduct(@PathVariable Long id) {
|
||||
return new FavorDTO(favorService.findFavor(id));
|
||||
}
|
||||
@GetMapping
|
||||
public List<FavorDTO> findAllProduct() {
|
||||
return favorService.findAllFavor()
|
||||
.stream()
|
||||
.map(FavorDTO::new)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user