красиво отображаются категории

This commit is contained in:
Елена Бакальская 2024-06-04 13:45:30 +04:00
parent ae35a740cc
commit f1101c99d0
5 changed files with 23 additions and 83 deletions

View File

@ -44,6 +44,9 @@ public class BackendApplication implements CommandLineRunner {
final var u7 = new UserEntity(null, "7", "1234");
final var cat1 = new CategorieEntity(null, "Драма", null);
final var cat2 = new CategorieEntity(null, "Комедия", null);
final var cat3 = new CategorieEntity(null, "Хоррор", null);
final var cat4 = new CategorieEntity(null, "Мультитк", null);
admin.setRole(UserRole.ADMIN);
vasya.setRole(UserRole.USER);
@ -67,6 +70,9 @@ public class BackendApplication implements CommandLineRunner {
userService.create(u7);
categorieService.create(cat1);
categorieService.create(cat2);
categorieService.create(cat3);
categorieService.create(cat4);
_logger.info("Admin user added");
}

View File

@ -84,7 +84,7 @@ public class CategorieController {
if (!imageFile.isEmpty()) {
Path fileNameAndPath = Paths.get(UPLOAD_DIR, imageFile.getOriginalFilename());
Files.write(fileNameAndPath, imageFile.getBytes());
category.setImage("/uploads/" + imageFile.getOriginalFilename());
// category.setImage("/uploads/" + imageFile.getOriginalFilename());
}
categorieService.create(category);
} catch (IOException e) {

View File

@ -7,92 +7,24 @@
<body>
<main layout:fragment="content">
<form action="/admin/categories/edit/" method="post" enctype="multipart/form-data">
<!-- <div class="form-group">
<label for="name">Название:</label>
<input type="text" id="name" name="name" class="form-control" required>
</div>
<div class="form-group">
<label for="image">Картинка:</label>
<input type="file" id="image" name="image" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Сохранить</button> -->
<!-- <div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:field="*{id}" id="id" class="form-control" readonly disabled>
</div> -->
<div class="mb-3">
<label for="name">Название</label>
<input type="text" class="form-control" id="name" th:field="*{name}" required />
</div>
<div class="mb-3">
<label for="image">Выбрать фотографию</label>
<input type="file" class="form-control" id="image" name="image" required />
</div>
<button type="submit" class="btn btn-primary">Сохранить</button>
</form>
</main>
</body>
</html>
<!--
<body>
<main layout:fragment="content">
<div class="container">
<h2>Create Category</h2>
<form action="#" th:action="@{/admin/categories/edit/{id}(id=${categorie.id})}" th:object="${categorie}"
method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" th:field="*{id}" id="id" class="form-control" readonly disabled>
</div>
<div class="mb-3">
<label for="name">Название</label>
<input type="text" class="form-control" id="name" th:field="*{name}" required />
</div>
<div class="mb-3">
<label for="image">Select Image</label>
<input type="file" class="form-control" id="image" name="image" required />
</div>
<button type="submit" class="btn btn-primary">Сохранить</button>
<!-- </form> -->
<div>
<a th:href="@{/admin/categories}">Вернуться на категории</a>
</div>
<!--
<form action="#" th:action="@{/admin/categories/edit/{id}(id=${categorie.id})}" th:object="${categorie}"
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">
<label for="password" class="form-label">Пароль</label>
<input type="text" th:field="*{password}" id="password" class="form-control">
<div th:if="${#fields.hasErrors('password')}" th:errors="*{password}" class="invalid-feedback"></div>
<label for="name" class="form-label">Имя пользователя</label>
<input type="text" th:field="*{name}" id="login" class="form-control">
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" 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>
</div>
</main>
<a class="btn btn-secondary button-fixed-width" th:href="@{/admin/categories}">Отмена</a>
</div>
</form>
</main>
</body>
</html> -->
</html>

View File

@ -28,10 +28,12 @@
<th:block th:switch="${categories.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<div class="categories-container">
<div class="category-item" th:each="categorie : ${categories}">
<div class="card">
<img class="card-img-top" th:src="@{${categorie.image}}" th:alt="${categorie.name}" />
<div class="categories-container d-flex flex-row justify-content-center mt-3">
<div class="category-item d-flex flex-column justify-content-center align-items-center mb-5 mb-md-0"
th:each="categorie : ${categories}">
<div class="category-card">
<img class="card-img-top rounded-3"
src="https://live.funnelmates.com/wp-content/uploads/2021/08/placeholder-200x200-1-1-1.jpeg" />
<div class="card-body">
<h5 class="card-title" th:text="${categorie.name}"></h5>
</div>

Binary file not shown.