package org.codiki.versionrevisions;

import org.codiki.core.entities.persistence.Version;
import org.codiki.core.entities.persistence.VersionRevision;
import org.codiki.core.repositories.VersionRepository;
import org.codiki.core.repositories.VersionRevisionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/versionrevisions")
public class VersionRevisionController {
	private final VersionRevisionRepository repository;
	private final VersionRepository versionRepository;

	public VersionRevisionController(VersionRevisionRepository repository,
									 VersionRepository versionRepository) {
		this.repository = repository;
		this.versionRepository = versionRepository;
	}

	@GetMapping("/versions")
	public Iterable<Version> getVersions() {
		return versionRepository.findAllOrderByNumber();
	}
	
	@GetMapping("/{versionNumber}")
	public Iterable<VersionRevision> getVersionRevisionByVersionNumber(
			@PathVariable("versionNumber") final String pVersionNumber) {
		return repository.findByVersionNumber(pVersionNumber);
	}
}
