Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
dc5ce9b
Created homepage
Oct 12, 2020
39cf41b
started basic outlines of home pages
jmargarones21 Oct 19, 2020
2c79e3a
Created subject & class lists for homepage and subject templates
Oct 21, 2020
ab58158
Created html links that takes each subject and links to a different page
Oct 26, 2020
b9a73c0
Merge branch 'master' into maura-branch
jmargarones21 Oct 28, 2020
587ad05
Merge pull request #1 from mswitzer/maura-branch
jmargarones21 Oct 28, 2020
a0b4cb2
Added image to homepage & created a css page.
Nov 4, 2020
09f875c
Styled homepage images and buttons
Nov 9, 2020
d01fa6f
Centered and styled homepage images and links.
Nov 16, 2020
4e7c53d
Made links look like buttons and added a class page in templates.
Nov 18, 2020
3c4c3d2
Created new class page in MainController
Nov 23, 2020
ff8921e
Created new class page in MainController
Nov 30, 2020
fd405c5
started database class
jsmargarones Dec 2, 2020
b43dbdf
Updated homepage design - need to create getmapping classpage next
Dec 2, 2020
f5ac239
Updated homepage design - need to create getmapping classpage next
Dec 2, 2020
180c4b2
worked on database class
jsmargarones Dec 7, 2020
4598557
Created new @GetMapping page to connect to class page
Dec 7, 2020
f3ec7d7
Changed homepage design from flex-container to grid-container to make…
Dec 9, 2020
1b22876
CHANGE NAME CLASS TO SOMETHING ELSE
jsmargarones Dec 9, 2020
475ad14
fixed errors
jsmargarones Dec 14, 2020
c731e4b
Updated font style & button size - when database is linked, wull be a…
Dec 14, 2020
241d685
fixed errors
jsmargarones Dec 16, 2020
b9e93c3
Homepage & subject page code
Jan 4, 2021
5a9a6f1
Merge branch 'master' into maura-branch
Jan 6, 2021
7fdeaab
Homepage code (html & css)
Jan 6, 2021
b725832
Merge pull request #2 from mswitzer/maura-branch
mswitzer Jan 11, 2021
6f00093
Created environment variable for password
Jan 11, 2021
be993c1
Merge pull request #3 from mswitzer/maura-branch
mswitzer Jan 11, 2021
8f437c0
Updated subject page code
Jan 27, 2021
a41b8d8
Formatted headings for homepage & subject page with new css
Feb 2, 2021
f440631
subjectId is now included in link to subject pages
Feb 3, 2021
db5a772
Called classInfo method in MainController, working on accessing array…
Feb 11, 2021
64df75d
Fixed issues in MainController, working on using array in subject page
Feb 17, 2021
f75185c
Fixed issues in MainController, working on using array in subject page
Feb 24, 2021
3df5069
Updated database connection url
Mar 3, 2021
2912150
fixed errors
jsmargarones Mar 3, 2021
72f8c43
fixed errors
jsmargarones Mar 15, 2021
160c092
added new icons
jsmargarones Mar 31, 2021
231f2fe
Fixed database so links print on classPage
Mar 31, 2021
066cbf4
Merge remote-tracking branch 'origin/maura-branch' into maura-branch
Apr 12, 2021
7eab503
Updated CSS for homepage, subject page, and class page
Apr 12, 2021
abc82f0
More homepage updates
Apr 14, 2021
bc5e332
Merge pull request #4 from mswitzer/master
mswitzer Apr 14, 2021
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
5 changes: 5 additions & 0 deletions .idea/runConfigurations/bootRun.xml

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

74 changes: 74 additions & 0 deletions src/main/java/service/ClassConnector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package hello;
import java.util.ArrayList;

public class ClassConnector{
private int ClassID;
private String ClassName;
private String SubjectName;
private int SubjectID;
private String linkName;
private int linkID;

public ClassConnector(String cn, int cID, String sn, int sID, String ln, int lID){
ClassID = cID;
ClassName = cn;
SubjectName = sn;
SubjectID = sID;
linkName = ln;
linkID = lID;
}

public ClassConnector(String cn, int cID, int sID){
ClassID = cID;
ClassName = cn;
SubjectID = sID;
}

public ClassConnector(int cID, String ln, int lID){
ClassID = cID;
linkName = ln;
linkID = lID;
}

public int getClassID(){
return ClassID;
}

public String getClassName(){
return ClassName;
}

public int getSubjectID(){
return SubjectID;
}

public String getSubjectName() {
return SubjectName;
}

public String getLinkName() {return linkName;}

public int getLinkID() {return linkID;}

public void setClassID(int cID){
ClassID = cID;
}

public void setClassName(String cn){
ClassName = cn;
}

public void setSubjectID(int sID){
SubjectID = sID;
}

public void setSubjectName(String sn){
SubjectName = sn;
}

public void setLinkName(String ln) { linkName = ln;}

public void setLinkID(int lID) {linkID = lID;}


}
212 changes: 212 additions & 0 deletions src/main/java/service/DataBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@


package hello;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Map;
import java.net.URL;
import java.lang.Integer;

//@Controller
public class DataBase {

/* @GetMapping("/greeting")
public String greeting(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}

*/

public void CallDatabase() {

// Connect to DataBase.java
String hostName = "holynamesacademy.DataBase.java.windows.net";
String dbName = "HNAResources";
String user = "hna-admin";
String password = "HolyNames123";
String url = String.format("jdbc:sqlserver://%s:1433;DataBase.java=%s;user=%s;password=%s;encrypt=true;"
+ "hostNameInCertificate=*.DataBase.java.windows.net;loginTimeout=30;",hostName, dbName, user, password)
;
Connection connection = null;

try {
connection = DriverManager.getConnection(url);
String schema = connection.getSchema();
System.out.println("Successful connection - Schema: " + schema);

System.out.println("Query data example:");
System.out.println("=========================================");

// Create and execute a SELECT SQL statement.
String selectSql = "SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName "
+ "FROM [SalesLT].[ProductCategory] pc "
+ "JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid";

String selectSql2 = " SELECT * from Players; ";

try (Statement statement = connection.createStatement();
ResultSet resultSet2 = statement.executeQuery(selectSql2)) {

// Print results from select statement
System.out.println("Top 20 categories:");
while (resultSet2.next()) {
System.out.println(resultSet2.getInt(1) + " "
+ resultSet2.getString(2));
}
connection.close();
} catch (Exception e) {
e.printStackTrace();
}


} catch (Exception e) {
e.printStackTrace();
}
}

public static ArrayList<ClassConnector> ClassInfo(int subjectId) {
ArrayList<ClassConnector> classes = new ArrayList<ClassConnector>();
ClassConnector newClassConnector = new ClassConnector("noName", 0, subjectId);

try {
// create our mysql DataBase.java connection
//String myDriver = "org.gjt.mm.mysql.Driver";
// String myUrl = "jdbc:mysql://localhost/test";
// Class.forName(myDriver);
// Connection conn = DriverManager.getConnection(myUrl, "root", "");

String hostName = "holynamesacademy.database.windows.net";
String dbName = "HNAResources";
String user = "hna-admin";
Map<String, String> env = System.getenv();
String password = env.get("password");
//password here

String url = String.format("jdbc:sqlserver://%s:1433;database=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=true;"
+ "hostNameInCertificate=*.DataBase.java.windows.net;loginTimeout=30;", hostName, dbName, user, password);
Connection connection = null;


connection = DriverManager.getConnection(url);

// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
//get subjectId from maincontroller, pluge it into SubjectId + change to int

String query = "select * from [HNAResources].[dbo].[Classes] where SubjectId = " + subjectId; //where SubjectId = ???"

// create the java statement
Statement st = connection.createStatement();

// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);

// iterate through the java resultset
while (rs.next()) {
int id = rs.getInt("ClassId");
newClassConnector.setClassID(id);
String name = rs.getString("ClassName");
newClassConnector.setClassName(name);


classes.add(newClassConnector);

// print the results
System.out.format("%d, %s\n", newClassConnector.getClassID(), newClassConnector.getClassName());

System.out.print(newClassConnector.getClassName());

newClassConnector = new ClassConnector("noName", 0, 0);

}
st.close();


} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}

return classes;
}

public static ArrayList<ClassConnector> LinkInfo(int classId) {
ArrayList<ClassConnector> classes = new ArrayList<ClassConnector>();
ClassConnector newClassConnector = new ClassConnector(classId,"noName", 0);

try {
// create our mysql DataBase.java connection
//String myDriver = "org.gjt.mm.mysql.Driver";
// String myUrl = "jdbc:mysql://localhost/test";
// Class.forName(myDriver);
// Connection conn = DriverManager.getConnection(myUrl, "root", "");

String hostName = "holynamesacademy.database.windows.net";
String dbName = "HNAResources";
String user = "hna-admin";
Map<String, String> env = System.getenv();
String password = env.get("password");
//password here

String url = String.format("jdbc:sqlserver://%s:1433;database=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=true;"
+ "hostNameInCertificate=*.DataBase.java.windows.net;loginTimeout=30;", hostName, dbName, user, password);
Connection connection = null;


connection = DriverManager.getConnection(url);

// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
//get subjectId from maincontroller, pluge it into SubjectId + change to int

String query = "SELECT LinkId, Link FROM ClassLinks WHERE ClassId = " + classId; //where SubjectId = ???"

// create the java statement
Statement st = connection.createStatement();

// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);

// iterate through the java resultset
while (rs.next()) {
int id = rs.getInt("LinkId");
newClassConnector.setLinkID(id);
String name = rs.getString("Link");
newClassConnector.setLinkName(name);


classes.add(newClassConnector);

// print the results
System.out.format("%d, %s\n", newClassConnector.getLinkID(), newClassConnector.getLinkName());

System.out.print(newClassConnector.getLinkName());

newClassConnector = new ClassConnector(0, "noName", 0);

}
st.close();


} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}

return classes;
}

}

34 changes: 30 additions & 4 deletions src/main/java/service/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.ArrayList;
import hello.DataBase;
import hello.ClassConnector;

@Controller
public class MainController {

@GetMapping("/hello")
public String hello(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "hello";
//public ArrayList<ClassConnector> databaseClasses = new ArrayList<ClassConnector>();

DataBase databaseClasses = new DataBase();

@GetMapping("/subject")
public String subject(@RequestParam(name="subject", required=true) String name, Model model,
@RequestParam(name="subjectId", required=true) int subjectId) {
ArrayList<ClassConnector> classList = databaseClasses.ClassInfo(subjectId);
model.addAttribute("subject", name);
model.addAttribute("subjectId", subjectId);
model.addAttribute("classList", classList);
return "subject";
}




@GetMapping("/class/{classId}")
public String classPage(@PathVariable("classId") int classId, Model model) {
ArrayList<ClassConnector> linkList = databaseClasses.LinkInfo(classId);
model.addAttribute("classId", classId);
model.addAttribute("linkList", linkList);
return "classPage";
}




}
Binary file added src/main/resources/static/HNA logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/elective.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/english.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading