Commit 26c47489 authored by Sumaiyya Burney's avatar Sumaiyya Burney

Implements findAll and findById

parent bf9b8aae
package com.StudentServices.MarksService.controller;
import com.StudentServices.MarksService.model.StudentMarks;
import com.StudentServices.MarksService.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -16,11 +18,23 @@ public class StudentMarksController {
@Autowired StudentService studentService;
// (GET) findall studentmarks
@GetMapping
ResponseEntity<List<StudentMarks>> findAllStudentMarks(){
return ResponseEntity.ok(studentService.findAllStudents());
}
// (POST) create studentmark
// (GET) find studentmark by id
@GetMapping
ResponseEntity<StudentMarks> findStudentMarksById(String id){
StudentMarks sm = studentService.getStudentById(id);
if (sm == null){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
else {
return ResponseEntity.ok(sm);
}
}
// (PUT) update studentmark by id
// (DELETE) delete studentmark by id
......
......@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class StudentService {
......@@ -26,7 +27,8 @@ public class StudentService {
}
public StudentMarks getStudentById(String ID) {
return null;
Optional<StudentMarks> sm = studentRepository.findById(ID);
return sm.orElse(null);
}
public void updateStudent(StudentMarks studentMarks) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment