#17 - Redirect to filtering

This commit is contained in:
Anton Romanov 2021-03-31 13:25:33 +04:00
parent ec209e8fe8
commit bbdfb91b1d
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.extractor.repository.BranchRepository;
import ru.ulstu.extractor.repository.RepositoryRepository;
@Controller
public class BranchController {
private final RepositoryRepository repositoryRepository;
private final BranchRepository branchRepository;
public BranchController(RepositoryRepository repositoryRepository, BranchRepository branchRepository) {
this.repositoryRepository = repositoryRepository;
this.branchRepository = branchRepository;
}
@GetMapping("/details")
public String indexBranch(
Model model,
@RequestParam int repositoryId) {
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
model.addAttribute("repository", repositoryRepository.findById(repositoryId).get());
return "indexBranch";
}
}

View File

@ -4,6 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import ru.ulstu.extractor.model.Branch;
import ru.ulstu.extractor.model.Repository;
import java.util.List;
public interface BranchRepository extends JpaRepository<Branch, Integer> {
Branch findByRepositoryAndName(Repository repository, String name);
List<Branch> findByRepositoryId(Integer repositoryId);
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Проиндексированные репозитории</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">Ветки</th>
</tr>
</thead>
<tbody>
<tr th:each="branch: ${branches}">
<td><a th:href="@{'/filtering?branchName='+${branch.name}+'&repositoryUrl='+${repository.url}}"
th:text="${branch.name}"/></td>
</tr>
</tbody>
</table>
</div>
</html>