2 Commits

Author SHA1 Message Date
  Michelle DiMarino 50fb632548 it works 5 years ago
  Michelle DiMarino 060b956985 commit 1 5 years ago

BIN
.DS_Store View File


+ 14
- 2
pom.xml View File

14
 	<parent>
14
 	<parent>
15
 		<groupId>org.springframework.boot</groupId>
15
 		<groupId>org.springframework.boot</groupId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
17
+		<version>1.5.11.RELEASE</version>
18
 		<relativePath/> <!-- lookup parent from repository -->
18
 		<relativePath/> <!-- lookup parent from repository -->
19
 	</parent>
19
 	</parent>
20
 
20
 
25
 	</properties>
25
 	</properties>
26
 
26
 
27
 	<dependencies>
27
 	<dependencies>
28
+
28
 		<dependency>
29
 		<dependency>
29
 			<groupId>org.springframework.boot</groupId>
30
 			<groupId>org.springframework.boot</groupId>
30
 			<artifactId>spring-boot-starter</artifactId>
31
 			<artifactId>spring-boot-starter</artifactId>
50
 			<artifactId>spring-data-commons</artifactId>
51
 			<artifactId>spring-data-commons</artifactId>
51
 			<version>1.13.10.RELEASE</version>
52
 			<version>1.13.10.RELEASE</version>
52
 		</dependency>
53
 		</dependency>
53
-	</dependencies>
54
+        <dependency>
55
+            <groupId>org.springframework.boot</groupId>
56
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
57
+        </dependency>
58
+
59
+		<dependency>
60
+			<groupId>org.hsqldb</groupId>
61
+			<artifactId>hsqldb</artifactId>
62
+			<scope>runtime</scope>
63
+		</dependency>
64
+
65
+    </dependencies>
54
 
66
 
55
 	<build>
67
 	<build>
56
 		<plugins>
68
 		<plugins>

+ 5
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java View File

3
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 
5
 
6
+import javax.persistence.EntityManager;
7
+import javax.persistence.EntityManagerFactory;
8
+import javax.persistence.Persistence;
9
+
6
 @SpringBootApplication
10
 @SpringBootApplication
7
 public class BakeryApplication {
11
 public class BakeryApplication {
8
 
12
 
9
 	public static void main(String[] args) {
13
 	public static void main(String[] args) {
14
+
10
 		SpringApplication.run(BakeryApplication.class, args);
15
 		SpringApplication.run(BakeryApplication.class, args);
11
 	}
16
 	}
12
 }
17
 }

+ 15
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
7
 
9
 
10
+
11
+@RestController
8
 public class BakerController {
12
 public class BakerController {
9
 
13
 
14
+    @Autowired
10
     private BakerRepository bakerRepository;
15
     private BakerRepository bakerRepository;
11
 
16
 
17
+
18
+    @GetMapping("/baker")
12
     public ResponseEntity<Iterable<Baker>> index() {
19
     public ResponseEntity<Iterable<Baker>> index() {
13
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14
     }
21
     }
15
 
22
 
16
-    public ResponseEntity<Baker> show(Long id) {
23
+    @GetMapping("/baker/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
25
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18
     }
26
     }
19
 
27
 
20
-    public ResponseEntity<Baker> create(Baker baker) {
28
+    @PostMapping("/baker")
29
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
21
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22
     }
31
     }
23
 
32
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping("/baker/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
25
         Baker foundBaker = bakerRepository.findOne(id);
35
         Baker foundBaker = bakerRepository.findOne(id);
26
 
36
 
27
         foundBaker.setName(baker.getName());
37
         foundBaker.setName(baker.getName());
30
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31
     }
41
     }
32
 
42
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
43
+    @DeleteMapping("/baker/{id}")
44
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34
         this.bakerRepository.delete(id);
45
         this.bakerRepository.delete(id);
35
         return new ResponseEntity<>(true, HttpStatus.OK);
46
         return new ResponseEntity<>(true, HttpStatus.OK);
36
     }
47
     }

+ 18
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Muffin;
3
 import com.zipcodewilmington.bakery.Models.Muffin;
4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.*;
7
 
10
 
11
+import javax.persistence.EntityManager;
12
+import javax.persistence.EntityManagerFactory;
13
+import javax.persistence.Persistence;
14
+
15
+@RestController
8
 public class MuffinController {
16
 public class MuffinController {
9
 
17
 
18
+    @Autowired
10
     private MuffinRepository muffinRepository;
19
     private MuffinRepository muffinRepository;
11
 
20
 
21
+    @GetMapping("/muffin")
12
     public ResponseEntity<Iterable<Muffin>> index() {
22
     public ResponseEntity<Iterable<Muffin>> index() {
13
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
23
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14
     }
24
     }
15
 
25
 
16
-    public ResponseEntity<Muffin> show(Long id) {
26
+    @GetMapping("/muffin/{id}")
27
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
28
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18
     }
29
     }
19
 
30
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
31
+    @PostMapping("/muffin")
32
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
33
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22
     }
34
     }
23
 
35
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
36
+    @PutMapping("/muffin/{id}")
37
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25
         Muffin foundMuffin = muffinRepository.findOne(id);
38
         Muffin foundMuffin = muffinRepository.findOne(id);
26
         foundMuffin.setFlavor(muffin.getFlavor());
39
         foundMuffin.setFlavor(muffin.getFlavor());
27
 
40
 
28
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
41
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29
     }
42
     }
30
 
43
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
44
+    @DeleteMapping("/muffin/{id}")
45
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32
         this.muffinRepository.delete(id);
46
         this.muffinRepository.delete(id);
33
         return new ResponseEntity<>(true, HttpStatus.OK);
47
         return new ResponseEntity<>(true, HttpStatus.OK);
34
     }
48
     }

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java View File

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
3
 public class Baker {
7
 public class Baker {
8
+
9
+    @Id
10
+    @GeneratedValue(strategy = GenerationType.AUTO)
4
     private Long id;
11
     private Long id;
5
 
12
 
13
+    @Column
6
     private String name;
14
     private String name;
7
 
15
 
16
+    @Column
8
     private String employeeId;
17
     private String employeeId;
9
 
18
 
19
+    @Column
10
     private String specialty;
20
     private String specialty;
11
 
21
 
12
     public Baker(String name, String employeeId, String specialty) {
22
     public Baker(String name, String employeeId, String specialty) {

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java View File

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
3
 public class Muffin {
7
 public class Muffin {
4
 
8
 
9
+    @Id
10
+    @GeneratedValue(strategy = GenerationType.AUTO)
5
     private Long id;
11
     private Long id;
6
 
12
 
13
+    @Column
7
     private String flavor;
14
     private String flavor;
8
 
15
 
16
+
9
     public Muffin(String flavor) {
17
     public Muffin(String flavor) {
10
         this.flavor = flavor;
18
         this.flavor = flavor;
11
     }
19
     }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java View File

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import org.springframework.data.repository.CrudRepository;
4
 import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5
 
7
 
8
+@Repository
6
 public interface BakerRepository extends CrudRepository<Baker, Long> {
9
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7
 }
10
 }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java View File

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Muffin;
3
 import com.zipcodewilmington.bakery.Models.Muffin;
4
 import org.springframework.data.repository.CrudRepository;
4
 import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5
 
7
 
8
+@Repository
6
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
9
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7
 }
10
 }