31 lines
902 B
C#
31 lines
902 B
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Website.Data;
|
|
using Website.ViewModels;
|
|
using System.Linq;
|
|
|
|
namespace Website.Controllers {
|
|
public class HomeController : Controller {
|
|
private readonly BlogRepository _blogRepo;
|
|
private readonly GitServerApi _api;
|
|
|
|
public HomeController(BlogRepository blogRepo, GitServerApi api) {
|
|
_api = api;
|
|
_blogRepo = blogRepo;
|
|
}
|
|
|
|
public async Task<IActionResult> Index() {
|
|
var post = await _blogRepo.GetLatestPostAsync();
|
|
var repo = (await _api.GetRepositories()).First();
|
|
var branch = (await _api.GetBranches(repo.Name)).First();
|
|
var commit = await _api.GetCommit(repo.Name, branch.Commit.Id);
|
|
|
|
var model = new HomeViewModel {
|
|
BlogPost = new BlogPostViewModel(post, false),
|
|
GitCommit = new GitCommitViewModel(repo, branch, commit)
|
|
};
|
|
|
|
return View(model);
|
|
}
|
|
}
|
|
}
|