Это немного, но это честная работа

This commit is contained in:
gg12 darfren 2024-05-21 14:10:17 +04:00
parent e044259d46
commit 17f70e4061
12 changed files with 188 additions and 25 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -9,6 +9,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.example.demo.users.model.UserEntity; import com.example.demo.users.model.UserEntity;
import com.example.demo.users.model.UserRole;
import com.example.demo.users.service.UserService; import com.example.demo.users.service.UserService;
import com.example.demo.groups.model.GroupEntity; import com.example.demo.groups.model.GroupEntity;
import com.example.demo.groups.service.GroupService; import com.example.demo.groups.service.GroupService;
@ -41,6 +42,9 @@ public class DemoApplication implements CommandLineRunner {
final var user1 = userService.create(new UserEntity("Oleja123", "1234")); final var user1 = userService.create(new UserEntity("Oleja123", "1234"));
final var user2 = userService.create(new UserEntity("Vk1d2004", "4321")); final var user2 = userService.create(new UserEntity("Vk1d2004", "4321"));
final var admin = new UserEntity("admin", "admin");
admin.setRole(UserRole.ADMIN);
userService.create(admin);
log.info("Create default groups values"); log.info("Create default groups values");

View File

@ -72,8 +72,12 @@ public class MemberController {
} }
@GetMapping("/getmemberstopgroup") @GetMapping("/getmemberstopgroup")
public String getMembersTopGroup(@RequestParam(name = "group", defaultValue = "0") Long groupId, Model model) { public String getMembersTopGroup(@PathVariable(name = "group") Long groupId, Model model) {
model.addAttribute(MEMBERS_TOP_ATTRIBUTE, memberService.getMembersTopGroup(5, groupId).stream().map(this::toDto).toList()); List<MemberDto> lst = memberService.getMembersTopGroup(5, groupId).stream().map(this::toDto).toList();
final Map<String, Object> attributes = PageAttributesMapper.toAttributes(
memberService.getMembersTopGroup(5, groupId), this::toDto);
model.addAllAttributes(attributes);
model.addAttribute(GROUP_ATTRIBUTE, groupId);
return MEMBERS_TOP_VIEW; return MEMBERS_TOP_VIEW;
} }
@GetMapping @GetMapping

View File

@ -56,9 +56,9 @@ public class MemberService {
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<MemberEntity> getMembersTopGroup(int top, long groupId) { public Page<MemberEntity> getMembersTopGroup(int top, long groupId) {
final Pageable pageRequest = PageRequest.of(0, top); final Pageable pageRequest = PageRequest.of(0, top);
return repository.getMembersTopGroup(groupId, pageRequest).getContent(); return repository.getMembersTopGroup(groupId, pageRequest);
} }

View File

@ -1,15 +1,10 @@
<?xml version="1.0" standalone="no"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="74px" height="58px" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" <g><path style="opacity:1" fill="#fefdfd" d="M -0.5,-0.5 C 24.1667,-0.5 48.8333,-0.5 73.5,-0.5C 73.5,18.8333 73.5,38.1667 73.5,57.5C 48.8333,57.5 24.1667,57.5 -0.5,57.5C -0.5,38.1667 -0.5,18.8333 -0.5,-0.5 Z"/></g>
width="74.000000pt" height="58.000000pt" viewBox="0 0 74.000000 58.000000" <g><path style="opacity:1" fill="#389cd4" d="M 45.5,42.5 C 45.5,36.5 45.5,30.5 45.5,24.5C 41.5,24.8333 37.5,25.1667 33.5,25.5C 33.5,31.5 33.5,37.5 33.5,43.5C 32.3403,31.6738 32.1737,19.6738 33,7.5C 36.1831,5.47659 39.6831,4.97659 43.5,6C 44.3333,6.83333 45.1667,7.66667 46,8.5C 46.8259,20.0076 46.6593,31.3409 45.5,42.5 Z"/></g>
preserveAspectRatio="xMidYMid meet"> <g><path style="opacity:1" fill="#fbd674" d="M 27.5,31.5 C 26.596,30.791 26.2627,29.791 26.5,28.5C 22.5,28.5 18.5,28.5 14.5,28.5C 14.5,33.1667 14.5,37.8333 14.5,42.5C 13.3443,35.0113 13.1777,27.3446 14,19.5C 18.0019,15.8775 22.3353,15.5442 27,18.5C 27.499,22.8206 27.6657,27.1539 27.5,31.5 Z"/></g>
<g><path style="opacity:1" fill="#b72227" d="M 52.5,21.5 C 56.4367,21.2065 60.27,21.5399 64,22.5C 64.8123,29.7471 64.6456,36.9138 63.5,44C 59.577,44.7927 55.7436,44.626 52,43.5C 51.2036,36.0869 51.3703,28.7535 52.5,21.5 Z"/></g>
<g transform="translate(0.000000,58.000000) scale(0.100000,-0.100000)" <g><path style="opacity:1" fill="#1a83c4" d="M 45.5,42.5 C 44.1262,44.9588 41.9595,45.9588 39,45.5C 37.5,45.3333 36,45.1667 34.5,45C 33.944,44.6174 33.6107,44.1174 33.5,43.5C 33.5,37.5 33.5,31.5 33.5,25.5C 37.5,25.1667 41.5,24.8333 45.5,24.5C 45.5,30.5 45.5,36.5 45.5,42.5 Z"/></g>
fill="#000000" stroke="none"> <g><path style="opacity:1" fill="#f6c843" d="M 27.5,31.5 C 30.3443,42.4874 26.3443,46.6541 15.5,44C 14.944,43.6174 14.6107,43.1174 14.5,42.5C 14.5,37.8333 14.5,33.1667 14.5,28.5C 18.5,28.5 22.5,28.5 26.5,28.5C 26.2627,29.791 26.596,30.791 27.5,31.5 Z"/></g>
<path d="M415 373 c-81 -10 -76 -1 -73 -126 l3 -112 55 0 55 0 3 123 c1 67 -1
121 -5 121 -4 -1 -21 -4 -38 -6z"/>
<path d="M525 338 c-3 -13 -5 -63 -3 -113 l3 -90 48 -3 c27 -2 55 2 63 9 18
15 20 189 2 207 -7 7 -34 12 -60 12 -41 0 -48 -3 -53 -22z"/>
</g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Ошибка</title>
</head>
<body>
<main layout:fragment="content">
<ul class="list-group mb-2">
<th:block th:if="${#strings.isEmpty(message)}">
<li class="list-group-item">
Неизвестная ошибка
</li>
</th:block>
<th:block th:if="${not #strings.isEmpty(message)}">
<li class="list-group-item">
<strong>Ошибка:</strong> [[${message}]]
</li>
</th:block>
<th:block th:if="${not #strings.isEmpty(url)}">
<li class="list-group-item">
<strong>Адрес:</strong> [[${url}]]
</li>
<li class="list-group-item">
<strong>Класс исключения:</strong> [[${exception}]]
</li>
<li class="list-group-item">
[[${method}]] ([[${file}]]:[[${line}]])
</li>
</th:block>
</ul>
<a class="btn btn-primary button-fixed-width" href="/">На главную</a>
</main>
</body>
</html>

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Лучшие ученики группы</title>
</head>
<body>
<main layout:fragment="content">
<h2>Лучшие ученики группы</h2>
<th:block th:switch="${items.size()}">
<div>
<a th:href="@{/{groupid}/members(groupid=${group})}" class="btn btn-primary">Назад</a>
</div>
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<table class="table">
<caption></caption>
<thead>
<tr>
<th scope="col" class="w-8">ID</th>
<th scope="col" class="w-19">Имя участника</th>
<th scope="col" class="w-19">Хэндл</th>
<th scope="col" class="w-19">Рейтинг</th>
<th scope="col" class="w-19">Звание</th>
</tr>
</thead>
<tbody>
<tr th:each="member : ${items}">
<th scope="row" th:text="${member.id}"></th>
<td th:text="${member.name}"></td>
<td th:text="${member.handle}"></td>
<td th:text="${member.rating}"></td>
<td th:text="${member.rank}"></td>
</tr>
</tbody>
</table>
</th:block>
</main>
</body>
</html>

View File

@ -8,6 +8,9 @@
<body> <body>
<main layout:fragment="content"> <main layout:fragment="content">
<h2>Участники группы</h2> <h2>Участники группы</h2>
<div>
<a th:href="@{/{groupid}/members/getmemberstopgroup(groupid=${group})}" class="btn btn-primary">Лучшие ученики группы</a>
</div>
<div> <div>
<a th:href="@{/{groupid}/members/edit(groupid=${group})}" class="btn btn-primary">Добавить участника</a> <a th:href="@{/{groupid}/members/edit(groupid=${group})}" class="btn btn-primary">Добавить участника</a>
</div> </div>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Редакторовать пользователя</title>
</head>
<body>
<main layout:fragment="content">
<form action="#" th:action="@{/admin/user/edit/{id}(id=${user.id},page=${page})}" th:object="${user}"
method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
</div>
<div class="mb-3">
<label for="login" class="form-label">Имя пользователя</label>
<input type="text" th:field="*{login}" id="login" class="form-control">
<div th:if="${#fields.hasErrors('login')}" th:errors="*{login}" class="invalid-feedback"></div>
</div>
<div class="mb-3 d-flex flex-row">
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" th:href="@{/admin/user(page=${page})}">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Пользователи</title>
</head>
<body>
<main layout:fragment="content">
<th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<h2>Пользователи</h2>
<div>
<a th:href="@{/admin/user/edit/(page=${page})}" class="btn btn-primary">Добавить пользователя</a>
</div>
<table class="table">
<caption></caption>
<thead>
<tr>
<th scope="col" class="w-10">ID</th>
<th scope="col" class="w-auto">Имя пользователя</th>
<th scope="col" class="w-10"></th>
<th scope="col" class="w-10"></th>
</tr>
</thead>
<tbody>
<tr th:each="user : ${items}">
<th scope="row" th:text="${user.id}"></th>
<td th:text="${user.login}"></td>
<td>
<form th:action="@{/admin/user/edit/{id}(id=${user.id})}" method="get">
<input type="hidden" th:name="page" th:value="${page}">
<button type="submit" class="btn btn-link button-link">Редактировать</button>
</form>
</td>
<td>
<form th:action="@{/admin/user/delete/{id}(id=${user.id})}" method="post">
<input type="hidden" th:name="page" th:value="${page}">
<button type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">Удалить</button>
</form>
</td>
</tr>
</tbody>
</table>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'admin/user'},
totalPages=${totalPages},
currentPage=${currentPage}) }" />
</th:block>
</main>
</body>
</html>