Skip to content
Open

Feed #18

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
adb6025
Post Java Class
Oct 31, 2022
6bf0309
Stylized feed page (nav bar)
alana-kiwi23 Nov 16, 2022
668435c
11/16/22
anaiysaa Nov 16, 2022
d26c796
11/16/22
anaiysaa Nov 16, 2022
8b29a17
added @PostMapping to api path
jasmine-xnf Nov 21, 2022
956342c
Merge branch 'api' of https://github.com/HolyNamesAcademy/Projects-II…
anaiysaa Nov 21, 2022
fbf2c5c
Merge branch 'master' into api
anaiysaa Nov 21, 2022
3b01cbb
11/23/2022
AerialAstrea Nov 23, 2022
437f7a6
Stylized feed page (nav bar)
alana-kiwi23 Nov 23, 2022
82b8edf
small comments and little changes
AerialAstrea Nov 28, 2022
575d04d
Update bootRun.xml
anmac42 Nov 28, 2022
d6d3309
cleaned up some errors
AerialAstrea Nov 28, 2022
83d50ec
Merge branch 'database' of https://github.com/HolyNamesAcademy/Projec…
AerialAstrea Nov 28, 2022
e33988c
finally builds!!!
AerialAstrea Nov 28, 2022
c824a09
updated @PostMapping
jasmine-xnf Dec 7, 2022
21dc21b
Stylized feed page (nav bar)
alana-kiwi23 Dec 7, 2022
5e37a45
updated @PostMapping
jasmine-xnf Dec 7, 2022
c9a17d0
:))
AerialAstrea Dec 7, 2022
af78929
Stylized feed page (nav bar)
alana-kiwi23 Dec 7, 2022
a9bf677
still need to figure out postid
AerialAstrea Dec 12, 2022
731e9d0
Stylized feed page (nav bar)
alana-kiwi23 Dec 12, 2022
d9fa470
11/16/22
anaiysaa Dec 14, 2022
6121358
Stylized feed page (nav bar)
alana-kiwi23 Jan 11, 2023
fd7837a
added other method headers
AerialAstrea Jan 11, 2023
3fe95b2
in azure works ;) but in here tho but did some changes
AerialAstrea Jan 12, 2023
e3459fc
ahhh
AerialAstrea Jan 25, 2023
6f8247b
it works <333
AerialAstrea Jan 25, 2023
aabb5d9
:))
AerialAstrea Jan 25, 2023
1ad408d
naming of methods in Post
AerialAstrea Jan 25, 2023
2260da0
null postid
AerialAstrea Jan 25, 2023
f02da00
new constructor & changing variable
AerialAstrea Jan 25, 2023
34486ae
:)
AerialAstrea Jan 26, 2023
e5a35ee
Merge branch 'master' into database
AerialAstrea Jan 30, 2023
4fdb504
remove env
AerialAstrea Jan 30, 2023
7af2801
Update MainController.java
AerialAstrea Jan 30, 2023
32d6a38
Merge pull request #1 from HolyNamesAcademy/database
AerialAstrea Jan 30, 2023
d40a436
Stylized feed page (nav bar)
alana-kiwi23 Jan 30, 2023
441eefd
Stylized feed page (nav bar)
alana-kiwi23 Jan 30, 2023
c3d7cfe
Stylized feed page (nav bar)
alana-kiwi23 Feb 1, 2023
a0ebb20
Merge branch 'master' into Feed
alana-kiwi23 Feb 8, 2023
b087b44
Merge remote-tracking branch 'origin/Feed' into Feed
alana-kiwi23 Feb 8, 2023
c0c5809
java type
alana-kiwi23 Feb 13, 2023
7eb2edf
setting up for loop to auto-add posts from database
alana-kiwi23 Feb 13, 2023
1df6f0c
ready for database
alana-kiwi23 Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .idea/runConfigurations/bootRun.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
sourceCompatibility = '1.11'

configurations {
developmentOnly
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
41 changes: 41 additions & 0 deletions src/main/java/service/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
public respHttpResponse<String> 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<Post> posts = new ArrayList<Post>();
posts = sqlDB.viewPosts();
posts.add(plant1);
posts.add(plant2);
model.addAttribute("posts", posts);
return "/feed";
}
}
89 changes: 89 additions & 0 deletions src/main/java/service/Post.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
93 changes: 92 additions & 1 deletion src/main/java/service/SqlDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Post> viewPosts() {
Connection connect = null;

ArrayList<Post> 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<String> 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;
}
}
20 changes: 20 additions & 0 deletions src/main/java/service/plantAPi.java
Original file line number Diff line number Diff line change
@@ -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<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading