#28 Finished

Open
Skamath321 wants to merge 1 commits from Skamath321/CR-MicroLabs-Annotations-Bakery:master into master

BIN
.DS_Store View File


+ 8
- 1
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>2.1.1.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
+
29
+        <dependency>
30
+            <groupId>org.hsqldb</groupId>
31
+            <artifactId>hsqldb</artifactId>
32
+            <scope>runtime</scope>
33
+        </dependency>
34
+
28
         <dependency>
35
         <dependency>
29
             <groupId>org.springframework.boot</groupId>
36
             <groupId>org.springframework.boot</groupId>
30
             <artifactId>spring-boot-starter</artifactId>
37
             <artifactId>spring-boot-starter</artifactId>

+ 16
- 5
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;
7
 
8
 
9
+import org.springframework.web.bind.annotation.*;
10
+
11
+import java.nio.file.Path;
12
+
13
+@RestController
8
 public class BakerController {
14
 public class BakerController {
15
+
16
+    @Autowired
9
     private BakerRepository bakerRepository;
17
     private BakerRepository bakerRepository;
10
 
18
 
19
+    @GetMapping(path = "/bakers")
11
     public ResponseEntity<Iterable<Baker>> index() {
20
     public ResponseEntity<Iterable<Baker>> index() {
12
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
21
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13
     }
22
     }
14
 
23
 
15
-    public ResponseEntity<Baker> show(Long id) {
24
+    @GetMapping(path = "/bakers/{id}")
25
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
16
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
26
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
17
     }
27
     }
18
-
28
+    @PostMapping(path = "/bakers")
19
     public ResponseEntity<Baker> create(Baker baker) {
29
     public ResponseEntity<Baker> create(Baker baker) {
20
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21
     }
31
     }
22
 
32
 
23
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping(path = "/bakers/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
24
         Baker foundBaker = bakerRepository.findById(id).get();
35
         Baker foundBaker = bakerRepository.findById(id).get();
25
 
36
 
26
         foundBaker.setName(baker.getName());
37
         foundBaker.setName(baker.getName());
28
 
39
 
29
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
30
     }
41
     }
31
-
32
-    public ResponseEntity<Boolean> destroy(Long id) {
42
+    @DeleteMapping(path = "bakers/{id}")
43
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
33
         this.bakerRepository.findById(id).get();
44
         this.bakerRepository.findById(id).get();
34
         return new ResponseEntity<>(true, HttpStatus.OK);
45
         return new ResponseEntity<>(true, HttpStatus.OK);
35
     }
46
     }

+ 14
- 9
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.http.HttpStatus;
6
-import org.springframework.http.ResponseEntity;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.*;
7
+import org.springframework.stereotype.Controller;
8
+import org.springframework.web.bind.annotation.*;
7
 
9
 
10
+@Controller
8
 public class MuffinController {
11
 public class MuffinController {
9
 
12
 
13
+    @Autowired
10
     private MuffinRepository muffinRepository;
14
     private MuffinRepository muffinRepository;
11
 
15
 
16
+    @GetMapping(path = "/muffins")
12
     public ResponseEntity<Iterable<Muffin>> index() {
17
     public ResponseEntity<Iterable<Muffin>> index() {
13
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14
     }
19
     }
15
-
16
-    public ResponseEntity<Muffin> show(Long id) {
20
+    @GetMapping(path = "/muffins/{id}")
21
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
22
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
18
     }
23
     }
19
-
24
+    @PostMapping(path = "/muffins")
20
     public ResponseEntity<Muffin> create(Muffin muffin) {
25
     public ResponseEntity<Muffin> create(Muffin muffin) {
21
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
26
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22
     }
27
     }
23
-
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
28
+    @PutMapping(path = "/muffins/{id}")
29
+    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
25
         Muffin foundMuffin = muffinRepository.findById(id).get();
30
         Muffin foundMuffin = muffinRepository.findById(id).get();
26
         foundMuffin.setFlavor(muffin.getFlavor());
31
         foundMuffin.setFlavor(muffin.getFlavor());
27
 
32
 
28
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
33
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29
     }
34
     }
30
-
31
-    public ResponseEntity<Boolean> destroy(Long id) {
35
+    @DeleteMapping(path = "/muffins/{id}")
36
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32
         this.muffinRepository.deleteById(id);
37
         this.muffinRepository.deleteById(id);
33
         return new ResponseEntity<>(true, HttpStatus.OK);
38
         return new ResponseEntity<>(true, HttpStatus.OK);
34
     }
39
     }

+ 9
- 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.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.GenerationType;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Baker {
9
 public class Baker {
10
+
11
+    @Id
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
4
     private Long id;
13
     private Long id;
5
 
14
 
6
     private String name;
15
     private String name;

+ 9
- 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
+
5
+import javax.persistence.*;
6
+
7
+
8
+@Entity
3
 public class Muffin {
9
 public class Muffin {
10
+
11
+    @Id
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
4
     private Long id;
13
     private Long id;
5
 
14
 
6
     private String flavor;
15
     private String flavor;

+ 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;
5
 import org.springframework.stereotype.Repository;
6
 import org.springframework.stereotype.Repository;
6
 
7
 
8
+@Repository
9
+@RepositoryRestResource(collectionResourceRel = "bakers", path = "bakers")
7
 public interface BakerRepository extends CrudRepository<Baker, Long> {
10
 public interface BakerRepository extends CrudRepository<Baker, Long> {
8
 }
11
 }

+ 4
- 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;
5
 import org.springframework.stereotype.Repository;
6
 import org.springframework.stereotype.Repository;
6
 
7
 
8
+
9
+@Repository
10
+@RepositoryRestResource(collectionResourceRel = "muffins", path = "muffins")
7
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
11
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
8
 }
12
 }