Files
0xb00b5-packmate/src/main/java/ru/serega6531/packmate/controller/PatternController.java

37 lines
900 B
Java

package ru.serega6531.packmate.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.serega6531.packmate.model.Pattern;
import ru.serega6531.packmate.service.PatternService;
import java.util.Collection;
@RestController
@RequestMapping("/api/pattern/")
public class PatternController {
private final PatternService service;
@Autowired
public PatternController(PatternService service) {
this.service = service;
}
@GetMapping
public Collection<Pattern> getPatterns() {
return service.findAll();
}
@PostMapping("/{id}")
public void enable(@PathVariable int id, @RequestParam boolean enabled) {
service.enable(id, enabled);
}
@PostMapping
public Pattern addPattern(@RequestBody Pattern pattern) {
return service.save(pattern);
}
}