package eu.dnetlib.is.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import eu.dnetlib.data.is.resource.model.ResourceType;
import eu.dnetlib.data.is.resource.repository.ResourceTypeRepository;

@RestController
public class MainAjaxController {

	@Autowired
	private ResourceTypeRepository resourceTypeRepository;

	@GetMapping("/ajax/resourceTypes")
	public Iterable<ResourceType> resourceTypes() {
		return resourceTypeRepository.findAll();
	}

	@GetMapping("/ajax/resourceTypes/{id}")
	public ResourceType resourceTypes(@PathVariable final String id) {
		return resourceTypeRepository
			.findById(id)
			.orElse(new ResourceType("not_present", "???", MediaType.TEXT_PLAIN_VALUE, 0));
	}

}
