Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Create the following REST endpoints to interact with the application. You can us
- `GET` `/people/{id}` -- get the person with the specified ID
- `DELETE` `/people/{id}` -- Delete the person with the specified ID
- `GET` `/people` -- get all people in the database
- `GET` `/people/reverselookup/{mobileNumber}` -- find all people with the specified mobile number
- `GET` `/people/surname/{lastName}` -- Find all people with a particular last name
- `GET` `/people/reverselookup/{MOBILE}` -- find all people with the specified mobile number
- `GET` `/people/surname/{LAST_NAME}` -- Find all people with a particular last name
- `GET` `/people/surname` -- Get the result of the surname report above
- `GET` `/people/firstname/stats` -- Get the report of first name frequencies

Expand Down
24 changes: 18 additions & 6 deletions data-h2.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES ('Howard the Duck', 110, 'Sci-Fi', 4.6, 'PG');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Lavalantula', 83, 'Horror', 4.7, 'TV-14');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Starship Troopers', 129, 'Sci-Fi', 7.2, 'PG-13');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Waltz With Bashir', 90, 'Documentary', 8.0, 'R');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Spaceballs', 96, 'Comedy', 7.1, 'PG');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Monsters Inc.', 92, 'Animation', 8.1, 'G');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('2001: A Space Odyssey', 149, 'Sci-Fi', 8.3, 'G');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Blade Runner 2049', 164, 'Sci-Fi', 8.2, 'R');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Mad Max: Fury Road', 120, 'Action', 8.1, 'R');
INSERT INTO movies (title, runtime, genre, imdb_score, rating) VALUES('Titanic', 194, 'Romance', 7.8, 'PG-13');

INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('36 E. Bayberry Rd.Savannah, GA 31404', '565-6895');
INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('11 Essex Dr.Farmingdale, NY 11735', '454-4544');
INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('920 Arlington Street Clifton, NJ 07011', '985-4515');
INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('234 High Street, PA 19159 ', '267-3940');

INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ('Carbral', 'Sheeri', '230-4233', '1970-02-23', 2);
INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ( 'Sharam', 'Raj', '186-5223', '1980-08-31', 3);
INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ('Durand', 'Noelle', '395-6161', '1960-07-06', 1);
INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
INSERT INTO PERSON (LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);



INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID ) VALUES ('Carbral', 'Sheeri', '230-4233', '1970-02-23', 2);
INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ( 'Sharam', 'Raj', '186-5223', '1980-08-31', 3);
INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Durand', 'Noelle', '395-6161', '1960-07-06', 1);
INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);


7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand All @@ -48,7 +51,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.zipcoder.persistenceapp.Controller;

import io.zipcoder.persistenceapp.domain.Person;
import io.zipcoder.persistenceapp.Service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class PersonController {

private PersonService personService;

@Autowired
public PersonController(PersonService personService){
this.personService = personService;
}

@RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
public ResponseEntity<Person> getPerson(@PathVariable Long id) {
return personService.findById(id);
}
@RequestMapping(value = "/people", method = RequestMethod.GET)
public ResponseEntity<Iterable<Person>> getAllPeople() {
return personService.getAllPeople();
}
@RequestMapping(value = "/people", method = RequestMethod.POST)
public ResponseEntity<?> createPerson(@RequestBody Person person) {
return personService.addPerson(person);
}
@RequestMapping(value = "/people/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> updatePerson(@RequestBody Person person, @PathVariable Long id) {
return personService.updatePerson(person);
}
@RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> deletePerson(@PathVariable Long id) {
return personService.removePerson(id);
}

// @RequestMapping(value = "/people/reverselookup/{mobile}", method = RequestMethod.GET)
// public ResponseEntity<Iterable<Person>> reverseLookup(@PathVariable String mobile) {
// return personService.reverseLookup(mobile);
// }
//
// @RequestMapping(value = "/people/surname/{lastName}", method = RequestMethod.GET)
// public ResponseEntity<Iterable<Person>> surnameLookup(@PathVariable String lastName) {
// return personService.findByLastName(lastName);
// }

// @RequestMapping(value = "/people/firstname/stats", method = RequestMethod.GET)
// public ResponseEntity<Map<String, Integer>> firstNameWithStats() {
// return personService.getFirstNameStats();
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//package io.zipcoder.persistenceapp.Service;
//
//import io.zipcoder.persistenceapp.domain.Person;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//
/**
* defunct class from part 2
*/
//
////where the methods go
//@Service
//public class PersonService {
//
//// private SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
// /**
// * SQL methods needed:
// * Add - should work
// * Update - should work
// * Remove - works
// * Remove a list of people - in progress
// * Find single person by ID - works
// * Generate a map of lastnames to list people with that lastname - in progress
// * Generate a map of firstnames to the number of occurrences. - in progress
// */
//
// private static final String getAllPersons = "SELECT * FROM PERSON";
// private static final String getSingleId = "SELECT * FROM PERSON WHERE ID = ?";
// private static final String deletePerson = "DELETE * FROM PERSON WHERE ID = ?";
// private static final String findByLastName = "SELECT * FROM PERSON WHERE LAST_NAME = ?";
//// private static final String getMapLastName = "";
//// private static final String getMapFirstName = "";
//
// @Autowired
// private JdbcTemplate jdbcTemplate;
//
// public void getSinglePersonById(Long id){
// this.jdbcTemplate.execute(getSingleId);
// }
//
// public void getAllPersons(){
// this.jdbcTemplate.queryForList(getAllPersons);
// }
//
// public void deletePersonById(Long id){
// this.jdbcTemplate.execute(deletePerson);
// }
// public void findPersonByLastName(String last_name){
// this.jdbcTemplate.execute(findByLastName);
// }
// public void addPerson(Person person) {
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// String sql = "INSERT INTO person ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID ) VALUES ('" + person.getLAST_NAME() +
// "','" + person.getFIRST_NAME() + "','" + person.getMOBILE() + "','" + format.format(person.getBIRTHDAY()) + "','" + person.getHOME_ID() + "')";
// jdbcTemplate.execute(sql);
// }
// public void updatePerson(Person person, Long id) {
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// String sql = "UPDATE person SET FIRST_NAME = '" + person.getFIRST_NAME() +"', LAST_NAME = '" + person.getLAST_NAME() +
// "', MOBILE = '" + person.getMOBILE() + "', BIRTHDAY = '" + format.format(person.getBIRTHDAY()) + "', HOME_ID = '" +
// person.getHOME_ID() + "' WHERE ID = " + id;
// jdbcTemplate.execute(sql);
// }
//
//
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.zipcoder.persistenceapp.Service;

import io.zipcoder.persistenceapp.domain.Person;
import io.zipcoder.persistenceapp.domain.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Primary
@Service
public class JPAPersonServiceImpl implements PersonService{

private PersonRepository personRepository;
/**
* To-Do: findAll LastNames, FirstNames, Birthdays,Mobile.
* Done with: basic methods.
* @param personRepository
*/
@Autowired
public JPAPersonServiceImpl(PersonRepository personRepository){
this.personRepository = personRepository;
}
@Override
public ResponseEntity<Person> findById(Long id) {
return new ResponseEntity<>(personRepository.findOne(id), HttpStatus.OK);
}
@Override
public ResponseEntity<Iterable<Person>> getAllPeople() {
return new ResponseEntity<>(personRepository.findAll(), HttpStatus.OK);
}
@Override
public ResponseEntity<?> addPerson(Person person) {
return new ResponseEntity<>(personRepository.save(person), HttpStatus.OK);
}
@Override
public ResponseEntity<?> updatePerson(Person person) {
return new ResponseEntity<>(personRepository.save(person), HttpStatus.OK);
}
@Override
public ResponseEntity<?> removePerson(Long id) {
personRepository.delete(id);
return new ResponseEntity<>(HttpStatus.OK);
}
@Override
public ResponseEntity<Iterable<Person>> findByLastName(String lastname) {
return null;
}
@Override
public ResponseEntity<Iterable<Person>> reverseLookup(String mobile) {
return null;
}
@Override
public ResponseEntity<Iterable<Person>> findByBirthday(String birthday) {
return null;
}
// @Override
// public ResponseEntity<Map<String, List<Person>>> getSurname(String surname) {
// return null;
// }
// @Override
// public ResponseEntity<Map<String, Integer>> getFirstNameWithStats() {
// return null;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.zipcoder.persistenceapp.Service;

import io.zipcoder.persistenceapp.domain.Person;
import org.springframework.http.ResponseEntity;

public interface PersonService {

ResponseEntity<Person> findById(Long id);

ResponseEntity<Iterable<Person>> getAllPeople();

ResponseEntity<?> addPerson(Person person);

ResponseEntity<?> updatePerson(Person person);

ResponseEntity<?> removePerson(Long personId);

ResponseEntity<Iterable<Person>> findByLastName(String lastname);

ResponseEntity<Iterable<Person>> reverseLookup(String mobile);

ResponseEntity<Iterable<Person>> findByBirthday(String birthday);

// ResponseEntity<Map<String, List<Person>>> getSurname(String surname);
//
// ResponseEntity<Map<String, Integer>> getFirstNameWithStats();
}
89 changes: 89 additions & 0 deletions src/main/java/io/zipcoder/persistenceapp/domain/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.zipcoder.persistenceapp.domain;

import javax.persistence.*;

@Entity
public class Person {

@Id
@GeneratedValue
@Column(name = "PERSON_ID")
private Long Id;

@Column(name = "LAST_NAME")
private String LAST_NAME;

@Column(name = "FIRST_NAME")
private String FIRST_NAME;

@Column(name = "MOBILE")
private String MOBILE;

@Column(name = "BIRTHDAY")
private Long BIRTHDAY;

@Column(name = "HOME_ID")
private Integer HOME_ID;

public Person(){

}
public Person(Long Id, String FIRST_NAME, String LAST_NAME, String MOBILE){
this.Id = Id;
this.FIRST_NAME = FIRST_NAME;
this.LAST_NAME = LAST_NAME;
this.MOBILE = MOBILE;

}
public String getFIRST_NAME() {
return FIRST_NAME;
}

public void setFIRST_NAME(String FIRST_NAME) {
this.FIRST_NAME = FIRST_NAME;
}

public String getLAST_NAME() {
return LAST_NAME;
}

public void setLAST_NAME(String LAST_NAME) {
this.LAST_NAME = LAST_NAME;
}

public String getMOBILE() {
return MOBILE;
}

public void setMOBILE(String MOBILE) {
this.MOBILE = MOBILE;
}

public Long getBIRTHDAY() {
return BIRTHDAY;
}

public void setBIRTHDAY(Long BIRTHDAY) {
this.BIRTHDAY = BIRTHDAY;
}

public int getHOME_ID() {
return HOME_ID;
}

public void setHOME_ID(Integer HOME_ID) {
this.HOME_ID = HOME_ID;
}

public Long getId() {
return Id;
}

public void setId(Long id) {
this.Id = id;
}

// public String toString(){
// return String.format("[%s, %s, %s, %s, %d]", FIRST_NAME, LAST_NAME, MOBILE, BIRTHDAY, HOME_ID);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.zipcoder.persistenceapp.domain;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PersonRepository extends JpaRepository<Person, Long> {

}
Loading