Browse Source

Completed

Brandon Defrancis 5 years ago
parent
commit
0ba8182d3e

BIN
.DS_Store View File


+ 12
- 2
pom.xml View File

11
 	<name>bakery</name>
11
 	<name>bakery</name>
12
 	<description>Demo project for Spring Boot</description>
12
 	<description>Demo project for Spring Boot</description>
13
 
13
 
14
+
14
 	<parent>
15
 	<parent>
15
 		<groupId>org.springframework.boot</groupId>
16
 		<groupId>org.springframework.boot</groupId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
18
+		<version>1.5.11.RELEASE</version>
18
 		<relativePath/> <!-- lookup parent from repository -->
19
 		<relativePath/> <!-- lookup parent from repository -->
19
 	</parent>
20
 	</parent>
20
 
21
 
29
 			<groupId>org.springframework.boot</groupId>
30
 			<groupId>org.springframework.boot</groupId>
30
 			<artifactId>spring-boot-starter</artifactId>
31
 			<artifactId>spring-boot-starter</artifactId>
31
 		</dependency>
32
 		</dependency>
33
+		<dependency>
34
+			<groupId>org.hsqldb</groupId>
35
+			<artifactId>hsqldb</artifactId>
36
+			<scope>runtime</scope>
37
+		</dependency>
32
 
38
 
33
 		<dependency>
39
 		<dependency>
34
 			<groupId>org.springframework.boot</groupId>
40
 			<groupId>org.springframework.boot</groupId>
50
 			<artifactId>spring-data-commons</artifactId>
56
 			<artifactId>spring-data-commons</artifactId>
51
 			<version>1.13.10.RELEASE</version>
57
 			<version>1.13.10.RELEASE</version>
52
 		</dependency>
58
 		</dependency>
53
-	</dependencies>
59
+        <dependency>
60
+            <groupId>org.springframework.boot</groupId>
61
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
62
+        </dependency>
63
+    </dependencies>
54
 
64
 
55
 	<build>
65
 	<build>
56
 		<plugins>
66
 		<plugins>

BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File


BIN
src/main/java/com/.DS_Store View File


BIN
src/main/java/com/zipcodewilmington/.DS_Store View File


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

5
 
5
 
6
 @SpringBootApplication
6
 @SpringBootApplication
7
 public class BakeryApplication {
7
 public class BakeryApplication {
8
-
9
 	public static void main(String[] args) {
8
 	public static void main(String[] args) {
10
 		SpringApplication.run(BakeryApplication.class, args);
9
 		SpringApplication.run(BakeryApplication.class, args);
11
 	}
10
 	}

+ 20
- 6
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.PathVariable;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
7
 
12
 
13
+@RestController
8
 public class BakerController {
14
 public class BakerController {
9
 
15
 
10
-    private BakerRepository bakerRepository;
16
+    private final BakerRepository bakerRepository;
11
 
17
 
18
+    @Autowired
19
+    public BakerController(BakerRepository bakerRepository) {
20
+        this.bakerRepository = bakerRepository;
21
+    }
22
+
23
+    @RequestMapping(value="/bakers", method= RequestMethod.GET)
12
     public ResponseEntity<Iterable<Baker>> index() {
24
     public ResponseEntity<Iterable<Baker>> index() {
13
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
25
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14
     }
26
     }
15
 
27
 
16
-    public ResponseEntity<Baker> show(Long id) {
28
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.GET)
29
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
30
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18
     }
31
     }
19
 
32
 
33
+    @RequestMapping(value="/bakers", method= RequestMethod.POST)
20
     public ResponseEntity<Baker> create(Baker baker) {
34
     public ResponseEntity<Baker> create(Baker baker) {
21
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
35
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22
     }
36
     }
23
 
37
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
38
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.PUT)
39
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
25
         Baker foundBaker = bakerRepository.findOne(id);
40
         Baker foundBaker = bakerRepository.findOne(id);
26
-
27
         foundBaker.setName(baker.getName());
41
         foundBaker.setName(baker.getName());
28
         foundBaker.setSpecialty(baker.getSpecialty());
42
         foundBaker.setSpecialty(baker.getSpecialty());
29
-
30
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
43
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31
     }
44
     }
32
 
45
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
46
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.DELETE)
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34
         this.bakerRepository.delete(id);
48
         this.bakerRepository.delete(id);
35
         return new ResponseEntity<>(true, HttpStatus.OK);
49
         return new ResponseEntity<>(true, HttpStatus.OK);
36
     }
50
     }

+ 20
- 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.web.bind.annotation.PathVariable;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
7
 
12
 
13
+@RestController
8
 public class MuffinController {
14
 public class MuffinController {
9
 
15
 
10
-    private MuffinRepository muffinRepository;
16
+    private final MuffinRepository muffinRepository;
11
 
17
 
18
+    @Autowired
19
+    public MuffinController(MuffinRepository muffinRepository) {
20
+        this.muffinRepository = muffinRepository;
21
+    }
22
+
23
+    @RequestMapping(value="/muffins", method= RequestMethod.GET)
12
     public ResponseEntity<Iterable<Muffin>> index() {
24
     public ResponseEntity<Iterable<Muffin>> index() {
13
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
25
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14
     }
26
     }
15
 
27
 
16
-    public ResponseEntity<Muffin> show(Long id) {
28
+    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.GET)
29
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
30
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18
     }
31
     }
19
 
32
 
33
+    @RequestMapping(value="/muffins", method= RequestMethod.POST)
20
     public ResponseEntity<Muffin> create(Muffin muffin) {
34
     public ResponseEntity<Muffin> create(Muffin muffin) {
21
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
35
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22
     }
36
     }
23
 
37
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
38
+    @RequestMapping(value="/muffin/{MUFFIN_ID}", method=RequestMethod.PUT)
39
+    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
25
         Muffin foundMuffin = muffinRepository.findOne(id);
40
         Muffin foundMuffin = muffinRepository.findOne(id);
26
         foundMuffin.setFlavor(muffin.getFlavor());
41
         foundMuffin.setFlavor(muffin.getFlavor());
27
 
42
 
28
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
43
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29
     }
44
     }
30
 
45
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
46
+    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.DELETE)
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32
         this.muffinRepository.delete(id);
48
         this.muffinRepository.delete(id);
33
         return new ResponseEntity<>(true, HttpStatus.OK);
49
         return new ResponseEntity<>(true, HttpStatus.OK);
34
     }
50
     }

+ 13
- 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
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Baker {
9
 public class Baker {
10
+
11
+    @Id
12
+    @GeneratedValue
13
+    @Column(name = "BAKER_ID")
4
     private Long id;
14
     private Long id;
5
 
15
 
16
+    @Column(name = "NAME")
6
     private String name;
17
     private String name;
7
 
18
 
19
+    @Column(name = "EMPLOYEEID")
8
     private String employeeId;
20
     private String employeeId;
9
 
21
 
22
+    @Column(name = "SPECIALTY")
10
     private String specialty;
23
     private String specialty;
11
 
24
 
12
     public Baker(String name, String employeeId, String specialty) {
25
     public Baker(String name, String employeeId, String specialty) {

+ 10
- 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
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Muffin {
9
 public class Muffin {
4
 
10
 
11
+    @Id
12
+    @GeneratedValue
13
+    @Column(name = "MUFFIN_ID")
5
     private Long id;
14
     private Long id;
6
 
15
 
16
+    @Column(name = "FLAVOR")
7
     private String flavor;
17
     private String flavor;
8
 
18
 
9
     public Muffin(String flavor) {
19
     public Muffin(String flavor) {

+ 2
- 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.stereotype.Repository;
5
 
6
 
7
+@Repository
6
 public interface BakerRepository extends CrudRepository<Baker, Long> {
8
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7
 }
9
 }

+ 2
- 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.stereotype.Repository;
5
 
6
 
7
+@Repository
6
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
8
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7
 }
9
 }