Question: please give me the full code You are writing an endpoint that returns the total number of Items bought in your Online store by a

please give me the full code You are writing an endpoint that returns the total number of Items bought in your Online store by a given user.
Orders in your system are stored in an external service called OrdersService.
Your task is to:
.write an endpoint in the given UsersController class
. write a method in the given UserService class that counts the number of items bought by the given user.
.configure the UsersController and UserService classes
Environment
Your application is written with the Spring framework
public class OrderService {
List itemsBought(String username);
}
Requirements:
1. Make sure that the AppConfiguration class is treated as a Spring configuration bean.
2.Configure Spring to Scan for beans in the com.codility.external package.
3.prepare the OrdersService bean(please refer to the signatures decribed above)
.Inject the OrdersService bean into the ordersService field
.Use it in the getNumberOfItemsBought() method count the number of items bought by the given user.
4.Inject UserService into UsersController
5.Use it in the totalItemsBought() method to fetch the number of items bought by the given user.
6.The totalItemsBought() method should implements the following contract
.endpoint URL: /users/{username}/items/total,where username is a path variable;
.response JSON format:
{"totalItemsBought":number},where number is the number of items bought by the given user,
status code 200 in case of a successful response
7.Make sure you pass the username variable to the totalItemsBought call.
8.For simplicity,you don't have write any input validation or error handling
9. you are working with the spring Framework version 5.1.7 and java8
-------
package com.codility.app;
import org.springframework.context.annotation.*;
public class AppConfiguration {
}
-----
package com.codility.app;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Collections;
public class UserController {
private UsersService usersService;
public Map totalItemsBought()
{return null;}}
-------
package com.codility.app;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
public class UsersService {
private OrderService ordersService;
public int getNumberOfItemsBought(String username)
{return 0;}
}
------
package com.codility.external;
public class OrderService {
List itemsBought(String username);
}Make sure that the AppConfiguration class is treated
as a Spring configuration bean.
Configure Spring to scan for beans in the
com.codility. external package.
Prepare the OrdersService bean (please refer to the
signatures described above):
Inject the Ordersservice bean into the
ordersService field.
Use it in the getNumberofItemsBought method to
count the number of items bought by the given user.
Inject UsersService into UsersController.
requireIItIIs
 please give me the full code You are writing an endpoint

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!