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 @@ ...@@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<annotationProcessing> <annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Gradle Imported" enabled="true"> <profile name="Gradle Imported" enabled="true">
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false"> <processorPath useClasspath="false">
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <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; ...@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class MarksServiceApplication { public class MarksServiceApplication {
public static void main(String[] args) { public static void main(String []args) {
SpringApplication.run(MarksServiceApplication.class, args); SpringApplication.run(MarksServiceApplication.class, args);
} }
......
...@@ -3,7 +3,11 @@ package com.StudentServices.MarksService.controller; ...@@ -3,7 +3,11 @@ package com.StudentServices.MarksService.controller;
import com.StudentServices.MarksService.model.StudentMarks; import com.StudentServices.MarksService.model.StudentMarks;
import com.StudentServices.MarksService.service.StudentService; import com.StudentServices.MarksService.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException; import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -18,34 +22,29 @@ public class StudentMarksController { ...@@ -18,34 +22,29 @@ public class StudentMarksController {
@Autowired StudentService studentService; @Autowired StudentService studentService;
// (GET) findall studentmarks // (GET) findall studentmarks
@GetMapping
ResponseEntity<List<StudentMarks>> findAllStudentMarks(){
return ResponseEntity.ok(studentService.findAllStudents());
}
// (POST) create studentmark // (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 // (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 a particular employee
// // GET: http://localhost:8080/api/v1/employees/__num__ // // GET: http://localhost:8080/api/v1/employees/__num__
...@@ -69,32 +68,16 @@ public class StudentMarksController { ...@@ -69,32 +68,16 @@ public class StudentMarksController {
// //
// return ResponseEntity.ok().body(employee); // 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}") final StudentMarks updatedStudentMarks = studentService.editStudentMarks(studentMarks);
public ResponseEntity<StudentMarks> updateStudentMarks(@PathVariable = "emailAddress") String emailAddressId) throws ConfigDataResourceNotFoundException { return ResponseEntity.ok(updatedStudentMarks);
StudentMarks studentMarks = studentService.
} }
......
...@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Optional;
@Service @Service
public class StudentService { public class StudentService {
...@@ -22,13 +23,21 @@ public class StudentService { ...@@ -22,13 +23,21 @@ public class StudentService {
return null; return null;
} }
public void addStudent(StudentMarks studentMarks) { public StudentMarks addStudent(StudentMarks studentMarks) {
return studentRepository.save(studentMarks);
} }
public void updateStudent(StudentMarks studentMarks, StudentMarks studentMarksDetails) { public StudentMarks getStudentById(String ID) {
studentMarks.setMarks(studentMarksDetails.getMarks()); Optional<StudentMarks> sm = studentRepository.findById(ID);
studentRepository.save(studentMarks); return sm.orElse(null);
}
public StudentMarks editStudentMarks(StudentMarks studentMarks) {
studentMarks.setMarks(studentMarks.getMarks());
return studentRepository.save(studentMarks);
} }
public void deleteStudent(StudentMarks 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