UserRestController.java 1.34 KB
package fr.plil.sio.web.mvc;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
public class UserRestController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/api/users/", method = RequestMethod.GET)
    public List<User> listUsers() {
        return userService.findAll();
    }

    @RequestMapping(value = "/api/users/{username}/", method = RequestMethod.GET)
    public User listUsers(@PathVariable String username) {
        return userService.findByUsername(username);
    }

    @RequestMapping(value = "/api/debts/{username}/", method = RequestMethod.GET)
    public List<Dette> listDettes(@PathVariable String username) {
        return userService.findDettesByUsername(username);
    }

    @RequestMapping(value = "/api/addDette/", method = RequestMethod.POST)
    public boolean addDette(@RequestParam(value="username",required=false) String username,@RequestParam(value="sommeDette",required=false) String sommeDette) {
        return userService.addDette(username,sommeDette);
    }

}