Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package com.wasim.rest.api.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import com.wasim.rest.api.entity.Student;
import com.wasim.rest.api.service.StudentService;
Expand All @@ -35,9 +29,14 @@ public ResponseEntity<List<Student>> getAllStudent(){

return new ResponseEntity<List<Student>>(studentService.getAllStudent(), HttpStatus.OK);
}

@GetMapping("/getStudent/{id}")
public ResponseEntity<Student> getStudentById(@PathVariable long id){
return new ResponseEntity<Student>(studentService.getStudentById(id), HttpStatus.OK);
}

@PutMapping("/editStudent/{id}")
public ResponseEntity<Student> updateStudent(@PathVariable("id") long id, @RequestBody Student student){
public ResponseEntity<Student> updateStudent(@PathVariable long id, @RequestBody Student student){
return new ResponseEntity<Student>(studentService.updateStudent(id, student), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface StudentRepository extends JpaRepository<Student, Long>{

Student getStudentById(long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
public interface StudentService {

public Student createStudent(Student student);

public List<Student> getAllStudent();


public Student getStudentById(long id);

public Student updateStudent(long id, Student student);

public void deleteStudent(long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public List<Student> getAllStudent() {
return studentRepository.findAll();
}

@Override
public Student getStudentById(long id){
return studentRepository.getStudentById(id);
}

@Override
public Student updateStudent(long id, Student student) {
student.setId(id);
Expand Down