Hi guys, in this lesson we will create user controls. Like we said in previous lesson. In spring, there is a cycle in Model View control structures. First of all this guide model classes later call model classes from services finally call services from controllers and controllers, we will return other classes. In previous lesson, we describe our user service. In this lesson, we will call it from controllers, and we will map our REST API requests.
So do it. First of all, we will create controller class. First of all, let's create a new package under our main package. Our package name will be controls. Under controller package, we will create user code ruling class to define user controllers as rest controller class, we will add rest controller annotation to it. Later we will call user serves two dependency injection we can use auto wired in spring.
Okay, now we can create our API methods, our first method will be registered. In rest controllers, we will define every method with response entity capsulation response entity is a capsulation that contains HTTP headers, HTTP status and response body. For our register method, we will reach form data of request with using request body annotation. Our mapping request of methods will be post mapping and API path will be like service registration. In registration username should be unique for each user. So we should check it.
Whether username is exists or not. If username is already exist, we will return conflict as such Otherwise default role losses will be used. And finally, we will call our users hate method from user service and return created HTTP status. Are seconds methods VOB get user method with using security principle. In client side we can send authorization token value with request headers. And in sibling we can get this authorization video with using security principle security principle We'll get this encrypted authorization token.
Then with using spring security, it will provide an authorized credentials. Our get user method will be GET request method and API path will be service logging. In this method, first of all we shall check principle is now or not If it is not now, we will return user entity as response. And finally, we call our user find by username method from user service. are other methods VOB get user name list according to ID list. This method will be a POST request.
So as parameter we will get idealist as request body. And we will return find users from user service and API path VOB service names Last methods will be test. We will use it for test our service API pass VOB service test. Okay, that's all about user controller implementation. Thank you.