BAEL-5313: Use id path variable in the PUT mapping (#11634)
This commit is contained in:
parent
81642558b7
commit
26e179e3d3
|
@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -65,7 +66,11 @@ public class PostRestController {
|
||||||
|
|
||||||
@PutMapping(value = "/{id}")
|
@PutMapping(value = "/{id}")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public void updatePost(@RequestBody PostDto postDto) throws ParseException {
|
public void updatePost(@PathVariable("id") Long id, @RequestBody PostDto postDto) throws ParseException {
|
||||||
|
if(!Objects.equals(id, postDto.getId())){
|
||||||
|
throw new IllegalArgumentException("IDs don't match");
|
||||||
|
}
|
||||||
|
|
||||||
Post post = convertToEntity(postDto);
|
Post post = convertToEntity(postDto);
|
||||||
postService.updatePost(post);
|
postService.updatePost(post);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue