|
@@ -1,41 +0,0 @@
|
|
-package eu.jovian_hersemeule.dev.squad.squad_composer.controllers;
|
|
|
|
-
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
-import eu.jovian_hersemeule.dev.squad.squad_composer.data.MechRowMapper;
|
|
|
|
-import eu.jovian_hersemeule.dev.squad.squad_composer.data.model.Mech;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-import javax.sql.DataSource;
|
|
|
|
-
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
-
|
|
|
|
-@RestController
|
|
|
|
-@RequestMapping("/mech")
|
|
|
|
-public class MechController {
|
|
|
|
-
|
|
|
|
- private final JdbcTemplate jdbcTemplate;
|
|
|
|
-
|
|
|
|
- private final MechRowMapper mapper = new MechRowMapper();
|
|
|
|
-
|
|
|
|
- MechController(final DataSource ds) {
|
|
|
|
- jdbcTemplate = new JdbcTemplate(ds);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @GetMapping("/")
|
|
|
|
- public List<Mech> list() {
|
|
|
|
- return jdbcTemplate.query("SELECT * FROM MECH", mapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @GetMapping("/{id}")
|
|
|
|
- public Mech get(@PathVariable final int id) {
|
|
|
|
- final List<Mech> ans = jdbcTemplate.query("SELECT * FROM mech WHERE id = ?", mapper, id);
|
|
|
|
- if (ans.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- return ans.get(0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|