Parcourir la source

{jaejoson Bakery lab}

Jacqueline Joson il y a 5 ans
Parent
révision
e9c13a0a08

BIN
.DS_Store Voir le fichier


+ 8
- 1
pom.xml Voir le fichier

@@ -14,7 +14,7 @@
14 14
     <parent>
15 15
         <groupId>org.springframework.boot</groupId>
16 16
         <artifactId>spring-boot-starter-parent</artifactId>
17
-        <version>2.0.4.RELEASE</version>
17
+        <version>1.5.11.RELEASE</version>
18 18
         <relativePath/> <!-- lookup parent from repository -->
19 19
     </parent>
20 20
 
@@ -25,6 +25,13 @@
25 25
     </properties>
26 26
 
27 27
     <dependencies>
28
+
29
+        <dependency>
30
+            <groupId>org.hsqldb</groupId>
31
+            <artifactId>hsqldb</artifactId>
32
+            <scope>runtime</scope>
33
+        </dependency>
34
+        
28 35
         <dependency>
29 36
             <groupId>org.springframework.boot</groupId>
30 37
             <artifactId>spring-boot-starter</artifactId>

+ 12
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Voir le fichier

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

+ 12
- 8
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Voir le fichier

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Voir le fichier

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Voir le fichier

@@ -1,6 +1,14 @@
1 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 9
 public class Muffin {
10
+    @Id
11
+    @GeneratedValue(strategy = GenerationType.AUTO)
4 12
     private Long id;
5 13
 
6 14
     private String flavor;

+ 4
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Voir le fichier

@@ -4,5 +4,9 @@ import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
9
+@Repository
7 10
 public interface BakerRepository extends CrudRepository<Baker, Long> {
11
+    List<Object> findById(Long id);
8 12
 }

+ 4
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Voir le fichier

@@ -4,5 +4,9 @@ import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
9
+@Repository
7 10
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
11
+
8 12
 }