Skip to content

Commit 8687ebc

Browse files
committed
student done ✅
1 parent c333499 commit 8687ebc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/main/java/com/gdsc/springbootworkshop/controllers/StudentController.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.*;
77

8+
import javax.websocket.server.PathParam;
89
import java.util.List;
910

1011
@RestController
@@ -24,6 +25,24 @@ Student addStudent(@RequestBody Student student) throws Exception {
2425
return studentService.addStudent(student);
2526
}
2627

28+
@PutMapping("/{id}")
29+
Student updateStudent(@PathVariable("id") Long id, @RequestBody Student student){
30+
return studentService.updateStudent(id, student);
31+
}
32+
33+
@DeleteMapping("/{id}")
34+
void deleteStudent(@PathVariable("id") Long id){
35+
studentService.deleteStudent(id);
36+
}
37+
38+
@GetMapping("/{id}")
39+
Student findById(@PathVariable("id") Long id){
40+
return studentService.findById(id);
41+
}
42+
43+
44+
45+
2746

2847

2948
}

src/main/java/com/gdsc/springbootworkshop/services/StudentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Student addStudent(Student student) throws Exception {
2727

2828
@Override
2929
public Student updateStudent(Long id, Student student) {
30-
if(studentRepository.findById(id).isPresent() ){
30+
if(studentRepository.findById(id).isPresent()){
3131
Student toUpdateStudent = studentRepository.findById(id).get();
3232
toUpdateStudent.setFirstName(student.getFirstName());
3333
toUpdateStudent.setLastName(student.getLastName());

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ spring.datasource.password=
99
## JPA / HIBERNATE ###
1010
spring.jpa.show-sql=true
1111
spring.jpa.generate-ddl=true
12-
spring.jpa.hibernate.ddl-auto=create
12+
spring.jpa.hibernate.ddl-auto=update

0 commit comments

Comments
 (0)