diff --git a/.idea/runConfigurations/bootRun.xml b/.idea/runConfigurations/bootRun.xml
index e92b210..96a8654 100644
--- a/.idea/runConfigurations/bootRun.xml
+++ b/.idea/runConfigurations/bootRun.xml
@@ -1,6 +1,14 @@
+
@@ -15,7 +23,9 @@
- true
+ true
+ true
+ false
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
index f23332c..92ef683 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
+
{
"type": "java",
"name": "Attach Spring",
diff --git a/build.gradle b/build.gradle
index 1a634c4..e826f18 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ plugins {
group = 'com.example'
version = '0.0.1-SNAPSHOT'
-sourceCompatibility = '1.8'
+sourceCompatibility = '1.11'
configurations {
developmentOnly
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
diff --git a/src/main/java/service/MainController.java b/src/main/java/service/MainController.java
index eeb1a1f..1bfb967 100644
--- a/src/main/java/service/MainController.java
+++ b/src/main/java/service/MainController.java
@@ -4,8 +4,11 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import java.util.ArrayList;
+
@Controller
public class MainController {
@Autowired
@@ -20,5 +23,43 @@ public String index() {
public String hello(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "hello";
+
+
+ }
+
+ /* function httpGet(Url)
+ {
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open( "GET", https://house-plants.p.rapidapi.com/common/coralberry, false ); // false for synchronous request
+ xmlHttp.send( https://house-plants.p.rapidapi.com/common/coralberry );
+ return xmlHttp.responseText;
+ }
+ HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
+ public respHttpResponse getResponse() {return response;}
+ */
+
+ @GetMapping("/upload") // change to post later
+ public String uploadPost() {
+ // Post(int PlantId, int Age, String PlantName, String Species, String Status, String NameOfUser, String Caption, String PhotoUrl)
+ Post test = new Post(459, 987, "hi", "kjhgfd", "jgyhtg", "Sophia", "Penguins!", "https://flowermag.com/wp-content/uploads/2018/02/shasta-daisies-becky-1000x669.jpg");
+
+
+ sqlDB.uploadPost(test);
+ return "index";
+ }
+
+ @GetMapping("/feed")
+ public String feed(@RequestParam(name="Clarence", required=false, defaultValue="planty") String name, Model model){
+ model.addAttribute("Clarence", name);
+ Post plant1 = new Post(01, 01, 00, "plantbert", "green", "not green", "Alana", "pretty dead", "https://asset.bloomnation.com/c_pad,d_vendor:global:catalog:product:image.png,f_auto,fl_preserve_transparency,q_auto/v1627197230/vendor/2864/catalog/product/2/0/20200304122155_file_5e5ef4a3ccb60_5e5ef7b7cd5fa_600b664eac11a._600b6650be20c..jpg");
+ Post plant2 = new Post(02, 02, 00, "Belle-adona", "~~blue belle*&^$#@", "livin' life to the fullest", "Alana", "IM BLUE`*%@^!", "https://www.woodlandtrust.org.uk/media/4272/bluebells-close-up-wtml-1024791-web-upload.jpg");
+
+
+ ArrayList posts = new ArrayList();
+ posts = sqlDB.viewPosts();
+ posts.add(plant1);
+ posts.add(plant2);
+ model.addAttribute("posts", posts);
+ return "/feed";
}
}
\ No newline at end of file
diff --git a/src/main/java/service/Post.java b/src/main/java/service/Post.java
new file mode 100644
index 0000000..5133186
--- /dev/null
+++ b/src/main/java/service/Post.java
@@ -0,0 +1,89 @@
+package service;
+
+public class Post {
+ public Integer PostId;
+ public int PlantId, Age;
+ public String PlantName, Species, Status, NameOfUser, Caption, PhotoUrl;
+
+ public Post(int PostId, int PlantId, int Age, String PlantName, String Species, String Status, String NameOfUser, String Caption, String PhotoUrl) {
+ this.PostId = PostId;
+ this.PlantId = PlantId;
+ this.Age = Age;
+ this.PlantName = PlantName;
+ this.Species = Species;
+ this.Status = Status;
+ this.NameOfUser = NameOfUser;
+ this.Caption = Caption;
+ this.PhotoUrl = PhotoUrl;
+ }
+
+ public Post(int PlantId, int Age, String PlantName, String Species, String Status, String NameOfUser, String Caption, String PhotoUrl) {
+ PostId = null; // "created" when post is added to the database
+ this.PlantId = PlantId;
+ this.Age = Age;
+ this.PlantName = PlantName;
+ this.Species = Species;
+ this.Status = Status;
+ this.NameOfUser = NameOfUser;
+ this.Caption = Caption;
+ this.PhotoUrl = PhotoUrl;
+ }
+
+ // all the get methods
+ public int getPostID() {
+ return PostId;
+ }
+ public int getPlantID() {
+ return PlantId;
+ }
+ public int getAge() {
+ return Age;
+ }
+ public String getPlantName() {
+ return PlantName;
+ }
+ public String getSpecies() {
+ return Species;
+ }
+ public String getStatus() {
+ return Status;
+ }
+ public String getNameOfUser() {
+ return NameOfUser;
+ }
+ public String getCaption() {
+ return Caption;
+ }
+ public String getPhotoUrl() {
+ return PhotoUrl;
+ }
+
+ // all the set methods
+ public void setPostID(int PostId) {
+ this.PostId = PostId;
+ }
+ public void setPlantID(int PlantId) {
+ this.PlantId = PlantId;
+ }
+ public void setAge(int age) {
+ this.Age = Age;
+ }
+ public void setPlantName(String PlantName) {
+ this.PlantName = PlantName;
+ }
+ public void setSpecies(String Species) {
+ this.Species = Species;
+ }
+ public void setStatus(String Status) {
+ this.Status = Status;
+ }
+ public void setNameOfUser(String NameOfUser) {
+ this.NameOfUser = NameOfUser;
+ }
+ public void setCaption(String Caption) {
+ this.Caption = Caption;
+ }
+ public void setPhotoUrl(String PhotoUrl) {
+ this.PhotoUrl = PhotoUrl;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/service/SqlDB.java b/src/main/java/service/SqlDB.java
index c7a6976..cc26c35 100644
--- a/src/main/java/service/SqlDB.java
+++ b/src/main/java/service/SqlDB.java
@@ -3,6 +3,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.sql.*;
@Component
public class SqlDB {
@@ -23,6 +25,95 @@ public SqlDB(Environment env) {
+ "hostNameInCertificate=*.database.windows.net;loginTimeout=30;", hostName, dbName, user, password);
}
- // TODO: Add methods to talk to your DB here
+ /*
+ * Take created post information and add it into the database
+ * @param line -
+ */
+ public void uploadPost(Post post) {
+ Connection connect = null;
+ try {
+ connect = DriverManager.getConnection(connectionUrl);
+ // creating the query
+ String query1 = "INSERT INTO Post ([PlantID], [Age], [PlantName], [Species], [Status], [NameOfUser], [Caption], [PhotoURL])";
+ query1 += " VALUES (" + getValues(post) + ");";
+
+ // adding the post to the table
+ Statement st = connect.createStatement();
+ st.execute(query1, Statement.RETURN_GENERATED_KEYS); // check what this returns (returns a boolean)
+
+ //TODO: get PostID and assigned it
+
+ } catch (Exception e) {
+ System.err.println("Got an error in tags query! ");
+ System.err.println(e.getMessage());
+ }
+ }
+
+ public ArrayList viewPosts() {
+ Connection connect = null;
+
+ ArrayList posts = new ArrayList<>();
+
+ try {
+ connect = DriverManager.getConnection(connectionUrl);
+
+ } catch (Exception e) {
+ System.err.println("Got an error in tags query! ");
+ System.err.println(e.getMessage());
+ }
+
+ return posts;
+ }
+
+ public void deletePosts(Post post) {
+ Connection connect = null;
+ try {
+ connect = DriverManager.getConnection(connectionUrl);
+
+ // creating the query
+ String query1 = "DELETE FROM Post WHERE PostID=" + post.getPostID() +
+ ", PlantID=" + post.getPlantID() + ", Age=" + post.getAge() +
+ ", PlantName=" + post.getPlantName() + " Species, Status, NameOfUser, Caption, PhotoURL";
+
+ // deleting the post to the table
+ Statement st = connect.createStatement();
+ st.execute(query1, Statement.RETURN_GENERATED_KEYS);
+ } catch (Exception e) {
+ System.err.println("Got an error in tags query! ");
+ System.err.println(e.getMessage());
+ }
+ }
+
+ public void updatePosts() {
+ Connection connect = null;
+ try {
+ connect = DriverManager.getConnection(connectionUrl);
+
+ } catch (Exception e) {
+ System.err.println("Got an error in tags query! ");
+ System.err.println(e.getMessage());
+ }
+ }
+
+ private String getValues(Post post) {
+ ArrayList temp = new ArrayList<>();
+ temp.add(Integer.toString(post.getPlantID()));
+ temp.add(Integer.toString(post.getAge()));
+ temp.add("N'" + post.getPlantName() + "'");
+ temp.add("N'" + post.getSpecies() + "'");
+ temp.add("N'" + post.getStatus() + "'");
+ temp.add("N'" + post.getNameOfUser() + "'");
+ temp.add("N'" + post.getCaption() + "'");
+ temp.add("N'" + post.getPhotoUrl() + "'");
+
+ String result = "";
+ for (int i = 0; i < temp.size(); i++) {
+ result += temp.get(i);
+ if (i < temp.size() - 1) {
+ result += ", ";
+ }
+ }
+ return result;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/service/plantAPi.java b/src/main/java/service/plantAPi.java
new file mode 100644
index 0000000..510b4ff
--- /dev/null
+++ b/src/main/java/service/plantAPi.java
@@ -0,0 +1,20 @@
+package service;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+
+public class plantAPi {
+ public void api() throws IOException, InterruptedException {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://house-plants.p.rapidapi.com/common/coralberry"))
+ .header("X-RapidAPI-Key", "e3a6efcf20msh357c2c0f26d706dp1bb9fbjsn3c9ffec76d95")
+ .header("X-RapidAPI-Host", "house-plants.p.rapidapi.com")
+ .method("GET", HttpRequest.BodyPublishers.noBody())
+ .build();
+ HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
+ System.out.println(response.body());
+ }
+}
diff --git a/src/main/resources/static/Copy-of-Copy-of-Untitled-1.jpg b/src/main/resources/static/Copy-of-Copy-of-Untitled-1.jpg
new file mode 100644
index 0000000..ee00b51
Binary files /dev/null and b/src/main/resources/static/Copy-of-Copy-of-Untitled-1.jpg differ
diff --git a/src/main/resources/templates/feed.html b/src/main/resources/templates/feed.html
new file mode 100644
index 0000000..747cd4a
--- /dev/null
+++ b/src/main/resources/templates/feed.html
@@ -0,0 +1,123 @@
+
+
+
+
+
+ PlantBook: Main Feed
+
+ Bootstrap Example
+
+
+
+
+
+
+ //
+//< style="height:1500px">
+
+
+
+
+
+
Say hi to some plants!
+
+
+
+
+
+
Plant Name
+
+
Caption
+
+
+
Post 2
+
Post 3
+
Post 4
+
+
Post 5
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index 702abed..54ab6a7 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -5,6 +5,6 @@
-