1
1
package com .example .easynotes .controller ;
2
2
3
3
import com .example .easynotes .exception .ResourceNotFoundException ;
4
+ import com .example .easynotes .model .Box ;
4
5
import com .example .easynotes .model .BoxEvent ;
6
+ import com .example .easynotes .model .BoxState ;
5
7
import com .example .easynotes .repository .BoxEventRepository ;
8
+ import com .example .easynotes .repository .BoxRepository ;
9
+ import com .example .easynotes .repository .BoxStateRepository ;
10
+
6
11
import org .springframework .beans .factory .annotation .Autowired ;
7
12
import org .springframework .http .ResponseEntity ;
8
13
import org .springframework .web .bind .annotation .*;
@@ -21,29 +26,55 @@ public class BoxTrackingController {
21
26
BoxEventRepository boxEventRepository ;
22
27
23
28
@ Autowired
24
- BoxEventRepository boxRepository ;
29
+ BoxRepository boxRepository ;
25
30
26
31
@ Autowired
27
- BoxEventRepository boxStateRepository ;
32
+ BoxStateRepository boxStateRepository ;
28
33
29
34
@ GetMapping ("/boxes" )
30
- public List <BoxEvent > getAllNotes () {
35
+ public List <BoxEvent > getAllBoxEvents () {
31
36
return boxEventRepository .findAll ();
32
37
}
38
+
39
+ @ GetMapping ("/boxStates" )
40
+ public List <BoxState > getAllBoxStates () {
41
+ return boxStateRepository .findAll ();
42
+ }
33
43
34
44
@ PostMapping ("/boxes" )
35
- public BoxEvent createNote (@ Valid @ RequestBody BoxEvent boxEvent ) {
45
+ public BoxEvent createBoxEvent (@ Valid @ RequestBody BoxEvent boxEvent ) {
36
46
return boxEventRepository .save (boxEvent );
37
47
}
48
+
49
+ @ PostMapping ("/boxState" )
50
+ public BoxState createBoxState (@ Valid @ RequestBody BoxState boxState ) {
51
+ return boxStateRepository .save (boxState );
52
+ }
53
+
54
+ @ GetMapping ("/box" )
55
+ public List <Box > getAllBoxes () {
56
+ return boxRepository .findAll ();
57
+ }
58
+
59
+ @ PostMapping ("/box" )
60
+ public Box createBox (@ Valid @ RequestBody Box box ) {
61
+ return boxRepository .save (box );
62
+ }
38
63
39
- @ GetMapping ("/notes/{id}" )
40
- public BoxEvent getNoteById (@ PathVariable (value = "id" ) Long boxId ) {
64
+ @ GetMapping ("/box/{id}" )
65
+ public Box getBoxById (@ PathVariable (value = "id" ) Long boxId ) {
66
+ return boxRepository .findById (boxId )
67
+ .orElseThrow (() -> new ResourceNotFoundException ("Note" , "id" , boxId ));
68
+ }
69
+
70
+ @ GetMapping ("/boxes/{id}" )
71
+ public BoxEvent getBoxEventById (@ PathVariable (value = "id" ) Long boxId ) {
41
72
return boxEventRepository .findById (boxId )
42
73
.orElseThrow (() -> new ResourceNotFoundException ("Note" , "id" , boxId ));
43
74
}
44
75
45
- @ PutMapping ("/notes /{id}" )
46
- public BoxEvent updateNote (@ PathVariable (value = "id" ) Long boxId ,
76
+ @ PutMapping ("/boxes /{id}" )
77
+ public BoxEvent updateBox (@ PathVariable (value = "id" ) Long boxId ,
47
78
@ Valid @ RequestBody BoxEvent boxDetails ) {
48
79
49
80
BoxEvent boxEvent = boxEventRepository .findById (boxId )
@@ -54,8 +85,8 @@ public BoxEvent updateNote(@PathVariable(value = "id") Long boxId,
54
85
55
86
}
56
87
57
- @ DeleteMapping ("/notes /{id}" )
58
- public ResponseEntity <?> deleteNote (@ PathVariable (value = "id" ) Long boxId ) {
88
+ @ DeleteMapping ("/boxes /{id}" )
89
+ public ResponseEntity <?> deleteBox (@ PathVariable (value = "id" ) Long boxId ) {
59
90
BoxEvent boxEvent = boxEventRepository .findById (boxId )
60
91
.orElseThrow (() -> new ResourceNotFoundException ("Note" , "id" , boxId ));
61
92
0 commit comments