Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 itemsBoughtString username;
Requirements:
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 beanplease 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.
Inject UserService into UsersController
Use it in the totalItemsBought method to fetch the number of items bought by the given user.
The totalItemsBought method should implements the following contract
endpoint URL: usersusernameitemstotalwhere username is a path variable;
response JSON format:
totalItemsBought:numberwhere number is the number of items bought by the given user,
status code in case of a successful response
Make sure you pass the username variable to the totalItemsBought call.
For simplicity,you don't have write any input validation or error handling
you are working with the spring Framework version and java
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 getNumberOfItemsBoughtString username
return ;
package com.codility.external;
public class OrderService
List itemsBoughtString 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started