"Welcome To Ashok IT" "Spring Boot & Microservices" Topic : Rest API Development - PUT & PATCH Request Mapping Date : 13/06/2025 (Session - 66) _____________________________________________________________________________________________________________________________ Mini Project Setup ================== * We Will be Implementing the Rest API Development with Mini Project(GET,POST,PUT,PATCH,DELETE) * As part of this mini project development will be covering with below concepts 1) Rest API Development with Database Interaction 2) Swagger Documentation Configuration for Rest API Mini Project 3) Exception Handling in Rest API Development 1) Creating the Spring boot Starter Project using below starter * Web Starter * Oracle Driver * Lombok * ModelMapper(Collect From Maven Repoistory) * Spring Boot Dev Tools 2) Creating the Following packages to organize our classes in project com.ashokit |-> Application.java com.ashokit.constants |-> ApplicationConstants.java com.ashokit.controller |-> PersonController.java com.ashokit.dao |-> PersonDao.java com.ashokit.service |-> PersonService.java |-> PersonServiceImpl.java com.ashokit.dto |-> PersonDTO.java com.ashokit.entity |-> Person.java com.ashokit.exception |-> ResourceNotFoundException.java com.ashokit.response |-> PageResponse.java pom.xml ======= 4.0.0 org.springframework.boot spring-boot-starter-parent 3.4.5 com.ashokit 36_SpringBootRest_MiniProject_App 0.0.1-SNAPSHOT war 36_SpringBootRest_MiniProject_App SpringBoot Rest API Mini Project 17 org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true com.oracle.database.jdbc ojdbc8 runtime org.projectlombok lombok true org.springframework.boot spring-boot-starter-tomcat provided org.springframework.boot spring-boot-starter-test test org.modelmapper modelmapper 3.1.1 com.fasterxml.jackson.dataformat jackson-dataformat-xml org.springdoc springdoc-openapi-starter-webmvc-ui 2.2.0 org.springframework.boot spring-boot-maven-plugin application.properties ====================== #server port changing server.port=8899 #Database Configuration spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe spring.datasource.username=system spring.datasource.password=manager #Hibernate Configuration spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true #FileUploading Configurations project.images=profilepics spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=10MB Person.java =========== package com.ashokit.entity; import java.time.LocalDate; import java.time.LocalDateTime; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @Entity @Table(name="ashokit_persons") @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class Person { @Id @Column(name="person_id",nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name="person_name") private String name; @Column(name="location") private String location; @Column(name="email_id") private String emailId; @Column(name="address") private String address; @Column(name="created_dt") @Temporal(TemporalType.TIMESTAMP) private LocalDateTime createdDate; } PersonDTO.java ============== package com.ashokit.dto; import java.time.LocalDateTime; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor @Builder @Schema(description = "Request Payload for Creating the Person Record....") public class PersonDTO { @Schema(description = "PersonID Will be auto generated....") private Integer id; @Schema(description = "PersonName",example = "Mahesh") private String name; @Schema(description = "PersonLocation",example="Hyderabad") private String location; @Schema(description = "PersonEmailID",example="mahesh.ashokit@gmail.com") private String emailId; @Schema(description = "PersonAddress",example="Hyderabad,Ameerpet") private String address; @Schema(description = "Person Record CreatedData Will be autogenerated.....") private LocalDateTime createdDate; } PersonService.java ================== package com.ashokit.service; import java.util.List; import org.springframework.web.multipart.MultipartFile; import com.ashokit.dto.PersonDTO; import com.ashokit.response.PageResponse; public interface PersonService { //creating the new Person public PersonDTO createNewPerson(PersonDTO personDTO) throws Exception; //Getting all Persons with out pagination public List getAllPersons(); //Getting all Persons with pagination public PageResponse getAllPersons(Integer pageNumber,Integer pageSize,String sortBy,String sortDirection); //Updating the Person Details public PersonDTO updatePersonDetails(PersonDTO personDTO); //Updating the Person Location field only public PersonDTO updatePersonLocationDetails(Integer personId,String newLocation); //Deleting the Person Details public String deletePersonDetailsById(Integer personId); //supporting for uploading public String uploadProfilePicture(String imageLocation, MultipartFile multipartImage) throws Exception; } PersonServiceImpl.java ====================== package com.ashokit.service; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import java.time.LocalDate; import java.util.List; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; import org.modelmapper.ModelMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import com.ashokit.dao.PersonDao; import com.ashokit.dto.PersonDTO; import com.ashokit.entity.Person; import com.ashokit.exceptions.ResourceNotFoundException; import com.ashokit.response.PageResponse; @Service public class PersonServiceImpl implements PersonService { @Autowired private PersonDao personDao; @Autowired private ModelMapper modelMapper; @Override public PersonDTO createNewPerson(PersonDTO personDTO) throws Exception { //Input Received as DTO and we need to Convert into Entity Class i.e.,Person Person personObj = this.modelMapper.map(personDTO, Person.class); //Setting Current Data While inserting the record personObj.setCreatedDate(LocalDate.now()); //personObj.setUpdatedDate(LocalDate.now()); //save the personObj into Database Person savedPersonObj = personDao.save(personObj); //Converting Back from Entity Class Object into DTO Class Object PersonDTO savedPersonDetails = this.modelMapper.map(savedPersonObj, PersonDTO.class); return savedPersonDetails; } @Override public List getAllPersons() { List allPersons = personDao.findAll(); //converting from List into List //allPersons.stream() -> converting List into Stream object //map() -> Its is a intermediate stream operation which take one input(Person) and give it as one output(PersonDTO) //collect() -> It is a terminal operation to collect data into single object //Collectors -> It is utility class from Java8 Stream library to collect data into list,set,map object // i.e..,Collectors.toList(), Collectors.toSet(), Collectors.toMap() List allPersonDtos = allPersons.stream().map(eachPerson ->{ return new PersonDTO(eachPerson.getId(),eachPerson.getName(), eachPerson.getLocation(),eachPerson.getEmailId(), eachPerson.getAddress(),eachPerson.getCreatedDate()); }).collect(Collectors.toList()); return allPersonDtos; } @Override public PageResponse getAllPersons(Integer pageNumber, Integer pageSize, String sortBy, String sortDirection) { //sortBy ::: Sorting Field Sort sort = Sort.by(sortBy).descending(); if("asc".equalsIgnoreCase(sortDirection)) { sort = sort.by(sortBy).ascending(); } //Creating the PageRequest Object Pageable pageable = PageRequest.of(pageNumber, pageSize, sort); //Get All the Records based on Pagination Page pageInfo = personDao.findAll(pageable); //Getting the pagecontent from above Page object List personList = pageInfo.getContent(); //Converting List into List //modelMapper -> predefined class from modelMapper library. // -> We represented this class as spring bean then we can autowire anywhere in our application // -> Modelmapper contains map() which takes two arguments first argument-> source type // -> Second argument -> destination type // -> return type -> destination type List personDTOList = personList.stream() .map(eachPerson -> this.modelMapper.map(eachPerson, PersonDTO.class)) .collect(Collectors.toList()); //Creating PageResponse Object for setting pagination Information PageResponse pageResponse = new PageResponse(); pageResponse.setContent(personDTOList); pageResponse.setPageNumber(pageInfo.getNumber()); pageResponse.setPageSize(pageInfo.getSize()); pageResponse.setTotalElements(pageInfo.getTotalElements()); pageResponse.setTotalPages(pageInfo.getTotalPages()); pageResponse.setLastPage(pageInfo.isLast()); return pageResponse; } @Override public PersonDTO updatePersonDetails(PersonDTO personDTO)throws ResourceNotFoundException{ //Fetching Existing Person Details Optional existingPersonDetails = personDao.findById(personDTO.getId()); if(existingPersonDetails.isPresent()) { //convert from DTO to Entity Person personDetails = this.modelMapper.map(personDTO, Person.class); //updating the record personDetails.setCreatedDate(existingPersonDetails.get().getCreatedDate()); Person updatedPersonDetails = personDao.save(personDetails); //Converting from Entity To DTO PersonDTO updatePersonDTODetails = this.modelMapper.map(updatedPersonDetails, PersonDTO.class); return updatePersonDTODetails; }else { throw new ResourceNotFoundException("Person", "PersonID", personDTO.getId()); } } @Override public PersonDTO updatePersonLocationDetails(Integer personId, String newLocation) { //Fetching Existing Person Details Optional existingPersonDetails = personDao.findById(personId); if(existingPersonDetails.isPresent()) { Person personDetails= existingPersonDetails.get(); //Setting the newLocation into Old Location personDetails.setLocation(newLocation); //saving the person information Person updatedPersonDetails = personDao.save(personDetails); //converting from entity class into DTO Class return this.modelMapper.map(updatedPersonDetails, PersonDTO.class); }else { throw new ResourceNotFoundException("Person", "PersonID", personId); } } @Override public String deletePersonDetailsById(Integer personId) { //Fetching Existing Person Details Optional existingPersonDetails = personDao.findById(personId); if(existingPersonDetails.isPresent()) { personDao.deleteById(personId); return String.format("%s Deleted Successfully", personId); }else { throw new ResourceNotFoundException("Person", "PersonID", personId,"Exception Occured in Delete..."); } } @Override public String uploadProfilePicture(String imageLocation, MultipartFile multipartImage) throws Exception{ //getting the original FileName i.e.,UserUploadedImage file name String originalFilename = multipartImage.getOriginalFilename(); System.out.println("Original File Name::::" + originalFilename); //Renaming the File Name String randomID = UUID.randomUUID().toString(); System.out.println("RandomID:::::" + randomID); //user.jpeg,user_profile.png String substringfileName= originalFilename.substring(originalFilename.lastIndexOf("."));//.png System.out.println("SubString file name::::" + substringfileName); String renamedFileName = randomID.concat(substringfileName); System.out.println("RenamedFileName:::::" + renamedFileName); //FilePath to be stored String destinationFilePath = imageLocation+File.separator+renamedFileName; System.out.println("Destination File Path::::" + destinationFilePath); //creating the folder if not exists File fileFolder = new File(imageLocation);//profilepics if(!fileFolder.exists()) fileFolder.mkdir(); //Copying the file Files.copy(multipartImage.getInputStream(), Paths.get(destinationFilePath)); return renamedFileName; } } PageResponse.java ================== package com.ashokit.response; import java.util.List; import com.ashokit.dto.PersonDTO; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @NoArgsConstructor @AllArgsConstructor @Setter @Getter public class PageResponse { //Holding page specific records private List content; private int pageNumber; private int pageSize; private long totalElements; private long totalPages; //If current page is lastPage means will return true otherwise will return false private boolean lastPage; } Application.java ================ package com.ashokit; import org.modelmapper.ModelMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } //Making ModelMapper as SpringBean @Bean public ModelMapper getModelMapper() { return new ModelMapper(); } } ResourceNotFoundException.java ============================== package com.ashokit.exceptions; import lombok.Getter; import lombok.Setter; @Getter @Setter public class ResourceNotFoundException extends RuntimeException { private static final long serialVersionUID = 1L; private String resourceName; private String fieldName; private long fieldValue; private String errorInfo; public ResourceNotFoundException() { // TODO Auto-generated constructor stub } // parameterized Constructor public ResourceNotFoundException(String resourceName, String fieldName) { // Person not found with personId super(String.format("%s not found with Given %s ", resourceName, fieldName)); this.resourceName = resourceName; this.fieldName = fieldName; } // parameterized Constructor public ResourceNotFoundException(String resourceName, String fieldName, long fieldValue) { // Person not found with personId : 1256 super(String.format("%s not found with %s : %s", resourceName, fieldName, fieldValue)); this.resourceName = resourceName; this.fieldName = fieldName; this.fieldValue = fieldValue; } // parameterized Constructor public ResourceNotFoundException(String resourceName, String fieldName, long fieldValue, String errorInfo) { // Person not found with personId : 1256 super(String.format("%s not found with %s : %s....%s", resourceName, fieldName, fieldValue,errorInfo)); this.resourceName = resourceName; this.fieldName = fieldName; this.fieldValue = fieldValue; this.errorInfo = errorInfo; } } PersonController.java ===================== package com.ashokit.controller; import java.time.LocalDateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import com.ashokit.constants.ApplicationConstants; import com.ashokit.dto.PersonDTO; import com.ashokit.exceptions.ErrorDetails; import com.ashokit.exceptions.ResourceNotFoundException; import com.ashokit.response.PageResponse; import com.ashokit.service.PersonService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/api/persons") @Tag(name="Person",description = "Person Controller Rest API Methods") public class PersonController { @Autowired private PersonService personService; //Getting image location @Value("${project.images}") private String imageLocation; @GetMapping(value="/",produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}) @Operation(summary = "This API is used for getting Persons information with Pagination", description ="This API Will return the Persons information by default with Pagination.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "Successfully Retrieved All the Persons Information....."), @ApiResponse(responseCode = "500", description = "Failure because of Unable to Retreive Persons Information.....") }) public ResponseEntity getAllPersonsInformation( @Parameter(description = "Defining the PageNumber To get Particular Page of Person Records default value is 0..") @RequestParam(name="pageNumber",defaultValue=ApplicationConstants.PAGE_NUMBER, required=false) Integer pageNumber, @Parameter(description = "Defining the PageSize To be displayed no of records in particular page the default value is 10... ") @RequestParam(name="pageSize",defaultValue=ApplicationConstants.PAGE_SIZE, required=false) Integer pageSize, @Parameter(description = "Defining the field to sort the person records based on supplied value and default value will be personID...") @RequestParam(name="sortBy",defaultValue=ApplicationConstants.SORT_BY, required=false) String sortBy, @Parameter(description = "Defining the Sort direction for sorting the recoreds and default value will be ascending...") @RequestParam(name="sortDir",defaultValue=ApplicationConstants.SORT_DIR, required=false) String sortDirection){ //Calling service method to get records with pagination PageResponse paginationData = personService.getAllPersons(pageNumber,pageSize,sortBy,sortDirection); return new ResponseEntity(paginationData,HttpStatus.OK); } @PostMapping(value="/",consumes = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}) @Operation(summary = "This API is used for Creating new Brand Person Record in Application", description ="This API Will Create new Person Record which accepts the Payload as JSON(or) XML .") @ApiResponses({ @ApiResponse(responseCode = "201", description = "Successfully new brand person record got created...."), @ApiResponse(responseCode = "500", description = "Request has been failed due to some technical problem....") }) public ResponseEntity createNewPerson(@RequestBody PersonDTO personDTO) throws Exception{ PersonDTO savedPersonDTO = personService.createNewPerson(personDTO); return new ResponseEntity(savedPersonDTO,HttpStatus.CREATED); } @PutMapping(value="/",consumes = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}) @Operation(summary = "This API is used for Updating existing Person Details in Application", description ="This API Will Modifying Person Details which accepts the Payload as JSON/XML.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "Successfully Updated Person Details....."), @ApiResponse(responseCode = "404", description = "RequestBody PersonId is not available...."), @ApiResponse(responseCode = "500", description = "Request Failed while processing data.....") }) public ResponseEntity modifyPersonDetails(@RequestBody PersonDTO personDTO){ PersonDTO updatedPersonDetails = personService.updatePersonDetails(personDTO); return new ResponseEntity(updatedPersonDetails,HttpStatus.OK); } @PatchMapping(value="/{personId}/{newLocation}",consumes = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity updatePersonLocationDetails(@PathVariable("personId") Integer personId, @PathVariable("newLocation") String newLocation){ PersonDTO updatedPersonDetails = personService.updatePersonLocationDetails(personId, newLocation); return new ResponseEntity(updatedPersonDetails,HttpStatus.OK); } @DeleteMapping("/{personId}") public ResponseEntity deletePersonDetails(@PathVariable("personId") Integer personId) { String deleteStatus = personService.deletePersonDetailsById(personId); return new ResponseEntity(deleteStatus, HttpStatus.OK); } //Rest API Method for Uploading image @PostMapping("/upload") public ResponseEntity uploadProfileImage(@RequestParam("profileImage") MultipartFile multipartImage) throws Exception { String renamedFileName = personService.uploadProfilePicture(imageLocation, multipartImage); return new ResponseEntity(renamedFileName, HttpStatus.OK); } //Controller level Exception Handler @ExceptionHandler(ResourceNotFoundException.class) public ResponseEntity handlingResourceNotFoundException(ResourceNotFoundException rnfe){ ErrorDetails errorDetails = ErrorDetails.builder().errorTime(LocalDateTime.now()) .errorMessage(rnfe.getMessage()) //Person not found with personId : 1256 .errorStatus("Resource Not Found.....") .build(); return new ResponseEntity(errorDetails,HttpStatus.NOT_FOUND); } } POST Request API ================ package com.ashokit.service; import java.util.List; import org.springframework.web.multipart.MultipartFile; import com.ashokit.dto.PersonDTO; import com.ashokit.response.PageResponse; public interface PersonService { //creating the new Person public PersonDTO createNewPerson(PersonDTO personDTO) throws Exception; //Getting all Persons with out pagination public List getAllPersons(); //Getting all Persons with pagination public PageResponse getAllPersons(Integer pageNumber,Integer pageSize,String sortBy,String sortDirection); } PersonServiceImpl.java ====================== package com.ashokit.service; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import java.time.LocalDate; import java.util.List; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; import org.modelmapper.ModelMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import com.ashokit.dao.PersonDao; import com.ashokit.dto.PersonDTO; import com.ashokit.entity.Person; import com.ashokit.exceptions.ResourceNotFoundException; import com.ashokit.response.PageResponse; @Service public class PersonServiceImpl implements PersonService { @Autowired private PersonDao personDao; @Autowired private ModelMapper modelMapper; @Override public PersonDTO createNewPerson(PersonDTO personDTO) throws Exception { //Input Received as DTO and we need to Convert into Entity Class i.e.,Person Person personObj = this.modelMapper.map(personDTO, Person.class); //Setting Current Data While inserting the record personObj.setCreatedDate(LocalDate.now()); //save the personObj into Database Person savedPersonObj = personDao.save(personObj); //Converting Back from Entity Class Object into DTO Class Object PersonDTO savedPersonDetails = this.modelMapper.map(savedPersonObj, PersonDTO.class); return savedPersonDetails; } @Override public List getAllPersons() { List allPersons = personDao.findAll(); //converting from List into List //allPersons.stream() -> converting List into Stream object //map() -> Its is a intermediate stream operation which take one input(Person) and give it as one output(PersonDTO) //collect() -> It is a terminal operation to collect data into single object //Collectors -> It is utility class from Java8 Stream library to collect data into list,set,map object // i.e..,Collectors.toList(), Collectors.toSet(), Collectors.toMap() List allPersonDtos = allPersons.stream().map(eachPerson ->{ return new PersonDTO(eachPerson.getId(),eachPerson.getName(), eachPerson.getLocation(),eachPerson.getEmailId(), eachPerson.getAddress(),eachPerson.getCreatedDate()); }).collect(Collectors.toList()); return allPersonDtos; } @Override public PageResponse getAllPersons(Integer pageNumber, Integer pageSize, String sortBy, String sortDirection) { //sortBy ::: Sorting Field Sort sort = Sort.by(sortBy).descending(); if("asc".equalsIgnoreCase(sortDirection)) { sort = sort.by(sortBy).ascending(); } //Creating the PageRequest Object Pageable pageable = PageRequest.of(pageNumber, pageSize, sort); //Get All the Records based on Pagination Page pageInfo = personDao.findAll(pageable); //Getting the pagecontent from above Page object List personList = pageInfo.getContent(); //Converting List into List //modelMapper -> predefined class from modelMapper library. // -> We represented this class as spring bean then we can autowire anywhere in our application // -> Modelmapper contains map() which takes two arguments first argument-> source type // -> Second argument -> destination type // -> return type -> destination type List personDTOList = personList.stream() .map(eachPerson -> this.modelMapper.map(eachPerson, PersonDTO.class)) .collect(Collectors.toList()); //Creating PageResponse Object for setting pagination Information PageResponse pageResponse = new PageResponse(); pageResponse.setContent(personDTOList); pageResponse.setPageNumber(pageInfo.getNumber()); pageResponse.setPageSize(pageInfo.getSize()); pageResponse.setTotalElements(pageInfo.getTotalElements()); pageResponse.setTotalPages(pageInfo.getTotalPages()); pageResponse.setLastPage(pageInfo.isLast()); return pageResponse; } } PersonController.java ===================== package com.ashokit.controller; import java.time.LocalDateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import com.ashokit.constants.ApplicationConstants; import com.ashokit.dto.PersonDTO; import com.ashokit.exceptions.ErrorDetails; import com.ashokit.exceptions.ResourceNotFoundException; import com.ashokit.response.PageResponse; import com.ashokit.service.PersonService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; @RestController @RequestMapping("/api/persons") @Tag(name="Person",description = "Person Controller Rest API Methods") public class PersonController { @Autowired private PersonService personService; @PostMapping(value="/",consumes = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity createNewPerson(@RequestBody PersonDTO personDTO) throws Exception{ PersonDTO savedPersonDTO = personService.createNewPerson(personDTO); return new ResponseEntity(savedPersonDTO,HttpStatus.CREATED); } } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++