Browse Source

who knows

Seth 6 years ago
parent
commit
46cfc2da90

+ 5
- 1
pom.xml View File

50
 			<artifactId>spring-data-commons</artifactId>
50
 			<artifactId>spring-data-commons</artifactId>
51
 			<version>1.13.10.RELEASE</version>
51
 			<version>1.13.10.RELEASE</version>
52
 		</dependency>
52
 		</dependency>
53
-	</dependencies>
53
+        <dependency>
54
+            <groupId>org.springframework.boot</groupId>
55
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
56
+        </dependency>
57
+    </dependencies>
54
 
58
 
55
 	<build>
59
 	<build>
56
 		<plugins>
60
 		<plugins>

+ 2
- 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 java.util.logging.Logger;
7
+
6
 @SpringBootApplication
8
 @SpringBootApplication
7
 public class BakeryApplication {
9
 public class BakeryApplication {
8
 
10
 

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

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

+ 5
- 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.Id;
5
+
6
+@Entity
3
 public class Baker {
7
 public class Baker {
8
+    @Id
4
     private Long id;
9
     private Long id;
5
 
10
 
6
     private String name;
11
     private String name;

+ 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.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
5
     private Long id;
13
     private Long id;
6
 
14
 
7
     private String flavor;
15
     private String flavor;

+ 3
- 1
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
 
6
-public interface BakerRepository extends CrudRepository<Baker, Long> {
7
+@Repository
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
 }