From 9fdff1ecbab8b4c2ab7d750226d8c12981db163a Mon Sep 17 00:00:00 2001 From: Steven Tracey Date: Thu, 27 Apr 2023 13:51:28 -0400 Subject: [PATCH] Handle location data on backend from id --- .idea/misc.xml | 2 +- locations.json | 20 ++++++++++++++++ src/main/java/tech/nevets/vcardgen/Main.java | 4 +++- src/main/resources/locations.json | 25 -------------------- 4 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 locations.json delete mode 100644 src/main/resources/locations.json diff --git a/.idea/misc.xml b/.idea/misc.xml index 6159638..62299b6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/locations.json b/locations.json new file mode 100644 index 0000000..c25ce07 --- /dev/null +++ b/locations.json @@ -0,0 +1,20 @@ +[ + { + "id": "caiu", + "name": "Capital Area Intermediate Unit", + "address": "55 Miller St, Enola, PA, 17025", + "phone": "(717)732-8400" + }, + { + "id": "caelc", + "name": "Capital Area Early Learning Center", + "address": "4100 Gettysburg Rd, Camp Hill, PA, 17011", + "phone": "(717)732-" + }, + { + "id": "hta", + "name": "Hill Top Academy", + "address": "405 E Winding Hill Rd, Mechanicsburg, PA, 17055", + "phone": "(717)732-8484" + } +] \ No newline at end of file diff --git a/src/main/java/tech/nevets/vcardgen/Main.java b/src/main/java/tech/nevets/vcardgen/Main.java index b0375db..b0cd92e 100644 --- a/src/main/java/tech/nevets/vcardgen/Main.java +++ b/src/main/java/tech/nevets/vcardgen/Main.java @@ -7,6 +7,7 @@ import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; import java.io.IOException; import static spark.Spark.*; @@ -38,11 +39,12 @@ public class Main { res.status(200); res.type("application/json"); res.header("Access-Control-Allow-Origin", "*"); - return Main.class.getResourceAsStream("/locations.json"); + return new FileInputStream("locations.json"); }); post("/", (req, res) -> { res.type("image/png"); + res.header("Access-Control-Allow-Origin", "*"); JsonObject data = new Gson().fromJson(req.body(), JsonObject.class); return generate( data.get("name").getAsString(), diff --git a/src/main/resources/locations.json b/src/main/resources/locations.json deleted file mode 100644 index 549a14c..0000000 --- a/src/main/resources/locations.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "locations": [ - { - "caiu": { - "name": "Capital Area Intermediate Unit", - "address": "55 Miller St, Enola, PA, 17025", - "phone": "(717)732-8400" - } - }, - { - "caelc": { - "name": "Capital Area Early Learning Center", - "address": "4100 Gettysburg Rd, Camp Hill, PA, 17011", - "phone": "(717)732-" - } - }, - { - "hta": { - "name": "Hill Top Academy", - "address": "405 E Winding Hill Rd, Mechanicsburg, PA, 17055", - "phone": "(717)732-8484" - } - } - ] -} \ No newline at end of file