-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemController.java
More file actions
36 lines (29 loc) · 1.09 KB
/
ItemController.java
File metadata and controls
36 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.mrxgrc.inventory.controller;
import com.mrxgrc.inventory.model.Item;
import com.mrxgrc.inventory.service.ItemService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class ItemController {
private final ItemService itemService;
public ItemController(ItemService itemService) {
this.itemService = itemService;
}
@GetMapping("/items")
public List<Item> getItems() {
return itemService.getAllItems();
}
@GetMapping("/items/{requestedId}")
public ResponseEntity<Item> getItemById(@PathVariable Long requestedId) {
// Call itemService.findById(requestedId) and return the appropriate response entity
Item item = itemService.findById(requestedId);
if (item == null) {
return ResponseEntity.notFound().build();
} else {
return ResponseEntity.ok(item);
}
}
}