Commit a413810f authored by Shanelle Valencia's avatar Shanelle Valencia

Add update method

parents 7b88c4f1 3142ec8f
#Fri Apr 02 15:32:24 PDT 2021
gradle.version=6.8.3
......@@ -2,6 +2,7 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Gradle Imported" enabled="true">
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
......
com/StudentServices/MarksService/MarksServiceApplication.java
com.StudentServices.MarksService.MarksServiceApplication
com/StudentServices/MarksService/service/StudentService.java
com.StudentServices.MarksService.service.StudentService
com/StudentServices/MarksService/model/StudentMarks.java
com.StudentServices.MarksService.model.StudentMarks
com/StudentServices/MarksService/controller/StudentMarksController.java
com.StudentServices.MarksService.controller.StudentMarksController
com/StudentServices/MarksService/repository/StudentRepository.java
com.StudentServices.MarksService.repository.StudentRepository
......@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MarksServiceApplication {
public static void main(String[] args) {
public static void main(String []args) {
SpringApplication.run(MarksServiceApplication.class, args);
}
......
......@@ -3,7 +3,11 @@ 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.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -18,34 +22,29 @@ public class StudentMarksController {
@Autowired StudentService studentService;
// (GET) findall studentmarks
@GetMapping
ResponseEntity<List<StudentMarks>> findAllStudentMarks(){
return ResponseEntity.ok(studentService.findAllStudents());
}
// (POST) create studentmark
@PostMapping("/studentMarks")
public ResponseEntity<StudentMarks> createMarks(@RequestBody StudentMarks studentMarks) {
StudentMarks studentMarks1 = studentService.addStudent(studentMarks);
return ResponseEntity.ok().body(studentMarks1);
}
// (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
//////////////////////////////////
// EX CODE FROM EMPLOYEE SERVICE
//////////////////////////////////
// // Return all employees
// // GET: http://localhost:8080/api/v1/employees/
// @GetMapping("/employees")
// public List<Employee> getAllEmployees() {
// return employeeService.findAllEmployees();
// }
//
// // Create a new employee
// // POST: http://localhost:8080/api/v1/employees/create
// // send this in postman: {"id": "4", "firstName": "Kyle", "lastName": "Muldoon"}
// @PostMapping("/employees/create")
// public Employee createEmployee(@RequestBody Employee employee) {
// return employeeService.addEmployee(employee);
// }
//
// // Get a particular employee
// // GET: http://localhost:8080/api/v1/employees/__num__
......@@ -69,32 +68,16 @@ public class StudentMarksController {
//
// return ResponseEntity.ok().body(employee);
// }
//
//
// // Delete a particular employee
// @DeleteMapping("/employees/remove/{id}")
// public ResponseEntity<Employee> deleteEmployeeById(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
//
// Employee employee = employeeService.getEmployeeById(employeeId)
// .orElseThrow(() -> new ResourceNotFoundException("Employee by Id Not Found" + employeeId));
// employeeService.deleteEmployeeById(employee.getId());
//
// return ResponseEntity.ok().body(employee);
// }
@GetMapping("/studentmarks/{id}")
public ResponseEntity<StudentMarks> getEmployeeById(@PathVariable(value = "emailAddress") String emailAddressId) throws ResourceNotFoundException {
StudentMarks studentMarks = studentService.
.orElseThrow(() -> new ResourceNotFoundException("Employee by Id Not Found" + employeeId));
return ResponseEntity.ok().body(employee);
}
@PutMapping("/studentMarks/update/{emailAddress}")
public ResponseEntity<StudentMarks> updateStudentMarks(@PathVariable (value= "emailAddress") String emailAddressId) throws ConfigDataResourceNotFoundException {
StudentMarks studentMarks = studentService.getStudentById(emailAddressId)
// .(() -> new ConfigDataResourceNotFoundException);
@PutMapping("/studentmarks/update/{id}")
public ResponseEntity<StudentMarks> updateStudentMarks(@PathVariable = "emailAddress") String emailAddressId) throws ConfigDataResourceNotFoundException {
StudentMarks studentMarks = studentService.
final StudentMarks updatedStudentMarks = studentService.editStudentMarks(studentMarks);
return ResponseEntity.ok(updatedStudentMarks);
}
......
......@@ -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 {
......@@ -22,13 +23,21 @@ public class StudentService {
return null;
}
public void addStudent(StudentMarks studentMarks) {
public StudentMarks addStudent(StudentMarks studentMarks) {
return studentRepository.save(studentMarks);
}
public void updateStudent(StudentMarks studentMarks, StudentMarks studentMarksDetails) {
studentMarks.setMarks(studentMarksDetails.getMarks());
studentRepository.save(studentMarks);
public StudentMarks getStudentById(String ID) {
Optional<StudentMarks> sm = studentRepository.findById(ID);
return sm.orElse(null);
}
public StudentMarks editStudentMarks(StudentMarks studentMarks) {
studentMarks.setMarks(studentMarks.getMarks());
return studentRepository.save(studentMarks);
}
public void deleteStudent(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