-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJournalEntryController.java
39 lines (30 loc) · 1.14 KB
/
JournalEntryController.java
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
37
38
39
package net.engineeringdigest.journalApp.Controller;
import net.engineeringdigest.journalApp.Entry.JournalEntry;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@RequestMapping("/journal")
public class JournalEntryController {
private Map<Long , JournalEntry> journalEntries = new HashMap<>();
@GetMapping("/abc")
public List<JournalEntry> getAll() {
return new ArrayList<>(journalEntries.values());
}
@PostMapping("/xyz")
public boolean createEntry(@RequestBody JournalEntry myEntry){
journalEntries.put(myEntry.getId(), myEntry);
return true;
}
@GetMapping("id/{myId}")
public JournalEntry getJournalEntryById(@PathVariable Long myId){
return journalEntries.get(myId);
}
@DeleteMapping("id/{myId}")
public JournalEntry deleteEntryById(@PathVariable Long myId){
return journalEntries.remove(myId);
}
@PutMapping("/id/{id}")
public JournalEntry updateJournalById(@PathVariable Long id, @RequestBody JournalEntry myEntry){
return journalEntries.put(id,myEntry);
}
}