Commit 4c2305c0 authored by dbhuller's avatar dbhuller

adds create, update methods to service

parent 0c8dcb6b
package service.student.studentaddressservice.service;
import org.apache.catalina.valves.StuckThreadDetectionValve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import service.student.studentaddressservice.StudentAddressServiceApplication;
import service.student.studentaddressservice.model.StudentAddress;
import service.student.studentaddressservice.repository.StudentAddressRepository;
......@@ -22,4 +24,21 @@ public class StudentAddressService {
public Optional<StudentAddress> getStudentAddressByEmail(String email){
return Optional.ofNullable(studentAddressRepository.findByEmail(email));
}
public StudentAddress createStudentAddress(StudentAddress studentAddressDetails) {
return studentAddressRepository.save(studentAddressDetails);
}
public StudentAddress updateStudentAddress(StudentAddress studentAddressDetails, String email) {
StudentAddress studentAddressToUpdate =
getStudentAddressByEmail(email).orElseThrow(() -> new NullPointerException("Email not found: " + email)); //TEMPORARY FIX
studentAddressToUpdate.setStreetAddress(studentAddressDetails.getStreetAddress());
studentAddressToUpdate.setState(studentAddressDetails.getState());
studentAddressToUpdate.setCity(studentAddressDetails.getCity());
studentAddressToUpdate.setZip(studentAddressDetails.getZip());
if (studentAddressDetails.getAptNum() != null) {
studentAddressToUpdate.setAptNum(studentAddressDetails.getAptNum());
}
return studentAddressRepository.save(studentAddressToUpdate);
}
}
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