Skip to content

Commit 54ef9eb

Browse files
committed
Graphic API
1 parent ab8dd5a commit 54ef9eb

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

backend/src/main/java/es/codeurjc/wallypop/controller/WallypopWebController.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,8 @@ public String sold(Model model) {
459459
}
460460

461461
@RequestMapping("/graphic")
462-
public String graphic(Model model) {
463-
List<Category> lCategory = categoryservice.findAll();
464-
for (Category c : lCategory) {
465-
c.setSize(c.getARTICLES().size());
466-
}
462+
public String graphic(Model model) throws SQLException {
463+
List<Category> lCategory = categoryservice.graphic();
467464
model.addAttribute("Categories", lCategory);
468465
return "graphic";
469466
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package es.codeurjc.wallypop.controller.api;
2+
3+
import java.sql.SQLException;
4+
import java.util.List;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import es.codeurjc.wallypop.model.Category;
12+
import es.codeurjc.wallypop.service.CategoryService;
13+
14+
@RestController
15+
@RequestMapping("/api/graphic")
16+
public class GraphicRestController {
17+
@Autowired
18+
private CategoryService categoryservice;
19+
20+
@GetMapping("")
21+
public List<Category> graphic() throws SQLException {
22+
List<Category> lCategory = categoryservice.graphic();
23+
return lCategory;
24+
}
25+
}

backend/src/main/java/es/codeurjc/wallypop/service/CategoryService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package es.codeurjc.wallypop.service;
22

3+
import java.sql.SQLException;
34
import java.util.List;
45
import java.util.Optional;
56

@@ -69,5 +70,12 @@ public ResponseEntity<Category> updateCategory(@PathVariable long id, @RequestBo
6970
save(updatedCategory);
7071
return new ResponseEntity<>(updatedCategory, HttpStatus.OK);
7172
}
72-
73+
74+
public List<Category> graphic() throws SQLException {
75+
List<Category> lCategory = categoryrepository.findAll();
76+
for (Category c : lCategory) {
77+
c.setSize(c.getARTICLES().size());
78+
}
79+
return lCategory;
80+
}
7381
}

0 commit comments

Comments
 (0)