diff --git a/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java b/src/main/java/ru/ulstu/extractor/mvc/GitFilteringController.java similarity index 64% rename from src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java rename to src/main/java/ru/ulstu/extractor/mvc/GitFilteringController.java index 463c468..53320f5 100644 --- a/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java +++ b/src/main/java/ru/ulstu/extractor/mvc/GitFilteringController.java @@ -5,17 +5,13 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import ru.ulstu.extractor.model.Branch; import ru.ulstu.extractor.model.Commit; import ru.ulstu.extractor.mvc.model.FilterForm; -import ru.ulstu.extractor.mvc.model.RepoForm; import ru.ulstu.extractor.service.CommitService; import ru.ulstu.extractor.service.FilteringService; import ru.ulstu.extractor.service.GitRepositoryService; @@ -27,12 +23,12 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; @Controller -public class GitExtractorController { +public class GitFilteringController { private final FilteringService filteringService; private final GitRepositoryService gitRepositoryService; private final CommitService commitService; - public GitExtractorController(FilteringService filteringService, + public GitFilteringController(FilteringService filteringService, GitRepositoryService gitRepositoryService, CommitService commitService) { this.filteringService = filteringService; @@ -40,12 +36,6 @@ public class GitExtractorController { this.commitService = commitService; } - @GetMapping("/newRepo") - public String indexNewRepo(Model model) { - model.addAttribute("repoForm", new RepoForm()); - return "newRepo"; - } - @PostMapping("/sendFilter") public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) throws GitAPIException, IOException { List list = gitRepositoryService.getCommits(filterForm.getUrl()); @@ -57,31 +47,6 @@ public class GitExtractorController { return "resultRepo"; } - @RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send") - public String getBranch(@ModelAttribute RepoForm repoForm, Model model) { - try { - gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo()); - List list = gitRepositoryService.getBranches(repoForm.getRepo()); - model.addAttribute("branches", list); - return "newRepo"; - } catch (Exception ex) { - model.addAttribute("error", ex.getMessage()); - return "newRepo"; - } - } - - @RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next") - public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) { - model.addAttribute("filterForm", new FilterForm(repoForm.getRepo())); - if (repoForm.getBranch() == null) { - return "newRepo"; - } else { - redirectAttributes.addAttribute("url", repoForm.getRepo()); - redirectAttributes.addAttribute("branch", repoForm.getBranch()); - return "redirect:/filtering"; - } - } - @RequestMapping(value = "/filtering", method = RequestMethod.GET) public String listCommits( Model model, diff --git a/src/main/java/ru/ulstu/extractor/mvc/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/mvc/GitIndexingController.java new file mode 100644 index 0000000..bfd61f6 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/GitIndexingController.java @@ -0,0 +1,55 @@ +package ru.ulstu.extractor.mvc; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import ru.ulstu.extractor.model.Branch; +import ru.ulstu.extractor.mvc.model.FilterForm; +import ru.ulstu.extractor.mvc.model.RepoForm; +import ru.ulstu.extractor.service.GitRepositoryService; + +import java.util.List; + +@Controller +public class GitIndexingController { + private final GitRepositoryService gitRepositoryService; + + public GitIndexingController(GitRepositoryService gitRepositoryService) { + this.gitRepositoryService = gitRepositoryService; + } + + @GetMapping("/newRepo") + public String indexNewRepo(Model model) { + model.addAttribute(new RepoForm()); + return "newRepo"; + } + + @RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "send") + public String getBranch(@ModelAttribute RepoForm repoForm, Model model) { + try { + gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo()); + List branches = gitRepositoryService.getBranches(repoForm.getRepo()); + model.addAttribute("branches", branches); + return "newRepo"; + } catch (Exception ex) { + model.addAttribute("error", ex.getMessage()); + return "newRepo"; + } + } + + @RequestMapping(value = "/newRepo", method = RequestMethod.POST, params = "next") + public String setBranch(@ModelAttribute RepoForm repoForm, Model model, RedirectAttributes redirectAttributes) { + model.addAttribute("filterForm", new FilterForm(repoForm.getRepo())); + if (repoForm.getBranch() == null) { + return "newRepo"; + } else { + redirectAttributes.addAttribute("url", repoForm.getRepo()); + redirectAttributes.addAttribute("branch", repoForm.getBranch()); + return "redirect:/filtering"; + } + } +} diff --git a/src/main/java/ru/ulstu/extractor/service/CommitService.java b/src/main/java/ru/ulstu/extractor/service/CommitService.java index 4f7b143..05ec123 100644 --- a/src/main/java/ru/ulstu/extractor/service/CommitService.java +++ b/src/main/java/ru/ulstu/extractor/service/CommitService.java @@ -25,7 +25,6 @@ public class CommitService { int currentPage = pageable.getPageNumber(); int startItem = currentPage * pageSize; List commits = gitRepositoryService.getCommits(url); - ; if (commits.size() < startItem) { commits = Collections.emptyList(); diff --git a/src/main/resources/templates/filtering.html b/src/main/resources/templates/filtering.html index 88676d5..8a8bca1 100644 --- a/src/main/resources/templates/filtering.html +++ b/src/main/resources/templates/filtering.html @@ -29,12 +29,12 @@

- - +
+ - - - + + +
AuthorDateCommitAuthorDateCommit