package eu.dnetlib.statsapi.controllers;

import eu.dnetlib.statsapi.domain.Result;
import eu.dnetlib.statsapi.repositories.FunderRepository;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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;

@RestController
@CrossOrigin(methods = RequestMethod.GET, origins = "*")
public class FunderController {

    @Autowired
    private FunderRepository funderRepository;

    private final Logger log = Logger.getLogger(this.getClass());

    @RequestMapping(value = "/funders/{funder}")
    public Result getFunder(@PathVariable(value = "funder") String funder) {
        log.info("request for funder: " + funder);
        return funderRepository.getFunder(funder);
    }
}
