Kate Moore 5 years ago
parent
commit
ca5573cbf3

+ 46
- 46
pom.xml View File

@@ -1,65 +1,65 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
-	<modelVersion>4.0.0</modelVersion>
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5 5
 
6
-	<groupId>io.zipcoder</groupId>
7
-	<artifactId>crud-app-starter</artifactId>
8
-	<version>0.0.1-SNAPSHOT</version>
9
-	<packaging>jar</packaging>
6
+    <groupId>io.zipcoder</groupId>
7
+    <artifactId>crud-app-starter</artifactId>
8
+    <version>0.0.1-SNAPSHOT</version>
9
+    <packaging>jar</packaging>
10 10
 
11
-	<name>crud-app-starter</name>
12
-	<description>Starter project for Spring Boot-based CRUD applications</description>
11
+    <name>crud-app-starter</name>
12
+    <description>Starter project for Spring Boot-based CRUD applications</description>
13 13
 
14
-	<parent>
15
-		<groupId>org.springframework.boot</groupId>
16
-		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>1.5.2.RELEASE</version>
18
-		<relativePath/> <!-- lookup parent from repository -->
19
-	</parent>
14
+    <parent>
15
+        <groupId>org.springframework.boot</groupId>
16
+        <artifactId>spring-boot-starter-parent</artifactId>
17
+        <version>1.5.2.RELEASE</version>
18
+        <relativePath/> <!-- lookup parent from repository -->
19
+    </parent>
20 20
 
21
-	<properties>
22
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
-		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
-		<java.version>1.8</java.version>
25
-	</properties>
21
+    <properties>
22
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+        <java.version>1.8</java.version>
25
+    </properties>
26 26
 
27
-	<dependencies>
28
-		<dependency>
29
-			<groupId>org.springframework.boot</groupId>
30
-			<artifactId>spring-boot-starter</artifactId>
31
-		</dependency>
27
+    <dependencies>
28
+        <dependency>
29
+            <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter</artifactId>
31
+        </dependency>
32 32
 
33
-		<dependency>
34
-			<groupId>com.h2database</groupId>
35
-			<artifactId>h2</artifactId>
33
+        <dependency>
34
+            <groupId>com.h2database</groupId>
35
+            <artifactId>h2</artifactId>
36 36
             <scope>compile</scope>
37
-		</dependency>
38
-		<dependency>
39
-			<groupId>org.springframework.boot</groupId>
40
-			<artifactId>spring-boot-starter-test</artifactId>
41
-			<scope>test</scope>
42
-		</dependency>
37
+        </dependency>
38
+        <dependency>
39
+            <groupId>org.springframework.boot</groupId>
40
+            <artifactId>spring-boot-starter-test</artifactId>
41
+            <scope>test</scope>
42
+        </dependency>
43 43
         <dependency>
44 44
             <groupId>org.springframework.boot</groupId>
45 45
             <artifactId>spring-boot-starter-web</artifactId>
46 46
             <!--<version>RELEASE</version>-->
47 47
         </dependency>
48
-		<dependency>
49
-			<groupId>org.springframework.boot</groupId>
50
-			<artifactId>spring-boot-starter-data-jpa</artifactId>
51
-			<!--<version>1.3.5.RELEASE</version>-->
52
-		</dependency>
48
+        <dependency>
49
+            <groupId>org.springframework.boot</groupId>
50
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
51
+            <!--<version>1.3.5.RELEASE</version>-->
52
+        </dependency>
53 53
     </dependencies>
54 54
 
55
-	<build>
56
-		<plugins>
57
-			<plugin>
58
-				<groupId>org.springframework.boot</groupId>
59
-				<artifactId>spring-boot-maven-plugin</artifactId>
60
-			</plugin>
61
-		</plugins>
62
-	</build>
55
+    <build>
56
+        <plugins>
57
+            <plugin>
58
+                <groupId>org.springframework.boot</groupId>
59
+                <artifactId>spring-boot-maven-plugin</artifactId>
60
+            </plugin>
61
+        </plugins>
62
+    </build>
63 63
 
64 64
 
65 65
 </project>

+ 52
- 0
src/main/java/io/zipcoder/crudapp/Person.java View File

@@ -0,0 +1,52 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Person {
7
+
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "ID")
11
+    private Long id;
12
+
13
+    @Column(name = "FIRST_NAME")
14
+    private String firstName;
15
+
16
+    @Column(name = "LAST_NAME")
17
+    private String lastName;
18
+
19
+    public Person() {
20
+    }
21
+
22
+    public Person(String firstName, String lastName, Long id) {
23
+        this.firstName = firstName;
24
+        this.lastName = lastName;
25
+        this.id = id;
26
+    }
27
+
28
+    public Person(String firstName, String lastName) {
29
+        this.firstName = firstName;
30
+        this.lastName = lastName;
31
+    }
32
+
33
+    public String getFirstName() {
34
+        return firstName;
35
+    }
36
+
37
+    public String getLastName() {
38
+        return lastName;
39
+    }
40
+
41
+    public Long getId() {
42
+        return id;
43
+    }
44
+
45
+    public void setFirstName(String firstName) {
46
+        this.firstName = firstName;
47
+    }
48
+
49
+    public void setLastName(String lastName) {
50
+        this.lastName = lastName;
51
+    }
52
+}

+ 47
- 0
src/main/java/io/zipcoder/crudapp/PersonController.java View File

@@ -0,0 +1,47 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.http.HttpStatus;
5
+import org.springframework.http.ResponseEntity;
6
+import org.springframework.web.bind.annotation.*;
7
+
8
+@RestController
9
+public class PersonController {
10
+
11
+    private PersonRepository personRepository;
12
+
13
+    @Autowired
14
+    public PersonController(PersonRepository repository) {
15
+        this.personRepository = repository;
16
+    }
17
+
18
+    @PostMapping("/people")
19
+    public ResponseEntity<Person> createPerson(@RequestBody Person p) {
20
+        personRepository.save(p);
21
+        return new ResponseEntity<>(HttpStatus.CREATED);
22
+    }
23
+
24
+    @GetMapping("/people/{id}")
25
+    public ResponseEntity<Person> getPerson(@PathVariable Long id) {
26
+        personRepository.findOne(id);
27
+        return new ResponseEntity<>(HttpStatus.OK);
28
+    }
29
+
30
+    @GetMapping("/people")
31
+    public ResponseEntity<Iterable<Person>> getPersonList(){
32
+        personRepository.findAll();
33
+        return new ResponseEntity<>(HttpStatus.OK);
34
+    }
35
+
36
+    @PutMapping("/people/{id}")
37
+    public ResponseEntity<?> updatePerson(@RequestBody Person person, @PathVariable Long id) {
38
+       personRepository.save(person);
39
+        return new ResponseEntity<>(HttpStatus.OK);
40
+    }
41
+
42
+    @DeleteMapping ("/people/{id}")
43
+    public ResponseEntity<?> deletePerson(@PathVariable Long id) {
44
+        personRepository.delete(id);
45
+        return new ResponseEntity<>(HttpStatus.ACCEPTED);
46
+    }
47
+}

+ 11
- 0
src/main/java/io/zipcoder/crudapp/PersonRepository.java View File

@@ -0,0 +1,11 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import org.springframework.data.repository.CrudRepository;
4
+import org.springframework.stereotype.Repository;
5
+
6
+@Repository
7
+public interface PersonRepository extends CrudRepository<Person, Long> {
8
+
9
+
10
+
11
+}

+ 1
- 0
src/test/java/io/zipcoder/crudapp/CRUDApplicationTests.java View File

@@ -11,6 +11,7 @@ public class CRUDApplicationTests {
11 11
 
12 12
 	@Test
13 13
 	public void contextLoads() {
14
+
14 15
 	}
15 16
 
16 17
 }

+ 14
- 0
src/test/java/io/zipcoder/crudapp/PersonControllerTest.java View File

@@ -0,0 +1,14 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import org.junit.runner.RunWith;
4
+import org.springframework.test.context.ContextConfiguration;
5
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
6
+import org.springframework.test.context.web.WebAppConfiguration;
7
+
8
+@WebAppConfiguration
9
+@RunWith(SpringJUnit4ClassRunner.class)
10
+@ContextConfiguration
11
+public class PersonControllerTest {
12
+
13
+
14
+}