Skip to content

Commit 7f30777

Browse files
committed
API report post report
posible solution to fix post report
1 parent 6c5ed98 commit 7f30777

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

backend/src/main/java/es/codeurjc/wallypop/controller/api/ReportRestController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.web.bind.annotation.*;
1515

1616
import es.codeurjc.wallypop.model.Report;
17+
import es.codeurjc.wallypop.service.ArticleService;
1718
import es.codeurjc.wallypop.service.ReportService;
1819
import org.springframework.web.multipart.MultipartFile;
1920

@@ -25,12 +26,16 @@ public class ReportRestController {
2526

2627
@Autowired
2728
private ReportService reportService;
28-
29-
@PostMapping("")
29+
@Autowired
30+
private ArticleService articleService;
31+
32+
@PostMapping("/{idArticle}")
3033
@ResponseStatus(HttpStatus.CREATED)
31-
public ResponseEntity<Report> createReport(@RequestBody Report report) {
32-
reportService.save(report);
33-
return new ResponseEntity<>(report, HttpStatus.OK);
34+
public ResponseEntity<Report> createReport(@PathVariable long idArticle,@RequestBody Report report) {
35+
reportService.save(report);
36+
reportService.findById(report.getID_REPORT()).get().setARTICLE(articleService.findById(idArticle).get());
37+
reportService.flush();
38+
return new ResponseEntity<>(report, HttpStatus.OK);
3439
}
3540

3641
@PostMapping("/{idReport}/image")

0 commit comments

Comments
 (0)