готово

This commit is contained in:
Milana Ievlewa 2024-05-23 17:04:39 +04:00
parent 68f1e0b0f8
commit 6903dc353b
34 changed files with 7018 additions and 434 deletions

View File

@ -28,11 +28,11 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.modelmapper:modelmapper:3.2.0'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.modelmapper:modelmapper:3.2.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.2.224'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2:2.2.224'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
@ -43,7 +43,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ public class DemoApplication implements CommandLineRunner {
2500.33,
30,
place1,
"https://sun9-78.userapi.com/impg/GqEhiQUHIxaQgbsA0xEL3LFSQDihGD_PCWrQiQ/-DaQ2XoijZE.jpg?size=500x600&quality=96&sign=0eb5cbb4139b47c00287dceacc1aa4c1&type=album"));
null));
final var ivent2 = iventService.create(new IventEntity(
"Placebo",
@ -80,7 +80,7 @@ public class DemoApplication implements CommandLineRunner {
2500.33,
30,
place2,
"https://sun9-32.userapi.com/impg/2pvZuqVQH4hOX2pDuR7G9VMA8d-yVoEkgeYtGQ/YUHaozp5U18.jpg?size=564x798&quality=96&sign=e60e12e163aa46f084f28cc6ce5487c5&type=album"));
null));
iventService.create(new IventEntity(
"Radiohead",
@ -91,7 +91,7 @@ public class DemoApplication implements CommandLineRunner {
2500.33,
30,
place3,
"https://sun7-21.userapi.com/impg/C5aKzJPvxULBB_CuWMgXIG6uj5AuB2qKlBVDxA/NR1B43MGKVs.jpg?size=500x629&quality=96&sign=ff85339d4ff11424738fe9d58c0b2d23&type=album"));
null));
iventService.create(new IventEntity(
"Сияние",
@ -102,7 +102,7 @@ public class DemoApplication implements CommandLineRunner {
2500.33,
45,
place3,
"https://sun9-3.userapi.com/impg/9oGzwF1Xx2OZmN_xzFGUo2AewBbuo2y2QYskTw/4euSR1gwhmE.jpg?size=556x832&quality=96&sign=d6e480044eedf3a0e0c24f16ad7473f7&type=album"));
null));
iventService.create(new IventEntity(
"Мастер и Маргарита",
@ -113,7 +113,7 @@ public class DemoApplication implements CommandLineRunner {
2500.33,
30,
place2,
"https://sun9-47.userapi.com/impg/AH0Cg6gGvoiKg324O8g4fipjZnNKf2SWg-oEUg/0L9VzH-6sGw.jpg?size=563x713&quality=96&sign=1b53e1cc0c69b3b09f6af2a5257757e7&type=album"));
null));
log.info("Create default users values");
final var admin = new UserEntity("Admin", "Admin@gmail.com", "admin");

View File

@ -1,7 +1,6 @@
package com.example.demo.cartItems.api;
import java.util.Objects;
import java.time.LocalDate;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
@ -17,12 +16,7 @@ public class CartItemDto {
@Min(1)
private Integer quantity;
@NotNull
private String iventName;
@NotNull
private LocalDate iventDate;
@NotNull
@Min(1)
private Double iventPrice;
public Long getId() {
@ -57,14 +51,6 @@ public class CartItemDto {
this.iventName = name;
}
public LocalDate getIventDate() {
return iventDate;
}
public void setIventDate(LocalDate date) {
this.iventDate = date;
}
public Double getIventPrice() {
return iventPrice;
}
@ -87,4 +73,4 @@ public class CartItemDto {
CartItemDto other = (CartItemDto) obj;
return Objects.equals(iventId, other.iventId) && Objects.equals(quantity, other.quantity);
}
}
}

View File

@ -18,6 +18,7 @@ import com.example.demo.core.configuration.Constants;
import com.example.demo.core.security.UserPrincipal;
import com.example.demo.core.session.SessionCart;
import com.example.demo.ivents.api.ExpandedIventDto;
import com.example.demo.ivents.api.IventDto;
import com.example.demo.ivents.model.IventEntity;
import com.example.demo.ivents.service.IventService;
@ -45,6 +46,14 @@ public class CatalogController {
return dto;
}
protected IventDto toDto(IventEntity entity) {
ExpandedIventDto dto = modelMapper.map(entity, ExpandedIventDto.class);
dto.setTypeName(entity.getType().getName());
final var isCartIvent = cart.containsKey(Objects.hash(dto.getId()));
dto.setIsCartIvent(isCartIvent);
return dto;
}
@GetMapping("/catalog")
public String getAll(
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
@ -52,10 +61,18 @@ public class CatalogController {
@AuthenticationPrincipal UserPrincipal principal) {
final Map<String, Object> attributes = PageAttributesMapper.toAttributes(
iventService.getAll(0L, 0L, null, null, page, Constants.DEFAULT_PAGE_SIZE),
item -> toExpandedDto(item, principal.getId()));
item -> {
if(principal != null) {
return toExpandedDto(item, principal.getId());
} else {
// Handle the case when the user is not authenticated
return toDto(item);
}
}
);
model.addAllAttributes(attributes);
model.addAttribute(PAGE_ATTRIBUTE, page);
return PRODUCTS_VIEW;
}
@ -85,7 +102,6 @@ public class CatalogController {
cartItem.setIventId(iventId);
cartItem.setQuantity(1);
cartItem.setIventName(ivent.getName());
cartItem.setIventDate(ivent.getDate());
cartItem.setIventPrice(ivent.getPrice());
cart.putIfAbsent(cartItem.hashCode(), cartItem);

View File

@ -21,33 +21,32 @@ import com.example.demo.users.model.UserRole;
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.headers(headers -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
httpSecurity.csrf(AbstractHttpConfigurer::disable);
httpSecurity.cors(Customizer.withDefaults());
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.headers(headers -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
httpSecurity.csrf(AbstractHttpConfigurer::disable);
httpSecurity.cors(Customizer.withDefaults());
httpSecurity.authorizeHttpRequests(requests -> requests
.requestMatchers("/css/**", "/webjars/**", "/*.svg")
.permitAll());
httpSecurity.authorizeHttpRequests(requests -> requests
.requestMatchers("/css/**", "/webjars/**", "/*.svg", "/*.jpg").permitAll()
.requestMatchers("/public/**").permitAll()
.requestMatchers(Constants.ADMIN_PREFIX + "/**").hasRole(UserRole.ADMIN.name())
.requestMatchers("/h2-console/**").hasRole(UserRole.ADMIN.name())
.requestMatchers(UserSignupController.URL).anonymous()
.requestMatchers(Constants.LOGIN_URL).anonymous()
.requestMatchers("/catalog").permitAll()
.anyRequest().authenticated()
);
httpSecurity.authorizeHttpRequests(requests -> requests
.requestMatchers(Constants.ADMIN_PREFIX + "/**").hasRole(UserRole.ADMIN.name())
.requestMatchers("/h2-console/**").hasRole(UserRole.ADMIN.name())
.requestMatchers(UserSignupController.URL).anonymous()
.requestMatchers(Constants.LOGIN_URL).anonymous()
.anyRequest().authenticated());
httpSecurity.formLogin(formLogin -> formLogin
.loginPage(Constants.LOGIN_URL));
httpSecurity.formLogin(formLogin -> formLogin
.loginPage(Constants.LOGIN_URL));
httpSecurity.rememberMe(rememberMe -> rememberMe.key("uniqueAndSecret"));
httpSecurity.rememberMe(rememberMe -> rememberMe.key("uniqueAndSecret"));
httpSecurity.logout(logout -> logout
.deleteCookies("JSESSIONID"));
return httpSecurity.build();
}
httpSecurity.logout(logout -> logout
.deleteCookies("JSESSIONID"));
return httpSecurity.build();
}
@Bean
DaoAuthenticationProvider authenticationProvider(UserDetailsService userDetailsService) {
final DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();

View File

@ -7,7 +7,8 @@ import com.example.demo.cartItems.api.CartItemDto;
public class SessionCart extends HashMap<Integer, CartItemDto> {
public double getSum() {
return this.values().stream()
.mapToDouble(item -> item.getQuantity() * item.getIventPrice())
.map(item -> item.getQuantity() * item.getIventPrice())
.mapToDouble(Double::doubleValue)
.sum();
}
}

View File

@ -63,11 +63,11 @@ public class IventDto {
this.date = date;
}
public String getDesc() {
public String getDescription() {
return description;
}
public void setDesc(String description) {
public void setDescription(String description) {
this.description = description;
}
@ -99,7 +99,7 @@ public class IventDto {
return placeId;
}
public void setPLaceId(Long placeId) {
public void setPlaceId(Long placeId) {
this.placeId = placeId;
}

View File

@ -1,6 +1,9 @@
package com.example.demo.ivents.model;
import java.util.Objects;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import com.example.demo.core.model.BaseEntity;
@ -10,6 +13,7 @@ import com.example.demo.places.model.PlaceEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@ -22,6 +26,7 @@ public class IventEntity extends BaseEntity {
@JoinColumn(name = "typeId", nullable = false)
private TypeEntity type;
@Column(nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date;
@Column(nullable = false)
private String description;

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@ -1,5 +1,4 @@
html,
header nav {
font-family: 'Correction Tape', sans-serif;
background-color:#2F2727;
@ -25,8 +24,56 @@ body{
color: #000000;
}
#container {
gap: 20px;
overflow-y: auto;
max-height: calc(100vh - 50px); /* Высота контейнера будет рассчитана как 100% высоты видимой области минус 20px */
}
.img-card {
width: 330px; /* Замените значение на желаемый размер для ширины */
height: 330px; /* Замените значение на желаемый размер для высоты */
object-fit: cover; /* Этот стиль поможет вписать изображение в указанные размеры */
}
.textForm {
color: #faebd7;
}
/*orders*/
.ordersbody {
display: flex;
justify-content: space-between;
padding: 0 5cm;
}
.ordersmain {
width: 66.6%; /* 2/3 от ширины страницы */
margin-right: 1cm; /* отступ между блоками */
}
.ordersform {
width: 100%;
}
.orders {
width: 100%;
}
.user-info {
width: 33.3%; /* 1/3 от ширины страницы */
}
.card{
margin:10px;
padding:5px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
footer {

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -56,25 +56,6 @@
</form>
</div>
</div>
<!--<div class="mb-2">
<form action="#" th:action="@{/cart}" th:object="${cartItem}" method="post">
<input type="text" th:value="*{id}" id="id" class="visually-hidden">
<div class="mb-2">
<label for="iventId" class="form-label">Товары</label>
<select th:field="*{iventId}" id="iventId" class="form-select">
<option selected value="">Укажите товар</option>
<option th:each="ivent : ${ivents}" th:value="${ivent.id}">[[${ivent.name}]]</option>
</select>
<div th:if="${#fields.hasErrors('iventId')}" th:errors="*{iventId}" class="invalid-feedback"></div>
</div>
<div class="mb-2">
<label for="quantity" class="form-label">Количество</label>
<input type="number" th:field="*{quantity}" id="quantity" class="form-control" value="0" step="1">
<div th:if="${#fields.hasErrors('quantity')}" th:errors="*{quantity}" class="invalid-feedback"></div>
</div>
<button type="submit" class="btn btn-primary">Добавить в корзину</button>
</form>
</div>-->
</main>
</body>

View File

@ -10,26 +10,24 @@
<div id="video-container">
<div class="video-foreground">
<iframe src="https://www.youtube.com/embed/XEEasR7hVhA?autoplay=1&controls=0&loop=1&showinfo=0&mute=1" allowfullscreen title="iframe_video"></iframe>
</div>
<th:block th:switch="${items.size()}">
</div>
<div id="container" style="gap: 20px; overflow-y: auto; max-height: auto;">
<th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<div class="mt-4" style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px">
<div class="card" th:each="ivent : ${items}">
<div class="card-body">
<img src="${ivent.image}" alt="s">
<h5 class="card-title mb-0" th:text="${ivent.name}"></h5>
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.typeName}"></small></p>
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.placeName}"></small></p>
<p class="card-text"><small class="text-body-secondary">[[${ivent.price}]] руб.</small></p>
<form
th:action="@{/buy?id={id}&isCartIvent={isCartIvent}(id=${ivent.id},isCartIvent=${ivent.isCartIvent})}"
method="post">
<button type="submit" class="btn btn-primary"
th:text="'Добавить в корзину'"></button>
</form>
</div>
</div>
<div class="mt-4" style="display: grid; grid-template-columns: repeat(4, 1fr)">
<div class="card" th:each="ivent : ${items}">
<script>
var eventName = `[[${ivent.name}]]`;
</script>
<img class="img-card" th:src="@{'/' + ${ivent.name} + '.jpg'}" alt="s">
<h5 class="card-title mb-0" th:text="${ivent.name}"></h5>
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.typeName}"></small></p>
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.placeName}"></small></p>
<p class="card-text"><small class="text-body-secondary">[[${ivent.price}]] руб.</small></p>
<form th:action="@{/buy?id={id}&isCartIvent={isCartIvent}(id=${ivent.id},isCartIvent=${ivent.isCartIvent})}" method="post">
<button type="submit" class="btn btn-primary" th:text="'Добавить в корзину'"></button>
</form>
</div>
</div>
<th:block th:replace="~{ pagination :: pagination (
@ -38,6 +36,7 @@
currentPage=${currentPage}) }" />
</th:block>
</th:block>
</div>
</main>
</body>

View File

@ -22,7 +22,7 @@
<li>
<a class="nav-link" href="/catalog"
th:classappend="${activeLink.startsWith('/catalog') ? 'active' : ''}">
◌ Каталог
◌ Каталог
</a>
</li>
<li>
@ -66,9 +66,9 @@
<nav class="navbar navbar-expand-md navbar-dark" data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" id="toggle-menu">
<i class="bi bi-ticket-detailed" onclick="toggleMenu()"></i>
<i class="bi bi-ticket-detailed" style="color:#faebd7;"onclick="toggleMenu()"></i>
</a>
<a class="navbar-brand" id="toggle-menu" href="/">
<a class="navbar-brand" id="toggle-menu" style="color: #faebd7;" href="/">
TicketsBook
</a>
<th:block sec:authorize="isAuthenticated()" th:with="userName=${#authentication.name}">
@ -89,12 +89,12 @@
</ul>
<ul class="navbar-nav" th:if="${not #strings.isEmpty(userName)}">
<form th:action="@{/logout}" method="post">
<button type="submit" class="navbar-brand nav-link" onclick="return confirm('Вы уверены?')">
<button type="submit" class="navbar-brand nav-link" style="color:#faebd7;" onclick="return confirm('Вы уверены?')">
Выход ([[${userName}]])
</button>
</form>
<a class="navbar-brand" href="/cart">
<i class="bi bi-cart-check"></i>
<a class="navbar-brand" style="color: #faebd7;" href="/cart">
<i class="bi bi-bag-heart" style="color: #faebd7;"></i>
[[${#numbers.formatDecimal(totalCart, 1, 2)}]] &#8381;
</a>
</ul>

View File

@ -0,0 +1,70 @@
<!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/ivent/edit/{id}(id=${ivent.id})}" th:object="${ivent}" 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="name" class="form-label">Название</label>
<input type="text" th:field="*{name}" id="name" class="form-control">
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="date" class="form-label">Дата</label>
<input type="text" th:field="*{date}" id="date" class="form-control" placeholder="yyyy-MM-dd">
<div th:if="${#fields.hasErrors('date')}" th:errors="*{date}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Описание</label>
<input type="text" th:field="*{description}" id="description" class="form-control">
<div th:if="${#fields.hasErrors('description')}" th:errors="*{description}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="other" class="form-label">Прочее</label>
<input type="text" th:field="*{other}" id="other" class="form-control">
<div th:if="${#fields.hasErrors('other')}" th:errors="*{other}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="price" class="form-label">Цена</label>
<input type="number" th:field="*{price}" id="price" class="form-control" min="1" step="1">
<div th:if="${#fields.hasErrors('price')}" th:errors="*{price}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="typeId" class="form-label">Тип</label>
<select th:field="*{typeId}" id="typeId" class="form-select">
<option selected value="">Укажите категорию</option>
<option th:each="type : ${types}" th:value="${type.id}">[[${type.name}]]</option>
</select>
<div th:if="${#fields.hasErrors('typeId')}" th:errors="*{typeId}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="placeId" class="form-label">Площадка</label>
<select th:field="*{placeId}" id="placeId" class="form-select">
<option selected value="">Укажите место</option>
<option th:each="place : ${places}" th:value="${place.id}">[[${place.name}]]</option>
</select>
<div th:if="${#fields.hasErrors('placeId')}" th:errors="*{placeId}" class="invalid-feedback"></div>
</div>
<div class="mb-1">
<label for="image" class="form-label">Изображение</label>
<input type="file" class="form-control" id="image" required>
<div class="valid-feedback">Изображение загружено</div>
<div 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" href="/admin/ivent">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -2,7 +2,7 @@
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Продукты</title>
<title>Мероприятия</title>
</head>
<body>
@ -10,9 +10,9 @@
<th:block th:switch="${items.size()}">
<h2 th:case="0">Данные отсутствуют</h2>
<th:block th:case="*">
<h2>Продукты</h2>
<h2>Мероприятия</h2>
<div>
<a href="/admin/ivent/edit/" class="btn btn-primary">Добавить продукт</a>
<a href="/admin/ivent/edit/" class="btn btn-primary">Добавить мероприятие</a>
</div>
<table class="table">
<caption></caption>
@ -21,6 +21,7 @@
<th scope="col" class="w-10">ID</th>
<th scope="col" class="w-auto">Название</th>
<th scope="col" class="w-auto">Категория</th>
<th scope="col" class="w-auto">Площадка</th>
<th scope="col" class="w-auto">Цена</th>
<th scope="col" class="w-10"></th>
<th scope="col" class="w-10"></th>
@ -31,6 +32,7 @@
<th scope="row" th:text="${ivent.id}"></th>
<td th:text="${ivent.name}"></td>
<td th:text="${ivent.typeName}"></td>
<td th:text="${ivent.placeName}"></td>
<td th:text="${ivent.price}"></td>
<td>
<form th:action="@{/admin/ivent/edit/{id}(id=${ivent.id})}" method="get">

View File

@ -4,7 +4,7 @@
<body>
<main layout:fragment="content">
<button class="btn btn-link button-link" onclick="history.back()">Назад</button>
<h1>Заказ №[[${order.id}]], [[${#dates.format(order.date, 'HH:mm dd-MM-yyyy')}]]</h1>
<h1 style="color:#faebd7;">Заказ №[[${order.id}]], [[${#dates.format(order.date, 'HH:mm dd-MM-yyyy')}]]</h1>
<th:block th:switch="${items.size()}">
<h2 th:case="0">Товары заказа отсутствуют</h2>
<th:block th:case="*">
@ -12,16 +12,16 @@
<caption></caption>
<thead>
<tr>
<th scope="col" class="w-auto">Название товара</th>
<th scope="col" class="w-10">Цена</th>
<th scope="col" class="w-10">Количество</th>
<th scope="col" class="w-auto" style="color:#faebd7;">Название товара</th>
<th scope="col" class="w-10" style="color:#faebd7;">Цена</th>
<th scope="col" class="w-10" style="color:#faebd7;">Количество</th>
</tr>
</thead>
<tbody>
<tr th:each="item : ${items}">
<td th:text="${item.iventName}"></td>
<td th:text="${#numbers.formatDecimal(item.iventPrice, 1, 2)}"></td>
<td th:text="${item.quantity}"></td>
<td th:text="${item.iventName}" style="color:#faebd7;"></td>
<td th:text="${#numbers.formatDecimal(item.iventPrice, 1, 2)}" style="color:#faebd7;"></td>
<td th:text="${item.quantity}" style="color:#faebd7;"></td>
</tr>
</tbody>
</table>
@ -30,7 +30,7 @@
url='',
totalPages=${totalPages},
currentPage=${currentPage}) }" />
<h2>Итого: [[${#numbers.formatDecimal(order.total, 1, 2)}]] руб</h2>
<h2 style="color:#faebd7;">Итого: [[${#numbers.formatDecimal(order.total, 1, 2)}]] руб</h2>
</th:block>
</main>
</body>

View File

@ -2,7 +2,7 @@
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Заказы</title>
<title>Личный кабинет - Заказы</title>
</head>
<body>

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/place/edit/{id}(id=${place.id})}" th:object="${place}"
method="post">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input place="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
</div>
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input place="text" th:field="*{name}" id="name" 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" place="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" href="/admin/place">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -0,0 +1,55 @@
<!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 href="/admin/place/edit/" 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="place : ${items}">
<th scope="row" th:text="${place.id}"></th>
<td th:text="${place.name}"></td>
<td>
<form th:action="@{/admin/place/edit/{id}(id=${place.id})}" method="get">
<button place="submit" class="btn btn-link button-link">Редактировать</button>
</form>
</td>
<td>
<form th:action="@{/admin/place/delete/{id}(id=${place.id})}" method="post">
<button place="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">Удалить</button>
</form>
</td>
</tr>
</tbody>
</table>
</th:block>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'admin/place'},
totalPages=${totalPages},
currentPage=${currentPage}) }" />
</th:block>
</main>
</body>
</html>

View File

@ -1,41 +0,0 @@
<!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/ivent/edit/{id}(id=${ivent.id})}" th:object="${ivent}" 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="name" class="form-label">Название</label>
<input type="text" th:field="*{name}" id="name" class="form-control">
<div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="price" class="form-label">Цена</label>
<input type="number" th:field="*{price}" id="price" class="form-control" min="1" step="1">
<div th:if="${#fields.hasErrors('price')}" th:errors="*{price}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="typeId" class="form-label">Тип</label>
<select th:field="*{typeId}" id="typeId" class="form-select">
<option selected value="">Укажите категорию</option>
<option th:each="type : ${types}" th:value="${type.id}">[[${type.name}]]</option>
</select>
<div th:if="${#fields.hasErrors('typeId')}" th:errors="*{typeId}" 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" href="/admin/ivent">Отмена</a>
</div>
</form>
</main>
</body>
</html>

View File

@ -14,9 +14,14 @@
<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>
<label for="handle" class="form-label">Логин</label>
<input type="text" th:field="*{handle}" id="handle" class="form-control">
<div th:if="${#fields.hasErrors('handle')}" th:errors="*{handle}" class="invalid-feedback"></div>
</div>
<div class="mb-3">
<label for="email" class="form-label">E-mail</label>
<input type="text" th:field="*{email}" id="email" class="form-control">
<div th:if="${#fields.hasErrors('email')}" th:errors="*{email}" class="invalid-feedback"></div>
</div>
<div class="mb-3 visually-hidden">
<label for="password" class="form-label">Пароль</label>

View File

@ -27,7 +27,7 @@
<tbody>
<tr th:each="user : ${items}">
<th scope="row" th:text="${user.id}"></th>
<td th:text="${user.login}"></td>
<td th:text="${user.handle}"></td>
<td>
<form th:action="@{/admin/user/edit/{id}(id=${user.id})}" method="get">
<input type="hidden" th:name="page" th:value="${page}">

View File

@ -2,11 +2,8 @@ package com.example.demo;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@ -14,17 +11,13 @@ import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.ivents.model.IventEntity;
import com.example.demo.ivents.service.IventService;
import com.example.demo.types.model.TypeEntity;
import com.example.demo.types.service.TypeService;
import com.example.demo.places.model.PlaceEntity;
import com.example.demo.places.service.PlaceService;
import com.example.demo.core.error.NotFoundException;
import jakarta.persistence.EntityManager;
import com.example.demo.types.model.TypeEntity;
import com.example.demo.types.service.TypeService;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
@ -38,86 +31,30 @@ class IventServiceTests {
@Autowired
private IventService iventService;
private IventEntity ivent;
@Test
@Order(1)
void createTest() {
final var type = typeService.create(new TypeEntity("newType"));
final var place = placeService.create(new PlaceEntity("newPlace"));
@BeforeEach
void createData() {
removeData();
final var type = typeService.create(new TypeEntity("Концерт"));
final var place = placeService.create(new PlaceEntity("USA, California"));
ivent = iventService.create(new IventEntity(
"Slipknot",
var ivent = iventService.create(new IventEntity(
"newIvent",
type,
LocalDate.of(2023, 10, 15),
LocalDate.of(2024, 10, 15),
"Описание Slipknot",
"Участники группы Slipknot",
2500.33,
30,
place,
""));
iventService.create(new IventEntity(
"Placebo",
type,
LocalDate.of(2024, 2, 13),
"Описание Placebo",
"Группа Placebo",
2500.33,
30,
place,
""));
iventService.create(new IventEntity(
"Radiohead",
type,
LocalDate.of(2024, 2, 15),
"Описание Radiohead",
"Участники Radiohead",
2500.33,
30,
place,
""));
}
@AfterEach
void removeData() {
iventService.getAll(0L, 0L, null, null).forEach(item -> iventService.delete(item.getId()));
typeService.getAll().forEach(item -> typeService.delete(item.getId()));
placeService.getAll().forEach(item -> placeService.delete(item.getId()));
}
@Transactional
@Test
@Order(1)
void createTest() {
Assertions.assertEquals(3, iventService.getAll(0L, 0L, null, null).size());
null));
Assertions.assertEquals(ivent, iventService.get(ivent.getId()));
}
@Test
@Order(2)
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> iventService.get(0L));
}
@Test
@Order(3)
void sortDates() {
LocalDate start = LocalDate.of(2024, 1, 15);
LocalDate end = LocalDate.of(2024, 5, 15);
List<IventEntity> list = iventService.getAll(0L, 0L, start, end);
Assertions.assertEquals(2, list.size());
}
@Test
@Order(4)
void createNullableTest() {
final IventEntity nullIvent = new IventEntity(
var type = typeService.create(new TypeEntity("qwe"));
var nullableIvent = new IventEntity(
null,
null,
null,
@ -126,53 +63,40 @@ class IventServiceTests {
null,
null,
null,
"");
Assertions.assertThrows(DataIntegrityViolationException.class, () -> iventService.create(nullIvent));
null);
Assertions.assertThrows(DataIntegrityViolationException.class, () -> iventService.create(nullableIvent));
}
@Test
@Order(3)
void sortDates() {
LocalDate start = LocalDate.of(2024, 9, 15);
LocalDate end = LocalDate.of(2024, 12, 15);
List<IventEntity> list = iventService.getAll(0L, 0L, start, end);
Assertions.assertEquals(1, list.size());
}
@Test
@Order(4)
void updateTest() {
var type = typeService.create(new TypeEntity("UpdateType"));
var place = placeService.create(new PlaceEntity("UpdatePlace"));
var ivent = iventService.create(new IventEntity("UpdateTest", type, LocalDate.of(2025, 10, 15), "desc", "other", 399.0, 3, place, null));
var updatedIvent = iventService.update(ivent.getId(), new IventEntity("UpdatedTest", type, LocalDate.of(2025, 10, 15), "desc", "updateTestOther", 1399.0, 3, place, null));
Assertions.assertEquals("UpdatedTest", updatedIvent.getName());
Assertions.assertEquals("updateTestOther", updatedIvent.getOther());
Assertions.assertEquals(1399.00, updatedIvent.getPrice());
}
@Transactional
@Test
@Order(5)
void updateTest() {
final String test = "TEST";
final TypeEntity type = typeService.create(new TypeEntity("Кино"));
final PlaceEntity place = placeService.create(new PlaceEntity("Germany, Berlin"));
final String oldName = ivent.getName();
final TypeEntity oldType = ivent.getType();
final PlaceEntity oldPlace = ivent.getPlace();
final IventEntity newEntity = iventService.update(ivent.getId(), new IventEntity(
test,
type,
LocalDate.of(2023, 10, 15),
"Radiohead - британская рок-группа, образованная в 1985 году.",
"Участниками Radiohead являются:<....>",
2500.33,
30,
place,
""));
Assertions.assertEquals(3, iventService.getAll(0L, 0L, null, null).size());
Assertions.assertEquals(newEntity, iventService.get(ivent.getId()));
Assertions.assertEquals(test, newEntity.getName());
Assertions.assertEquals(type, newEntity.getType());
Assertions.assertEquals(place, newEntity.getPlace());
Assertions.assertNotEquals(oldName, newEntity.getName());
Assertions.assertNotEquals(oldType, newEntity.getType());
Assertions.assertNotEquals(oldPlace, newEntity.getPlace());
}
@Test
@Order(6)
void deleteTest() {
var type = typeService.create(new TypeEntity("DeleteType"));
var place = placeService.create(new PlaceEntity("DeletePlace"));
var ivent = iventService.create(new IventEntity("ToDelete", type, LocalDate.of(2026, 10, 15), "description", "otherInformation", 399.00, 5, place, null));
iventService.delete(ivent.getId());
Assertions.assertEquals(2, iventService.getAll(0L, 0L, null, null).size());
final IventEntity newEntity = iventService.create(new IventEntity(ivent.getName(), ivent.getType(),
ivent.getDate(), ivent.getDesc(), ivent.getOther(), ivent.getPrice(), ivent.getCount(),
ivent.getPlace(), ivent.getImage()));
Assertions.assertEquals(1, typeService.getAll().size());
Assertions.assertEquals(1, placeService.getAll().size());
Assertions.assertNotEquals(ivent.getId(), newEntity.getId());
Assertions.assertFalse(iventService.getAll(0L, 0L, null, null).stream().anyMatch(p -> p.getId().equals(ivent.getId())));
}
}

View File

@ -0,0 +1,99 @@
package com.example.demo;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.demo.core.error.NotFoundException;
import com.example.demo.orders.api.OrderIventDto;
import com.example.demo.orders.service.OrderService;
import com.example.demo.places.model.PlaceEntity;
import com.example.demo.ivents.model.IventEntity;
import com.example.demo.ivents.service.IventService;
import com.example.demo.types.model.TypeEntity;
import com.example.demo.types.service.TypeService;
import com.example.demo.places.model.PlaceEntity;
import com.example.demo.places.service.PlaceService;
import com.example.demo.users.model.UserEntity;
import com.example.demo.users.service.UserService;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
public class OrderServiceTests {
@Autowired
private TypeService typeService;
@Autowired
private PlaceService placeService;
@Autowired
private IventService iventService;
@Autowired
private UserService userService;
@Autowired
private OrderService orderService;
@Test
@Order(1)
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> orderService.getAll(0L));
}
@Test
@Order(2)
void createTest() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate _date = LocalDate.parse("2023-10-15", formatter);
final var type1 = typeService.create(new TypeEntity("type1"));
final var type2 = typeService.create(new TypeEntity("type2"));
final var place1 = placeService.create(new PlaceEntity("place1"));
final var place2 = placeService.create(new PlaceEntity("place2"));
final var ivent1 = iventService.create(new IventEntity(
"ivent1",
type1,
_date,
"Slipknot(test) - американская ню-метал группа, основанная в 1995 году. Они известны своим агрессивным звучанием, смешением хардкор-панк и тяжелого метала с индастриалом и элементами альтернативного рока.",
"Участники группы Slipknot - это:<....>",
2500.33,
30,
place1,
null));
final var ivent2 = iventService.create(new IventEntity(
"ivent2",
type1,
_date,
"Placebo - британская альтернативная рок-группа, основанная в 1994 году. Они известны своим уникальным звучанием, погружающим слушателей в меланхоличную атмосферу и наполняющим музыку эмоциональным содержанием.",
"Группа Placebo состояла из следующих участников:<....>",
2500.33,
30,
place2,
null));
final var user1 = userService.create(new UserEntity("user11", "user11@mail.com", "user11"));
OrderIventDto ivent10 = new OrderIventDto();
ivent10.setIventId(ivent1.getId());
ivent10.setQuantity(4);
OrderIventDto ivent20 = new OrderIventDto();
ivent20.setIventId(ivent2.getId());
ivent20.setQuantity(6);
orderService.create(user1.getId(), Arrays.asList(ivent10, ivent20));
Assertions.assertEquals(1, orderService.getAll(user1.getId()).size());
}
}

View File

@ -1,81 +1,60 @@
package com.example.demo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.example.demo.places.model.PlaceEntity;
import com.example.demo.places.service.PlaceService;
import com.example.demo.types.model.TypeEntity;
import com.example.demo.core.error.NotFoundException;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
class PlaceServiceTests {
@Autowired
private PlaceService placeService;
private PlaceEntity place;
@Autowired
private PlaceService placeService;
@BeforeEach
void createData() {
removeData();
place = placeService.create(new PlaceEntity("USA, California"));
placeService.create(new PlaceEntity("Germany, Berlin"));
placeService.create(new PlaceEntity("UK, London"));
@Test
@Order(1)
void createTest() {
placeService.create(new PlaceEntity("place10"));
placeService.create(new PlaceEntity("place11"));
Assertions.assertEquals(10, placeService.getAll().size());
}
@AfterEach
void removeData() {
placeService.getAll().forEach(item -> placeService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> placeService.get(0L));
}
@Test
void createTest() {
Assertions.assertEquals(3, placeService.getAll().size());
Assertions.assertEquals(place, placeService.get(place.getId()));
}
@Test
@Test
@Order(2)
void createNotUniqueTest() {
final PlaceEntity nonUniquePlace = new PlaceEntity("USA, California");
final PlaceEntity nonUniquePlace = new PlaceEntity("Germany, Berlin");
Assertions.assertThrows(IllegalArgumentException.class, () -> placeService.create(nonUniquePlace));
}
@Test
@Test
@Order(3)
void createNullableTest() {
final PlaceEntity nullablePlace= new PlaceEntity(null);
final PlaceEntity nullablePlace = new PlaceEntity(null);
Assertions.assertThrows(DataIntegrityViolationException.class, () -> placeService.create(nullablePlace));
}
@Test
void updateTest() {
final String test = "TEST";
final String oldName = place.getName();
final PlaceEntity newEntity = placeService.update(place.getId(), new PlaceEntity(test));
Assertions.assertEquals(3, placeService.getAll().size());
Assertions.assertEquals(newEntity, placeService.get(place.getId()));
Assertions.assertEquals(test, newEntity.getName());
Assertions.assertNotEquals(oldName, newEntity.getName());
}
@Test
void deleteTest() {
placeService.delete(place.getId());
Assertions.assertEquals(2, placeService.getAll().size());
final PlaceEntity newEntity = placeService.create(new PlaceEntity(place.getName()));
Assertions.assertEquals(3, placeService.getAll().size());
Assertions.assertNotEquals(place.getId(), newEntity.getId());
}
}
@Test
@Order(4)
void updateTest() {
final PlaceEntity newEntity = placeService.update(19L, new PlaceEntity("TEST"));
Assertions.assertEquals(10, placeService.getAll().size());
Assertions.assertEquals("TEST", newEntity.getName());
Assertions.assertNotEquals("TESTS", newEntity.getName());
}
@Test
@Order(5)
void deleteTest() {
var del = placeService.create(new PlaceEntity("TESTSSS"));
var test = placeService.get(del.getId());
placeService.delete(test.getId());
Assertions.assertEquals(10, placeService.getAll().size());
}
}

View File

@ -1,79 +1,59 @@
package com.example.demo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.example.demo.types.model.TypeEntity;
import com.example.demo.types.service.TypeService;
import com.example.demo.core.error.NotFoundException;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
class TypeServiceTests {
@Autowired
private TypeService typeService;
private TypeEntity type;
@Autowired
private TypeService typeService;
@BeforeEach
void createData() {
removeData();
type = typeService.create(new TypeEntity("USA, California"));
typeService.create(new TypeEntity("Germany, Berlin"));
typeService.create(new TypeEntity("UK, London"));
@Test
@Order(1)
void createTest() {
typeService.create(new TypeEntity("type10"));
Assertions.assertEquals(10, typeService.getAll().size());
}
@AfterEach
void removeData() {
typeService.getAll().forEach(item -> typeService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L));
}
@Test
void createTest() {
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertEquals(type, typeService.get(type.getId()));
}
@Test
@Test
@Order(2)
void createNotUniqueTest() {
final TypeEntity nonUniqueType = new TypeEntity("USA, California");
final TypeEntity nonUniqueType = new TypeEntity("Концерт");
Assertions.assertThrows(IllegalArgumentException.class, () -> typeService.create(nonUniqueType));
}
@Test
@Test
@Order(3)
void createNullableTest() {
final TypeEntity nullableType= new TypeEntity(null);
final TypeEntity nullableType = new TypeEntity(null);
Assertions.assertThrows(DataIntegrityViolationException.class, () -> typeService.create(nullableType));
}
@Test
void updateTest() {
final String test = "TEST";
final String oldName = type.getName();
final TypeEntity newEntity = typeService.update(type.getId(), new TypeEntity(test));
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertEquals(newEntity, typeService.get(type.getId()));
Assertions.assertEquals(test, newEntity.getName());
Assertions.assertNotEquals(oldName, newEntity.getName());
}
@Test
@Order(4)
void updateTest() {
final TypeEntity newEntity = typeService.update(3L, new TypeEntity("TEST"));
Assertions.assertEquals(10, typeService.getAll().size());
Assertions.assertEquals("TEST", newEntity.getName());
Assertions.assertNotEquals("TESTS", newEntity.getName());
}
@Test
void deleteTest() {
typeService.delete(type.getId());
Assertions.assertEquals(2, typeService.getAll().size());
final TypeEntity newEntity = typeService.create(new TypeEntity(type.getName()));
Assertions.assertEquals(3, typeService.getAll().size());
Assertions.assertNotEquals(type.getId(), newEntity.getId());
}
@Test
@Order(5)
void deleteTest() {
var del = typeService.create(new TypeEntity("TESTSSS"));
var test = typeService.get(del.getId());
typeService.delete(test.getId());
Assertions.assertEquals(10, typeService.getAll().size());
}
}

View File

@ -1,86 +1,51 @@
package com.example.demo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.users.model.UserEntity;
import com.example.demo.users.service.UserService;
import com.example.demo.core.error.NotFoundException;
@SpringBootTest
@TestMethodOrder(OrderAnnotation.class)
class UserServiceTests {
@Autowired
private UserService userService;
private UserEntity user;
@BeforeEach
void createData() {
removeData();
user = userService.create(new UserEntity("Admin", "admin@gmail.com", "admin"));
userService.create(new UserEntity("Milana", "milana@gmail.com", "milana"));
userService.create(new UserEntity("TestUser", "user@gmail.com", "test"));
}
@AfterEach
void removeData() {
userService.getAll().forEach(item -> userService.delete(item.getId()));
}
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L));
}
@Transactional
@Test
@Order(1)
void createTest() {
Assertions.assertEquals(3, userService.getAll().size());
Assertions.assertEquals(user, userService.get(user.getId()));
}
@Test
void createNotUniqueTest() {
final UserEntity nonUniqueUser = new UserEntity("Milana", "milana@gmail.com", "milana");
Assertions.assertThrows(IllegalArgumentException.class, () -> userService.create(nonUniqueUser));
Assertions.assertEquals(4, userService.getAll().size());
}
@Test
@Order(2)
void createNullableTest() {
final UserEntity nullableUser = new UserEntity(null, "email@gamil.com", "pass");
var nullableUser = new UserEntity(null, "userTest1", "password");
Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser));
}
@Transactional
@Test
@Order(3)
void updateTest() {
final String test = "TEST";
final String oldLogin = user.getHandle();
final UserEntity newEntity = userService.update(user.getId(),
new UserEntity(test, "admin@gmail.com", "admin"));
Assertions.assertEquals(3, userService.getAll().size());
Assertions.assertEquals(newEntity, userService.get(user.getId()));
Assertions.assertEquals(test, newEntity.getHandle());
Assertions.assertNotEquals(oldLogin, newEntity.getHandle());
var user = userService.create(new UserEntity("userTest2", "userTest2@mail.com", "pswrd"));
var newEntity = userService.update(user.getId(),new UserEntity("userTest2123", "userTest2@mail.com", "password"));
Assertions.assertEquals(5, userService.getAll().size());
Assertions.assertEquals("userTest2123", newEntity.getHandle());
Assertions.assertEquals("password", newEntity.getPassword());
}
@Test
@Order(4)
void deleteTest() {
var user = userService.create(new UserEntity("Delete", "Delete", "Delete"));
userService.delete(user.getId());
Assertions.assertEquals(2, userService.getAll().size());
final UserEntity newEntity = userService
.create(new UserEntity("Admin", "admin@gmail.com", "admin"));
Assertions.assertEquals(3, userService.getAll().size());
Assertions.assertNotEquals(user.getId(), newEntity.getId());
Assertions.assertFalse(userService.getAll().stream().anyMatch(p -> p.getId().equals(user.getId())));
}
}

View File

@ -0,0 +1,14 @@
# Server
spring.main.banner-mode=off
# Logger settings
# Available levels are: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
logging.level.com.example.demo=DEBUG
# JPA Settings
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=password
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=create
spring.jpa.open-in-view=false