package eu.dnetlib.repo.manager.controllers;

import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.service.DashboardService;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/dashboard")
@Api(description = "Dashboard API",  tags = {"dashboard"})
public class DashboardController {

    @Autowired
    DashboardService dashboardService;

    @RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @PreAuthorize("hasRole('ROLE_USER')")
    public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
                                                                  @PathVariable("page") String page,
                                                                  @PathVariable("size") String size) throws JSONException {
        return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size);
    }
}
