Ver código fonte

{jaejoson Bakery lab}

Jacqueline Joson 5 anos atrás
pai
commit
e9c13a0a08

BIN
.DS_Store Ver arquivo


+ 8
- 1
pom.xml Ver arquivo

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
+
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>

+ 12
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Ver arquivo

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
+@RestController
8
 public class BakerController {
11
 public class BakerController {
12
+    @Autowired
9
     private BakerRepository bakerRepository;
13
     private BakerRepository bakerRepository;
10
 
14
 
15
+    @GetMapping("/index")
11
     public ResponseEntity<Iterable<Baker>> index() {
16
     public ResponseEntity<Iterable<Baker>> index() {
12
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
17
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13
     }
18
     }
14
-
19
+    @GetMapping("/show")
15
     public ResponseEntity<Baker> show(Long id) {
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
     public ResponseEntity<Baker> create(Baker baker) {
25
     public ResponseEntity<Baker> create(Baker baker) {
20
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
26
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21
     }
27
     }
22
 
28
 
29
+    @PutMapping("/update")
23
     public ResponseEntity<Baker> update(Long id, Baker baker) {
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
         foundBaker.setName(baker.getName());
33
         foundBaker.setName(baker.getName());
27
         foundBaker.setSpecialty(baker.getSpecialty());
34
         foundBaker.setSpecialty(baker.getSpecialty());
29
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
36
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
30
     }
37
     }
31
 
38
 
39
+    @DeleteMapping("/delete")
32
     public ResponseEntity<Boolean> destroy(Long id) {
40
     public ResponseEntity<Boolean> destroy(Long id) {
33
-        this.bakerRepository.findById(id).get();
41
+        this.bakerRepository.findById(id);
34
         return new ResponseEntity<>(true, HttpStatus.OK);
42
         return new ResponseEntity<>(true, HttpStatus.OK);
35
     }
43
     }
36
 }
44
 }

+ 12
- 8
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Ver arquivo

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Ver arquivo

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Ver arquivo

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

+ 4
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Ver arquivo

4
 import org.springframework.data.repository.CrudRepository;
4
 import org.springframework.data.repository.CrudRepository;
5
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
6
 
6
 
7
+import java.util.List;
8
+
9
+@Repository
7
 public interface BakerRepository extends CrudRepository<Baker, Long> {
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 Ver arquivo

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