Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions