‫Hi, welcome back. In the previous lecture, we have written a JUnit to test update employee rest API.
‫In this lecture, we are going to build delete employee REST API and in the next lecture,
‫we're going to unit test delete Employee Rest API.
‫Let's head over to EmployeeController
‫and within a EmployeeController,
‫we're going to build delete employee REST API.
‫Well, let's go and let's write the method over here.
‫public and the return of the method is a ResponseEntity and we gonna
‫pass String as a type. Let's give the method name as deleteEmployee and let's pass the method argument as
‫employee id
‫All right.
‫Let's annotate this method with @DeleteMapping annotation and let's pass the id as
‫a part variable.
‫Now we want to bind the value of this
‫URI template variable to this employee id right so in order to do that
‫let's go ahead and let's use @PathVariable annotation and then pass id. Now within a delete employee method,
‫we're going to write a logic to delete the employee. Well, let's go ahead and call the employeeService object
‫it has a delete employee method.
‫Look at here,
‫delete employee method returns void and it expects id as a method argument.
‫OK, so look here delete employee returns void here.
‫All right.
‫So go ahead and just pass the employeeId to it.
‫Now, once the employee object is deleted successfully, then REST API should return the response
‫to the client right.
‫In order to do that, let's have a response object over here. Return new and the response object should
‫be a response entity.
‫And this should be a type string because in response you can see we have passed String as
‫you know, generic type.
‫Let's have a message something like employee deleted successfully.
‫Something like that.
‫Successfully, and if the employee deleted successfully, then we should return to the status code
‫200
‫So just call HTTP status and then OK, perfect.
‫Well, what we have done, we have created a deleteEmployee method and within a deleteEmployee method,
‫we have called the employeeService.deleteEmployee method which delete the employee object from the
‫database by using employeId.
‫And then we have returned a response like employee deleted successfully with a status code
‫200.
‫All right.
‫In the next lecture, we're going to write a JUnit test case to test this delete employee REST API.
‫All right.
‫I will see you in a next lecture.