Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
package com.codility.app;

import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UsersController {
    private final UsersService usersService;

    @Autowired
    public UsersController(UsersService usersService) {
        this.usersService = usersService;
    }

    @GetMapping("/users/{username}/items/total")
    @ResponseBody
    public Map<String, Integer> totalItemsBought(@PathVariable String username) {
        int totalItemsBought = usersService.getNumberOfItemsBought(username);
        Map<String, Integer> response = new HashMap<>();
        response.put("totalItemsBought", totalItemsBought);
        return response;
    }
}