Skip to content

Commit 163cb5b

Browse files
committed
committing initial code
1 parent 110369d commit 163cb5b

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

src/main/java/com/example/easynotes/controller/BoxTrackingController.java

+41-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.example.easynotes.controller;
22

33
import com.example.easynotes.exception.ResourceNotFoundException;
4+
import com.example.easynotes.model.Box;
45
import com.example.easynotes.model.BoxEvent;
6+
import com.example.easynotes.model.BoxState;
57
import com.example.easynotes.repository.BoxEventRepository;
8+
import com.example.easynotes.repository.BoxRepository;
9+
import com.example.easynotes.repository.BoxStateRepository;
10+
611
import org.springframework.beans.factory.annotation.Autowired;
712
import org.springframework.http.ResponseEntity;
813
import org.springframework.web.bind.annotation.*;
@@ -21,29 +26,55 @@ public class BoxTrackingController {
2126
BoxEventRepository boxEventRepository;
2227

2328
@Autowired
24-
BoxEventRepository boxRepository;
29+
BoxRepository boxRepository;
2530

2631
@Autowired
27-
BoxEventRepository boxStateRepository;
32+
BoxStateRepository boxStateRepository;
2833

2934
@GetMapping("/boxes")
30-
public List<BoxEvent> getAllNotes() {
35+
public List<BoxEvent> getAllBoxEvents() {
3136
return boxEventRepository.findAll();
3237
}
38+
39+
@GetMapping("/boxStates")
40+
public List<BoxState> getAllBoxStates() {
41+
return boxStateRepository.findAll();
42+
}
3343

3444
@PostMapping("/boxes")
35-
public BoxEvent createNote(@Valid @RequestBody BoxEvent boxEvent) {
45+
public BoxEvent createBoxEvent(@Valid @RequestBody BoxEvent boxEvent) {
3646
return boxEventRepository.save(boxEvent);
3747
}
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+
}
3863

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) {
4172
return boxEventRepository.findById(boxId)
4273
.orElseThrow(() -> new ResourceNotFoundException("Note", "id", boxId));
4374
}
4475

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,
4778
@Valid @RequestBody BoxEvent boxDetails) {
4879

4980
BoxEvent boxEvent = boxEventRepository.findById(boxId)
@@ -54,8 +85,8 @@ public BoxEvent updateNote(@PathVariable(value = "id") Long boxId,
5485

5586
}
5687

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) {
5990
BoxEvent boxEvent = boxEventRepository.findById(boxId)
6091
.orElseThrow(() -> new ResourceNotFoundException("Note", "id", boxId));
6192

0 commit comments

Comments
 (0)