Skip to content

Commit 88cd651

Browse files
author
Karthik Raghunathan
committed
working get, getall, put todo thymeleaf
1 parent b856575 commit 88cd651

File tree

216 files changed

+10538
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+10538
-13
lines changed

src/main/java/com/example/todo/Entry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.example.todo;
22

3+
import org.springframework.format.annotation.DateTimeFormat;
4+
35
import javax.persistence.Entity;
46
import javax.persistence.GeneratedValue;
57
import javax.persistence.GenerationType;
@@ -16,7 +18,11 @@ public class Entry {
1618
private String owner;
1719
private double latitude;
1820
private double longitude;
21+
22+
@DateTimeFormat(pattern = "yyyy-MM-dd")
1923
private Date created;
24+
25+
@DateTimeFormat(pattern = "yyyy-MM-dd")
2026
private Date lastUpdated;
2127
private String status;
2228

src/main/java/com/example/todo/EntryController.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,63 @@
33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.web.bind.annotation.DeleteMapping;
55
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.ModelAttribute;
7+
import org.springframework.web.bind.annotation.PathVariable;
68
import org.springframework.web.bind.annotation.PostMapping;
79
import org.springframework.web.bind.annotation.PutMapping;
810
import org.springframework.web.bind.annotation.RestController;
11+
import org.springframework.web.servlet.ModelAndView;
12+
13+
import java.util.List;
14+
import java.util.Optional;
915

1016
@RestController
1117
public class EntryController {
1218

13-
1419
@Autowired
1520
EntryRepository repository;
1621

22+
@GetMapping("/todos")
23+
public ModelAndView all() {
1724

18-
@GetMapping
19-
public String get(){
20-
return "hello world";
25+
ModelAndView v = new ModelAndView("items");
26+
List<Entry> l = repository.findAll();
27+
v.addObject("donkeys", l);
28+
return v;
29+
}
30+
31+
@GetMapping("/todos/.json")
32+
public List<Entry> alljson() {
33+
34+
List<Entry> l = repository.findAll();
35+
return l;
2136
}
22-
@PutMapping
23-
public void put(){
2437

38+
@GetMapping("/todos/{id}")
39+
public ModelAndView get(@PathVariable Long id){
40+
ModelAndView mv = new ModelAndView("item");
41+
42+
Optional<Entry> l = repository
43+
.findById(id);
44+
mv.addObject( "item", l.get());
45+
return mv;
46+
}
47+
48+
@PostMapping("/todos")
49+
public String newEmployee(@ModelAttribute Entry newEntry) {
50+
51+
repository.save( newEntry);
52+
return "OK done";
2553
}
26-
@PostMapping
27-
public void post(){
54+
55+
@PutMapping("/todos/{id})")
56+
public void put(){
2857

2958
}
30-
@DeleteMapping
31-
public void delete(){
3259

60+
@DeleteMapping("/todos/{id}")
61+
public void deleteEmployee(@PathVariable Long id) {
62+
repository.deleteById(id);
3363
}
3464

3565

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.example.todo;
22

3-
import org.springframework.data.repository.CrudRepository;
3+
import org.springframework.data.jpa.repository.JpaRepository;
44

55
// see : https://www.baeldung.com/spring-data-repositories
6-
76
// I think we should use a PagingAndSortingRepository
87

9-
public interface EntryRepository extends CrudRepository<Entry, Long> {
8+
public interface EntryRepository extends JpaRepository<Entry, Long> {
109

1110
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*!
2+
* Start Bootstrap - 3 Col Portfolio (http://startbootstrap.com/)
3+
* Copyright 2013-2016 Start Bootstrap
4+
* Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE)
5+
*/
6+
7+
body {
8+
padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
9+
}
10+
11+
.portfolio-item {
12+
margin-bottom: 25px;
13+
}
14+
15+
footer {
16+
margin: 50px 0;
17+
}

src/main/resources/public/css/bootstrap-theme.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)