Added a basic first index with header fragment, and configured the project for mysql.
This commit is contained in:
		
							parent
							
								
									a22d759399
								
							
						
					
					
						commit
						672bafbfcf
					
				
							
								
								
									
										6
									
								
								pom.xml
								
								
								
								
							
							
						
						
									
										6
									
								
								pom.xml
								
								
								
								
							| 
						 | 
					@ -69,10 +69,16 @@
 | 
				
			||||||
			<scope>test</scope>
 | 
								<scope>test</scope>
 | 
				
			||||||
		</dependency>
 | 
							</dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<!-- Database Drivers -->
 | 
				
			||||||
		<dependency>
 | 
							<dependency>
 | 
				
			||||||
			<groupId>com.h2database</groupId>
 | 
								<groupId>com.h2database</groupId>
 | 
				
			||||||
			<artifactId>h2</artifactId>
 | 
								<artifactId>h2</artifactId>
 | 
				
			||||||
		</dependency>
 | 
							</dependency>
 | 
				
			||||||
 | 
							<dependency>
 | 
				
			||||||
 | 
								<groupId>mysql</groupId>
 | 
				
			||||||
 | 
								<artifactId>mysql-connector-java</artifactId>
 | 
				
			||||||
 | 
								<version>8.0.15</version>
 | 
				
			||||||
 | 
							</dependency>
 | 
				
			||||||
	</dependencies>
 | 
						</dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	<build>
 | 
						<build>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,13 +1,29 @@
 | 
				
			||||||
package nl.andrewlalis.teaching_assistant_assistant;
 | 
					package nl.andrewlalis.teaching_assistant_assistant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.Course;
 | 
				
			||||||
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
 | 
					import org.springframework.boot.CommandLineRunner;
 | 
				
			||||||
import org.springframework.boot.SpringApplication;
 | 
					import org.springframework.boot.SpringApplication;
 | 
				
			||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
					import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
				
			||||||
 | 
					import org.springframework.data.repository.CrudRepository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SpringBootApplication
 | 
					@SpringBootApplication
 | 
				
			||||||
public class TeachingAssistantAssistantApplication {
 | 
					public class TeachingAssistantAssistantApplication implements CommandLineRunner {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Autowired
 | 
				
			||||||
 | 
						CourseRepository courseRepository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void main(String[] args) {
 | 
						public static void main(String[] args) {
 | 
				
			||||||
		SpringApplication.run(TeachingAssistantAssistantApplication.class, args);
 | 
							SpringApplication.run(TeachingAssistantAssistantApplication.class, args);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void run(String... args) throws Exception {
 | 
				
			||||||
 | 
							System.out.println("Running startup...");
 | 
				
			||||||
 | 
							courseRepository.save(new Course("Intro to Information Systems", "INF-1"));
 | 
				
			||||||
 | 
							courseRepository.save(new Course("Program Correctness", "PC-002"));
 | 
				
			||||||
 | 
							System.out.println("Saved two courses.");
 | 
				
			||||||
 | 
							System.out.println("Course count: " + courseRepository.count());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					package nl.andrewlalis.teaching_assistant_assistant.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.boot.context.properties.ConfigurationProperties;
 | 
				
			||||||
 | 
					import org.springframework.boot.jdbc.DataSourceBuilder;
 | 
				
			||||||
 | 
					import org.springframework.context.annotation.Bean;
 | 
				
			||||||
 | 
					import org.springframework.context.annotation.Configuration;
 | 
				
			||||||
 | 
					import org.springframework.context.annotation.Primary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.sql.DataSource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Configures the data source for this application.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Configuration
 | 
				
			||||||
 | 
					public class DataSourceConfig {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final String USERNAME = "root";
 | 
				
			||||||
 | 
					    private static final String PASSWORD = "root";
 | 
				
			||||||
 | 
					    private static final String DB_HOST = "localhost";
 | 
				
			||||||
 | 
					    private static final String DB_NAME = "teaching_assistant_assistant";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ConfigurationProperties(prefix = "spring.datasource")
 | 
				
			||||||
 | 
					    @Bean
 | 
				
			||||||
 | 
					    @Primary
 | 
				
			||||||
 | 
					    public DataSource getDataSource() {
 | 
				
			||||||
 | 
					        return DataSourceBuilder
 | 
				
			||||||
 | 
					                .create()
 | 
				
			||||||
 | 
					                .url("jdbc:mysql://" + DB_HOST + '/' + DB_NAME)
 | 
				
			||||||
 | 
					                .username(USERNAME)
 | 
				
			||||||
 | 
					                .password(PASSWORD)
 | 
				
			||||||
 | 
					                .build();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,20 @@
 | 
				
			||||||
 | 
					package nl.andrewlalis.teaching_assistant_assistant.controllers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Controller;
 | 
				
			||||||
 | 
					import org.springframework.ui.Model;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.ResponseBody;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Controller
 | 
				
			||||||
 | 
					public class RootController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @RequestMapping(
 | 
				
			||||||
 | 
					            path = "/",
 | 
				
			||||||
 | 
					            produces = "text/html"
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    public String index(Model model) {
 | 
				
			||||||
 | 
					        model.addAttribute("name", "JOHN");
 | 
				
			||||||
 | 
					        return "index.html";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -10,10 +10,12 @@ import java.util.Date;
 | 
				
			||||||
 * in this system should extend from BasicEntity.
 | 
					 * in this system should extend from BasicEntity.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@MappedSuperclass
 | 
					@MappedSuperclass
 | 
				
			||||||
public class BasicEntity {
 | 
					public abstract class BasicEntity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Id
 | 
					    @Id
 | 
				
			||||||
    @GeneratedValue
 | 
					    @GeneratedValue(
 | 
				
			||||||
 | 
					            strategy = GenerationType.IDENTITY
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    private Long id;
 | 
					    private Long id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Temporal(
 | 
					    @Temporal(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,11 @@
 | 
				
			||||||
package nl.andrewlalis.teaching_assistant_assistant.model;
 | 
					package nl.andrewlalis.teaching_assistant_assistant.model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.persistence.Column;
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment;
 | 
				
			||||||
import javax.persistence.Entity;
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.people.Student;
 | 
				
			||||||
import javax.persistence.Inheritance;
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
 | 
				
			||||||
import javax.persistence.InheritanceType;
 | 
					
 | 
				
			||||||
 | 
					import javax.persistence.*;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Represents a course, containing many students and teaching assistants, as well as a collection of assignments.
 | 
					 * Represents a course, containing many students and teaching assistants, as well as a collection of assignments.
 | 
				
			||||||
| 
						 | 
					@ -14,15 +16,64 @@ import javax.persistence.InheritanceType;
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
public class Course extends BasicEntity {
 | 
					public class Course extends BasicEntity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The human-readable name for this course.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Column(unique = true, nullable = false)
 | 
					    @Column(unique = true, nullable = false)
 | 
				
			||||||
    private String name;
 | 
					    private String name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The unique identifying code for this course.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Column(unique = true, nullable = false)
 | 
					    @Column(unique = true, nullable = false)
 | 
				
			||||||
    private String code;
 | 
					    private String code;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The list of students participating in this course. This is a many-to-many relationship because a course can
 | 
				
			||||||
 | 
					     * contain multiple students, and a student can participate in multiple courses at once.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @ManyToMany
 | 
				
			||||||
 | 
					    @JoinTable(
 | 
				
			||||||
 | 
					            name = "course_student",
 | 
				
			||||||
 | 
					            joinColumns = @JoinColumn(name = "course_id"),
 | 
				
			||||||
 | 
					            inverseJoinColumns = @JoinColumn(name = "student_id")
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    private List<Student> students;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The list of teaching assistants managing this course. Just like for students, this is a many-to-many relation.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @ManyToMany
 | 
				
			||||||
 | 
					    @JoinTable(
 | 
				
			||||||
 | 
					            name = "course_teachingAssistant",
 | 
				
			||||||
 | 
					            joinColumns = @JoinColumn(name = "course_id"),
 | 
				
			||||||
 | 
					            inverseJoinColumns = @JoinColumn(name = "teachingAssistant_id")
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    private List<TeachingAssistant> teachingAssistants;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The list of assignments this course contains.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @OneToMany(
 | 
				
			||||||
 | 
					            fetch = FetchType.LAZY,
 | 
				
			||||||
 | 
					            orphanRemoval = true
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    @JoinColumn(name = "course_id")
 | 
				
			||||||
 | 
					    private List<Assignment> assignments;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Default constructor for JPA.
 | 
					     * Default constructor for JPA.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected Course() {}
 | 
					    protected Course() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Constructs a new Course object.
 | 
				
			||||||
 | 
					     * @param name The name of the course.
 | 
				
			||||||
 | 
					     * @param code The course's unique code.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public Course(String name, String code) {
 | 
				
			||||||
 | 
					        this.name = name;
 | 
				
			||||||
 | 
					        this.code = code;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,7 @@ public class Assignment extends BasicEntity {
 | 
				
			||||||
            fetch = FetchType.EAGER,
 | 
					            fetch = FetchType.EAGER,
 | 
				
			||||||
            orphanRemoval = true
 | 
					            orphanRemoval = true
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					    @JoinColumn(name = "assignment_id")
 | 
				
			||||||
    private List<AssignmentSection> sections;
 | 
					    private List<AssignmentSection> sections;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ import javax.persistence.*;
 | 
				
			||||||
@Inheritance(
 | 
					@Inheritance(
 | 
				
			||||||
        strategy = InheritanceType.JOINED
 | 
					        strategy = InheritanceType.JOINED
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
public class Person extends BasicEntity {
 | 
					public abstract class Person extends BasicEntity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Column(nullable = false)
 | 
					    @Column(nullable = false)
 | 
				
			||||||
    private String firstName;
 | 
					    private String firstName;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,4 +8,10 @@ import javax.persistence.Entity;
 | 
				
			||||||
@Entity
 | 
					@Entity
 | 
				
			||||||
public class Student extends Person {
 | 
					public class Student extends Person {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Student(String firstName, String lastName, String emailAddress) {
 | 
				
			||||||
 | 
					        super(firstName, lastName, emailAddress);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					package nl.andrewlalis.teaching_assistant_assistant.model.repositories;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nl.andrewlalis.teaching_assistant_assistant.model.Course;
 | 
				
			||||||
 | 
					import org.springframework.data.repository.CrudRepository;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Repository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * The repository used to interact with various Course objects.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Repository
 | 
				
			||||||
 | 
					public interface CourseRepository extends CrudRepository<Course, Long> {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
 | 
					spring.jpa.hibernate.ddl-auto=create-drop
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html xmlns:th="http://www.thymeleaf.org">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8">
 | 
				
			||||||
 | 
					    <title>Title</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<nav th:fragment="header">
 | 
				
			||||||
 | 
					    <ul>
 | 
				
			||||||
 | 
					        <li>
 | 
				
			||||||
 | 
					            <a href="#" th:href="@{/}">Home</a>
 | 
				
			||||||
 | 
					        </li>
 | 
				
			||||||
 | 
					        <li>
 | 
				
			||||||
 | 
					            <a href="#" th:href="@{/courses}">Courses</a>
 | 
				
			||||||
 | 
					        </li>
 | 
				
			||||||
 | 
					        <li>
 | 
				
			||||||
 | 
					            <a href="#" th:href="@{/students}">Students</a>
 | 
				
			||||||
 | 
					        </li>
 | 
				
			||||||
 | 
					    </ul>
 | 
				
			||||||
 | 
					</nav>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html xmlns:th="http://www.thymeleaf.org">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8">
 | 
				
			||||||
 | 
					    <title>Title</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div th:replace="~{fragments/header :: header}"> </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div>
 | 
				
			||||||
 | 
					    <p>
 | 
				
			||||||
 | 
					        Welcome to the home page.
 | 
				
			||||||
 | 
					    </p>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
		Loading…
	
		Reference in New Issue