Commit 1b5760bd by Patryk Czarnik

Dodatkowe metody RESTowe

parent cb853633
...@@ -4,6 +4,10 @@ import java.util.List; ...@@ -4,6 +4,10 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; 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 org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -18,4 +22,20 @@ public class BlogRestController { ...@@ -18,4 +22,20 @@ public class BlogRestController {
return blogService.getTeksty(); return blogService.getTeksty();
} }
@GetMapping(path="/{numer}", produces="application/json")
public String getTekst(@PathVariable("numer") int i) {
return blogService.getTekst(i);
}
@PutMapping(path="/{numer}", consumes = {"application/json", "text/plain"})
public void setTekst(
@PathVariable("numer") int i,
@RequestBody String tekst) {
blogService.setTekst(i, tekst);
}
@PostMapping(consumes = {"application/json", "text/plain"})
public void addTekst(@RequestBody String tekst) {
blogService.addTekst(tekst);
}
} }
...@@ -14,6 +14,14 @@ public class BlogService { ...@@ -14,6 +14,14 @@ public class BlogService {
return Collections.unmodifiableList(teksty); return Collections.unmodifiableList(teksty);
} }
public String getTekst(int i) {
return teksty.get(i);
}
public void setTekst(int i, String tekst) {
teksty.set(i, tekst);
}
public void addTekst(String tekst) { public void addTekst(String tekst) {
teksty.add(tekst); teksty.add(tekst);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment