Ver código fonte

troubleshooting db

Jonathan Hinds 7 anos atrás
pai
commit
181c8d9a16

+ 5
- 3
src/main/java/io/zipcoder/persistenceapp/PersonController.java Ver arquivo

@@ -23,16 +23,18 @@ public class PersonController {
23 23
     }
24 24
 
25 25
     @PutMapping("/people/{id}")
26
-    @ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Person not found.")
26
+    //@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Person not found.")
27 27
     public Person updatePerson(@PathVariable int id, @RequestBody Person updatedPerson){
28 28
         Person p = serv.findById(id);
29
+        System.out.println(p + " line 29");
29 30
         updatedPerson.setId(p.getId());
30
-        if( p != null ) {
31
+        if(p != null) {
31 32
             serv.updatePerson(updatedPerson);
33
+            System.out.println("Updated");
32 34
         } else {
33 35
             new ResponseEntity(HttpStatus.NOT_FOUND);
34 36
         }
35
-        return null;
37
+        return updatedPerson;
36 38
     }
37 39
 
38 40
     @GetMapping("/people")

+ 9
- 3
src/main/java/io/zipcoder/persistenceapp/PersonService.java Ver arquivo

@@ -54,8 +54,8 @@ public class PersonService {
54 54
                 e.getFirstName() + "', LAST_NAME = '" +
55 55
                 e.getLastName() + "', MOBILE = '" +
56 56
                 e.getMobile() + "', BIRTHDAY = '" +
57
-                e.getBirthday() + "', HOME_ID = '" +
58
-                e.getHomeId() + "' where id = '" + e.getId() + "');");
57
+                e.getBirthday() + "', HOME_ID = " +
58
+                e.getHomeId() + " where id = " + e.getId() + ";");
59 59
     }
60 60
 
61 61
     public int deletePerson(Person e){
@@ -73,7 +73,13 @@ public class PersonService {
73 73
     }
74 74
 
75 75
     public Person findById(int ID){
76
-        return jdbcTemplate.queryForObject("SELECT * FROM PERSON WHERE ID = " + ID + ";", Person.class);
76
+        List<Person> people = getAllPeople();
77
+        for(Person person : people){
78
+            if(person.getId() == ID){
79
+                return person;
80
+            }
81
+        }
82
+        return null;
77 83
     }
78 84
 
79 85
     public Map<String, List<Person>> surnameQuery(){