From 9288c58eec20b082dc7caee331fc81f6e34bb850 Mon Sep 17 00:00:00 2001
From: Carnell <92267723+c-poteat@users.noreply.github.com>
Date: Sun, 19 Dec 2021 17:29:00 -0500
Subject: [PATCH] Updated lab
---
pom.xml | 1 -
src/main/java/io/zipcoder/crudapp/Person.java | 49 ++++++++++++++++++
.../io/zipcoder/crudapp/PersonController.java | 50 +++++++++++++++++++
.../io/zipcoder/crudapp/PersonRepository.java | 10 ++++
src/main/resources/application-h2.properties | 4 --
src/main/resources/application.properties | 7 +--
6 files changed, 113 insertions(+), 8 deletions(-)
create mode 100644 src/main/java/io/zipcoder/crudapp/Person.java
create mode 100644 src/main/java/io/zipcoder/crudapp/PersonController.java
create mode 100644 src/main/java/io/zipcoder/crudapp/PersonRepository.java
diff --git a/pom.xml b/pom.xml
index 558c7a1..8b42a12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,6 @@
com.h2database
h2
- compile
org.springframework.boot
diff --git a/src/main/java/io/zipcoder/crudapp/Person.java b/src/main/java/io/zipcoder/crudapp/Person.java
new file mode 100644
index 0000000..5f7e62d
--- /dev/null
+++ b/src/main/java/io/zipcoder/crudapp/Person.java
@@ -0,0 +1,49 @@
+package io.zipcoder.crudapp;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+ @Entity
+ public class Person {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Integer id;
+ private String firstName;
+ private String lastName;
+
+ public Person() {
+ }
+
+ public Person(Integer id, String firstName, String lastName) {
+ this.id = id;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ }
diff --git a/src/main/java/io/zipcoder/crudapp/PersonController.java b/src/main/java/io/zipcoder/crudapp/PersonController.java
new file mode 100644
index 0000000..e5fbcbd
--- /dev/null
+++ b/src/main/java/io/zipcoder/crudapp/PersonController.java
@@ -0,0 +1,50 @@
+package io.zipcoder.crudapp;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController// Annotation
+@RequestMapping(value = "/person-controller")
+
+public class PersonController {
+ @Autowired
+ private PersonRepository personRepository;
+
+ public PersonController(PersonRepository personRepository) {
+ this.personRepository = personRepository;
+ }
+
+ @RequestMapping(value = "/people", method = RequestMethod.POST)
+ public Person createPerson(@RequestBody Person p) {
+ return personRepository.save(p);
+ }
+
+ @RequestMapping(value = "/people/", method = RequestMethod.GET)
+ public List getPersonList() {
+ List newList = new ArrayList<>();
+ for (Person p : personRepository.findAll()) {
+ newList.add(p);
+ }
+ return newList;
+ }
+
+ @RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
+ public Person getPerson(@PathVariable Integer id) {
+ return personRepository.findOne(id);
+ }
+
+
+ @RequestMapping(value = "/people/{id}", method = RequestMethod.PUT)
+ public Person updatePerson(@PathVariable Integer id, @RequestBody Person p) {
+ p = personRepository.findOne(id);
+ return personRepository.save(p);
+ }
+
+ @RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)
+ public void deletePerson(@PathVariable Integer id) {
+ personRepository.delete(id);
+ }
+}
diff --git a/src/main/java/io/zipcoder/crudapp/PersonRepository.java b/src/main/java/io/zipcoder/crudapp/PersonRepository.java
new file mode 100644
index 0000000..2385d10
--- /dev/null
+++ b/src/main/java/io/zipcoder/crudapp/PersonRepository.java
@@ -0,0 +1,10 @@
+package io.zipcoder.crudapp;
+
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.stereotype.Service;
+
+@Service
+@Repository // optional
+public interface PersonRepository extends CrudRepository {
+}
diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties
index 74765cc..e69de29 100644
--- a/src/main/resources/application-h2.properties
+++ b/src/main/resources/application-h2.properties
@@ -1,4 +0,0 @@
-spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle
-spring.datasource.platform=h2
-spring.jpa.hibernate.ddl-auto=none
-spring.datasource.continue-on-error=true
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index dde67ef..efe9af2 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,3 +1,4 @@
-spring.profiles.active=h2
-
-spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
\ No newline at end of file
+server.port=8081
+spring.h2.console.enabled=true
+spring.h2.console.view=/h2-console
+spring.datasource.url=jdbc:h2:mem:testdb
\ No newline at end of file