From d0f4fbf1a77475574b4ae8a294fcb45c66cf275b Mon Sep 17 00:00:00 2001 From: Jordan Mason Date: Mon, 28 Sep 2020 12:23:09 -0400 Subject: [PATCH] Updated SQLDriver to get all cards. Added card page. --- .vscode/launch.json | 26 +++++++ pom.xml | 10 +++ src/main/java/MTGClone/SQLDriver.java | 40 +++++++++++ .../MTGClone/controller/CardController.java | 34 ++++++++++ src/main/webapp/WEB-INF/jsp/card.jsp | 67 +++++++++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 src/main/java/MTGClone/controller/CardController.java create mode 100644 src/main/webapp/WEB-INF/jsp/card.jsp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b2916a4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "command": "mvn exec:java", + "name": "Run mvn exec", + "request": "launch", + "type": "node-terminal" + }, + + { + "type": "java", + "name": "Debug (Launch) - Current File", + "request": "launch", + "mainClass": "${file}" + }, + + + + + + ] +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6859331..c9d17a9 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,8 @@ UTF-8 11 11 + 3.2.2.RELEASE + 1.2 @@ -31,7 +33,15 @@ org.springframework.boot spring-boot-starter-web + + + jstl + jstl + ${jstl.version} + + + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/MTGClone/SQLDriver.java b/src/main/java/MTGClone/SQLDriver.java index 2371186..575c631 100644 --- a/src/main/java/MTGClone/SQLDriver.java +++ b/src/main/java/MTGClone/SQLDriver.java @@ -55,6 +55,46 @@ public class SQLDriver { return null; } + public ArrayList getAllCards() { + ArrayList topdeck = new ArrayList(); + try { + c = DriverManager.getConnection("jdbc:sqlite:cards.db"); + c.setAutoCommit(false); + + Statement stmt = c.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM CARDS;"); + String cardName = ""; + int manaCost = 0; + int power = 0; + int toughness = 0; + String description = ""; + String image = ""; + String creatureType = ""; + + while (rs.next()) { + cardName = rs.getString("CARDNAME"); + manaCost = rs.getInt("MANACOST"); + power = rs.getInt("POWER"); + toughness = rs.getInt("TOUGHNESS"); + description = rs.getString("DESCRIPTION"); + image = rs.getString("IMAGE"); + creatureType = rs.getString("CREATURETYPE"); + Card card = new Card(cardName, manaCost, power, toughness, description, image, creatureType); + topdeck.add(card); + } + rs.close(); + stmt.close(); + c.close(); + + return topdeck; + } catch (Exception e) { + System.err.println(e.getClass().getName() + ": " + e.getMessage()); + System.exit(0); + } + System.err.println("Returning null."); + return null; + } + public boolean insertCard(Card card) { Statement stmt = null; try { diff --git a/src/main/java/MTGClone/controller/CardController.java b/src/main/java/MTGClone/controller/CardController.java new file mode 100644 index 0000000..7d8f35b --- /dev/null +++ b/src/main/java/MTGClone/controller/CardController.java @@ -0,0 +1,34 @@ +package MTGClone.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import MTGClone.Card; +import MTGClone.SQLDriver; +import java.util.ArrayList; + +@Controller +public class CardController { + @GetMapping({"/card"}) + public String hello(Model model) { + ArrayList allCards = (new SQLDriver()).getAllCards(); + model.addAttribute("allcards", allCards); + + return "card"; + } + + @PostMapping({"/card"}) + public String greet(@RequestParam("cardname") String cardname, @RequestParam("manacost") int manacost, + @RequestParam("power") int power, @RequestParam("toughness") int toughness, @RequestParam("description") String description, @RequestParam("creaturetype") String creaturetype, + ModelMap modelMap) { + Card newCard = new Card(cardname, manacost, power, toughness, description, "", creaturetype); + SQLDriver d = new SQLDriver(); + d.insertCard(newCard); + return "card"; + } + +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/card.jsp b/src/main/webapp/WEB-INF/jsp/card.jsp new file mode 100644 index 0000000..ede1d1a --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/card.jsp @@ -0,0 +1,67 @@ + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + Hello ${name}! + + +

Hello ${name}!

+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Card NameMana CostPowerToughnessDescriptionCreature Type
${listValue.cardName}${listValue.manaCost}${listValue.power}${listValue.toughness}${listValue.description}${listValue.creatureType}
+ + \ No newline at end of file