BAEL-5313: Use id path variable in the PUT mapping (#11634)

This commit is contained in:
kwoyke 2021-12-29 13:50:16 +01:00 committed by GitHub
parent 81642558b7
commit 26e179e3d3
1 changed files with 6 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import java.text.ParseException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Controller
@ -65,7 +66,11 @@ public class PostRestController {
@PutMapping(value = "/{id}")
@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);
postService.updatePost(post);
}