Soujanya Buragapu 5 년 전
부모
커밋
91cd3add9e

BIN
.DS_Store 파일 보기


+ 23
- 9
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java 파일 보기

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

+ 19
- 11
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java 파일 보기

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

+ 15
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java 파일 보기

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
-public class Baker {
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Baker
7
+{
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "bakerId")
4
     private Long id;
11
     private Long id;
5
 
12
 
13
+    @Column(name = "Name")
6
     private String name;
14
     private String name;
7
 
15
 
16
+    @Column(name = "employeeId")
8
     private String employeeId;
17
     private String employeeId;
9
 
18
 
19
+    @Column(name = "specialty")
10
     private String specialty;
20
     private String specialty;
11
 
21
 
22
+    public Baker() {
23
+
24
+    }
25
+
12
     public Baker(String name, String employeeId, String specialty) {
26
     public Baker(String name, String employeeId, String specialty) {
13
         this.name = name;
27
         this.name = name;
14
         this.employeeId = employeeId;
28
         this.employeeId = employeeId;

+ 14
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java 파일 보기

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
-public class Muffin {
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Muffin
7
+{
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+
11
+    @Column(name = "muffin_id")
4
     private Long id;
12
     private Long id;
5
 
13
 
14
+    @Column(name = "flavor")
6
     private String flavor;
15
     private String flavor;
7
 
16
 
8
     public Muffin(String flavor) {
17
     public Muffin(String flavor) {
9
         this.flavor = flavor;
18
         this.flavor = flavor;
10
     }
19
     }
11
 
20
 
21
+    public Muffin() {
22
+    }
23
+
24
+
12
     public Long getId() {
25
     public Long getId() {
13
         return id;
26
         return id;
14
     }
27
     }