Commit a51c8c01 authored by Darrick Yong's avatar Darrick Yong

set up connection with local db

parent f7ac1395
package com.student.details.controllers; package com.student.details.controllers;
import com.student.details.models.Student;
import com.student.details.services.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
public class DetailsController { public class DetailsController {
@Autowired
StudentService studentService;
@GetMapping("/students") @GetMapping("/students")
public void index() { public List<Student> getAllStudents() {
System.out.println("This is the students index route."); // System.out.println("This is the students index route.");
return studentService.findAllStudents();
} }
} }
...@@ -4,7 +4,7 @@ import javax.persistence.*; ...@@ -4,7 +4,7 @@ import javax.persistence.*;
import java.time.LocalDate; import java.time.LocalDate;
@Entity @Entity
@Table(name = "student") @Table(name = "student_details")
public class Student { public class Student {
@Id @Id
......
...@@ -6,5 +6,6 @@ import org.springframework.stereotype.Repository; ...@@ -6,5 +6,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface StudentRepository extends JpaRepository<Student, Long> { public interface StudentRepository extends JpaRepository<Student, Long> {
} }
...@@ -2,9 +2,9 @@ CREATE TABLE student_details ...@@ -2,9 +2,9 @@ CREATE TABLE student_details
( (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
email VARCHAR(100) UNIQUE NOT NULL, email VARCHAR(100) UNIQUE NOT NULL,
firstName VARCHAR(100) NOT NULL, first_name VARCHAR(100) NOT NULL,
lastName VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL,
dateOfBirth DATE NOT NULL, date_of_birth DATE NOT NULL,
course VARCHAR(100) NOT NULL course VARCHAR(100) NOT NULL
); );
INSERT INTO student_details (email, firstName, lastName, dateOfBirth, course) INSERT INTO student_details (email, first_name, last_name, date_of_birth, course)
VALUES ('dyong@nisum.com', 'Darrick', 'Yong', DATE('1990-09-08'), 'Math'), VALUES ('dyong@nisum.com', 'Darrick', 'Yong', DATE('1990-09-08'), 'Math'),
('apinto@nisum.com', 'Alex', 'Pinto', DATE('1997-07-04'), 'English'), ('apinto@nisum.com', 'Alex', 'Pinto', DATE('1997-07-04'), 'English'),
('banderson@nisum.com', 'Ben', 'Anderson', DATE('1993-09-20'), 'Chemistry'), ('banderson@nisum.com', 'Ben', 'Anderson', DATE('1993-09-20'), 'Chemistry'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment