готово
This commit is contained in:
parent
68f1e0b0f8
commit
6903dc353b
10
build.gradle
10
build.gradle
@ -28,11 +28,11 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
implementation 'org.modelmapper:modelmapper:3.2.0'
|
implementation 'org.modelmapper:modelmapper:3.2.0'
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
implementation 'com.h2database:h2:2.2.224'
|
implementation 'com.h2database:h2:2.2.224'
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
@ -43,7 +43,7 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
|
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') {
|
tasks.named('test') {
|
||||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
6469
data.trace.db
6469
data.trace.db
File diff suppressed because it is too large
Load Diff
@ -69,7 +69,7 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
2500.33,
|
2500.33,
|
||||||
30,
|
30,
|
||||||
place1,
|
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(
|
final var ivent2 = iventService.create(new IventEntity(
|
||||||
"Placebo",
|
"Placebo",
|
||||||
@ -80,7 +80,7 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
2500.33,
|
2500.33,
|
||||||
30,
|
30,
|
||||||
place2,
|
place2,
|
||||||
"https://sun9-32.userapi.com/impg/2pvZuqVQH4hOX2pDuR7G9VMA8d-yVoEkgeYtGQ/YUHaozp5U18.jpg?size=564x798&quality=96&sign=e60e12e163aa46f084f28cc6ce5487c5&type=album"));
|
null));
|
||||||
|
|
||||||
iventService.create(new IventEntity(
|
iventService.create(new IventEntity(
|
||||||
"Radiohead",
|
"Radiohead",
|
||||||
@ -91,7 +91,7 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
2500.33,
|
2500.33,
|
||||||
30,
|
30,
|
||||||
place3,
|
place3,
|
||||||
"https://sun7-21.userapi.com/impg/C5aKzJPvxULBB_CuWMgXIG6uj5AuB2qKlBVDxA/NR1B43MGKVs.jpg?size=500x629&quality=96&sign=ff85339d4ff11424738fe9d58c0b2d23&type=album"));
|
null));
|
||||||
|
|
||||||
iventService.create(new IventEntity(
|
iventService.create(new IventEntity(
|
||||||
"Сияние",
|
"Сияние",
|
||||||
@ -102,7 +102,7 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
2500.33,
|
2500.33,
|
||||||
45,
|
45,
|
||||||
place3,
|
place3,
|
||||||
"https://sun9-3.userapi.com/impg/9oGzwF1Xx2OZmN_xzFGUo2AewBbuo2y2QYskTw/4euSR1gwhmE.jpg?size=556x832&quality=96&sign=d6e480044eedf3a0e0c24f16ad7473f7&type=album"));
|
null));
|
||||||
|
|
||||||
iventService.create(new IventEntity(
|
iventService.create(new IventEntity(
|
||||||
"Мастер и Маргарита",
|
"Мастер и Маргарита",
|
||||||
@ -113,7 +113,7 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
2500.33,
|
2500.33,
|
||||||
30,
|
30,
|
||||||
place2,
|
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");
|
log.info("Create default users values");
|
||||||
final var admin = new UserEntity("Admin", "Admin@gmail.com", "admin");
|
final var admin = new UserEntity("Admin", "Admin@gmail.com", "admin");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.example.demo.cartItems.api;
|
package com.example.demo.cartItems.api;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@ -17,12 +16,7 @@ public class CartItemDto {
|
|||||||
@Min(1)
|
@Min(1)
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String iventName;
|
private String iventName;
|
||||||
@NotNull
|
|
||||||
private LocalDate iventDate;
|
|
||||||
@NotNull
|
|
||||||
@Min(1)
|
|
||||||
private Double iventPrice;
|
private Double iventPrice;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -57,14 +51,6 @@ public class CartItemDto {
|
|||||||
this.iventName = name;
|
this.iventName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getIventDate() {
|
|
||||||
return iventDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIventDate(LocalDate date) {
|
|
||||||
this.iventDate = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getIventPrice() {
|
public Double getIventPrice() {
|
||||||
return iventPrice;
|
return iventPrice;
|
||||||
}
|
}
|
||||||
@ -87,4 +73,4 @@ public class CartItemDto {
|
|||||||
CartItemDto other = (CartItemDto) obj;
|
CartItemDto other = (CartItemDto) obj;
|
||||||
return Objects.equals(iventId, other.iventId) && Objects.equals(quantity, other.quantity);
|
return Objects.equals(iventId, other.iventId) && Objects.equals(quantity, other.quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ import com.example.demo.core.configuration.Constants;
|
|||||||
import com.example.demo.core.security.UserPrincipal;
|
import com.example.demo.core.security.UserPrincipal;
|
||||||
import com.example.demo.core.session.SessionCart;
|
import com.example.demo.core.session.SessionCart;
|
||||||
import com.example.demo.ivents.api.ExpandedIventDto;
|
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.model.IventEntity;
|
||||||
import com.example.demo.ivents.service.IventService;
|
import com.example.demo.ivents.service.IventService;
|
||||||
|
|
||||||
@ -45,6 +46,14 @@ public class CatalogController {
|
|||||||
return dto;
|
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")
|
@GetMapping("/catalog")
|
||||||
public String getAll(
|
public String getAll(
|
||||||
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
@RequestParam(name = PAGE_ATTRIBUTE, defaultValue = "0") int page,
|
||||||
@ -52,10 +61,18 @@ public class CatalogController {
|
|||||||
@AuthenticationPrincipal UserPrincipal principal) {
|
@AuthenticationPrincipal UserPrincipal principal) {
|
||||||
final Map<String, Object> attributes = PageAttributesMapper.toAttributes(
|
final Map<String, Object> attributes = PageAttributesMapper.toAttributes(
|
||||||
iventService.getAll(0L, 0L, null, null, page, Constants.DEFAULT_PAGE_SIZE),
|
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.addAllAttributes(attributes);
|
||||||
model.addAttribute(PAGE_ATTRIBUTE, page);
|
model.addAttribute(PAGE_ATTRIBUTE, page);
|
||||||
|
|
||||||
return PRODUCTS_VIEW;
|
return PRODUCTS_VIEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +102,6 @@ public class CatalogController {
|
|||||||
cartItem.setIventId(iventId);
|
cartItem.setIventId(iventId);
|
||||||
cartItem.setQuantity(1);
|
cartItem.setQuantity(1);
|
||||||
cartItem.setIventName(ivent.getName());
|
cartItem.setIventName(ivent.getName());
|
||||||
cartItem.setIventDate(ivent.getDate());
|
|
||||||
cartItem.setIventPrice(ivent.getPrice());
|
cartItem.setIventPrice(ivent.getPrice());
|
||||||
|
|
||||||
cart.putIfAbsent(cartItem.hashCode(), cartItem);
|
cart.putIfAbsent(cartItem.hashCode(), cartItem);
|
||||||
|
@ -21,33 +21,32 @@ import com.example.demo.users.model.UserRole;
|
|||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration {
|
public class SecurityConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
|
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
|
||||||
httpSecurity.headers(headers -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
|
httpSecurity.headers(headers -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
|
||||||
httpSecurity.csrf(AbstractHttpConfigurer::disable);
|
httpSecurity.csrf(AbstractHttpConfigurer::disable);
|
||||||
httpSecurity.cors(Customizer.withDefaults());
|
httpSecurity.cors(Customizer.withDefaults());
|
||||||
|
|
||||||
httpSecurity.authorizeHttpRequests(requests -> requests
|
httpSecurity.authorizeHttpRequests(requests -> requests
|
||||||
.requestMatchers("/css/**", "/webjars/**", "/*.svg")
|
.requestMatchers("/css/**", "/webjars/**", "/*.svg", "/*.jpg").permitAll()
|
||||||
.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
|
httpSecurity.formLogin(formLogin -> formLogin
|
||||||
.requestMatchers(Constants.ADMIN_PREFIX + "/**").hasRole(UserRole.ADMIN.name())
|
.loginPage(Constants.LOGIN_URL));
|
||||||
.requestMatchers("/h2-console/**").hasRole(UserRole.ADMIN.name())
|
|
||||||
.requestMatchers(UserSignupController.URL).anonymous()
|
|
||||||
.requestMatchers(Constants.LOGIN_URL).anonymous()
|
|
||||||
.anyRequest().authenticated());
|
|
||||||
|
|
||||||
httpSecurity.formLogin(formLogin -> formLogin
|
httpSecurity.rememberMe(rememberMe -> rememberMe.key("uniqueAndSecret"));
|
||||||
.loginPage(Constants.LOGIN_URL));
|
|
||||||
|
|
||||||
httpSecurity.rememberMe(rememberMe -> rememberMe.key("uniqueAndSecret"));
|
httpSecurity.logout(logout -> logout
|
||||||
|
.deleteCookies("JSESSIONID"));
|
||||||
httpSecurity.logout(logout -> logout
|
|
||||||
.deleteCookies("JSESSIONID"));
|
|
||||||
|
|
||||||
return httpSecurity.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return httpSecurity.build();
|
||||||
|
}
|
||||||
@Bean
|
@Bean
|
||||||
DaoAuthenticationProvider authenticationProvider(UserDetailsService userDetailsService) {
|
DaoAuthenticationProvider authenticationProvider(UserDetailsService userDetailsService) {
|
||||||
final DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
|
final DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
|
||||||
|
@ -7,7 +7,8 @@ import com.example.demo.cartItems.api.CartItemDto;
|
|||||||
public class SessionCart extends HashMap<Integer, CartItemDto> {
|
public class SessionCart extends HashMap<Integer, CartItemDto> {
|
||||||
public double getSum() {
|
public double getSum() {
|
||||||
return this.values().stream()
|
return this.values().stream()
|
||||||
.mapToDouble(item -> item.getQuantity() * item.getIventPrice())
|
.map(item -> item.getQuantity() * item.getIventPrice())
|
||||||
|
.mapToDouble(Double::doubleValue)
|
||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,11 @@ public class IventDto {
|
|||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDesc() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDesc(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class IventDto {
|
|||||||
return placeId;
|
return placeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPLaceId(Long placeId) {
|
public void setPlaceId(Long placeId) {
|
||||||
this.placeId = placeId;
|
this.placeId = placeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.example.demo.ivents.model;
|
package com.example.demo.ivents.model;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import com.example.demo.core.model.BaseEntity;
|
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.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@ -22,6 +26,7 @@ public class IventEntity extends BaseEntity {
|
|||||||
@JoinColumn(name = "typeId", nullable = false)
|
@JoinColumn(name = "typeId", nullable = false)
|
||||||
private TypeEntity type;
|
private TypeEntity type;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String description;
|
private String description;
|
||||||
|
BIN
src/main/resources/public/Placebo.jpg
Normal file
BIN
src/main/resources/public/Placebo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
src/main/resources/public/Radiohead.jpg
Normal file
BIN
src/main/resources/public/Radiohead.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
BIN
src/main/resources/public/Slipknot.jpg
Normal file
BIN
src/main/resources/public/Slipknot.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
@ -1,5 +1,4 @@
|
|||||||
html,
|
html,
|
||||||
|
|
||||||
header nav {
|
header nav {
|
||||||
font-family: 'Correction Tape', sans-serif;
|
font-family: 'Correction Tape', sans-serif;
|
||||||
background-color:#2F2727;
|
background-color:#2F2727;
|
||||||
@ -25,8 +24,56 @@ body{
|
|||||||
color: #000000;
|
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{
|
.card{
|
||||||
margin:10px;
|
margin:10px;
|
||||||
|
padding:5px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
|
BIN
src/main/resources/public/Мастер и Маргарита.jpg
Normal file
BIN
src/main/resources/public/Мастер и Маргарита.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
src/main/resources/public/Сияние.jpg
Normal file
BIN
src/main/resources/public/Сияние.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
@ -56,25 +56,6 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -10,26 +10,24 @@
|
|||||||
<div id="video-container">
|
<div id="video-container">
|
||||||
<div class="video-foreground">
|
<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>
|
<iframe src="https://www.youtube.com/embed/XEEasR7hVhA?autoplay=1&controls=0&loop=1&showinfo=0&mute=1" allowfullscreen title="iframe_video"></iframe>
|
||||||
</div>
|
</div>
|
||||||
<th:block th:switch="${items.size()}">
|
<div id="container" style="gap: 20px; overflow-y: auto; max-height: auto;">
|
||||||
|
<th:block th:switch="${items.size()}">
|
||||||
<h2 th:case="0">Данные отсутствуют</h2>
|
<h2 th:case="0">Данные отсутствуют</h2>
|
||||||
<th:block th:case="*">
|
<th:block th:case="*">
|
||||||
<div class="mt-4" style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px">
|
<div class="mt-4" style="display: grid; grid-template-columns: repeat(4, 1fr)">
|
||||||
<div class="card" th:each="ivent : ${items}">
|
<div class="card" th:each="ivent : ${items}">
|
||||||
<div class="card-body">
|
<script>
|
||||||
<img src="${ivent.image}" alt="s">
|
var eventName = `[[${ivent.name}]]`;
|
||||||
<h5 class="card-title mb-0" th:text="${ivent.name}"></h5>
|
</script>
|
||||||
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.typeName}"></small></p>
|
<img class="img-card" th:src="@{'/' + ${ivent.name} + '.jpg'}" alt="s">
|
||||||
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.placeName}"></small></p>
|
<h5 class="card-title mb-0" th:text="${ivent.name}"></h5>
|
||||||
<p class="card-text"><small class="text-body-secondary">[[${ivent.price}]] руб.</small></p>
|
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.typeName}"></small></p>
|
||||||
<form
|
<p class="card-text"><small class="text-body-secondary" th:text="${ivent.placeName}"></small></p>
|
||||||
th:action="@{/buy?id={id}&isCartIvent={isCartIvent}(id=${ivent.id},isCartIvent=${ivent.isCartIvent})}"
|
<p class="card-text"><small class="text-body-secondary">[[${ivent.price}]] руб.</small></p>
|
||||||
method="post">
|
<form th:action="@{/buy?id={id}&isCartIvent={isCartIvent}(id=${ivent.id},isCartIvent=${ivent.isCartIvent})}" method="post">
|
||||||
<button type="submit" class="btn btn-primary"
|
<button type="submit" class="btn btn-primary" th:text="'Добавить в корзину'"></button>
|
||||||
th:text="'Добавить в корзину'"></button>
|
</form>
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<th:block th:replace="~{ pagination :: pagination (
|
<th:block th:replace="~{ pagination :: pagination (
|
||||||
@ -38,6 +36,7 @@
|
|||||||
currentPage=${currentPage}) }" />
|
currentPage=${currentPage}) }" />
|
||||||
</th:block>
|
</th:block>
|
||||||
</th:block>
|
</th:block>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<a class="nav-link" href="/catalog"
|
<a class="nav-link" href="/catalog"
|
||||||
th:classappend="${activeLink.startsWith('/catalog') ? 'active' : ''}">
|
th:classappend="${activeLink.startsWith('/catalog') ? 'active' : ''}">
|
||||||
◌ Каталог
|
◌ Каталог
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@ -66,9 +66,9 @@
|
|||||||
<nav class="navbar navbar-expand-md navbar-dark" data-bs-theme="dark">
|
<nav class="navbar navbar-expand-md navbar-dark" data-bs-theme="dark">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" id="toggle-menu">
|
<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>
|
||||||
<a class="navbar-brand" id="toggle-menu" href="/">
|
<a class="navbar-brand" id="toggle-menu" style="color: #faebd7;" href="/">
|
||||||
TicketsBook
|
TicketsBook
|
||||||
</a>
|
</a>
|
||||||
<th:block sec:authorize="isAuthenticated()" th:with="userName=${#authentication.name}">
|
<th:block sec:authorize="isAuthenticated()" th:with="userName=${#authentication.name}">
|
||||||
@ -89,12 +89,12 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav" th:if="${not #strings.isEmpty(userName)}">
|
<ul class="navbar-nav" th:if="${not #strings.isEmpty(userName)}">
|
||||||
<form th:action="@{/logout}" method="post">
|
<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}]])
|
Выход ([[${userName}]])
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<a class="navbar-brand" href="/cart">
|
<a class="navbar-brand" style="color: #faebd7;" href="/cart">
|
||||||
<i class="bi bi-cart-check"></i>
|
<i class="bi bi-bag-heart" style="color: #faebd7;"></i>
|
||||||
[[${#numbers.formatDecimal(totalCart, 1, 2)}]] ₽
|
[[${#numbers.formatDecimal(totalCart, 1, 2)}]] ₽
|
||||||
</a>
|
</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
70
src/main/resources/templates/ivent-edit.html
Normal file
70
src/main/resources/templates/ivent-edit.html
Normal 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>
|
@ -2,7 +2,7 @@
|
|||||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Продукты</title>
|
<title>Мероприятия</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -10,9 +10,9 @@
|
|||||||
<th:block th:switch="${items.size()}">
|
<th:block th:switch="${items.size()}">
|
||||||
<h2 th:case="0">Данные отсутствуют</h2>
|
<h2 th:case="0">Данные отсутствуют</h2>
|
||||||
<th:block th:case="*">
|
<th:block th:case="*">
|
||||||
<h2>Продукты</h2>
|
<h2>Мероприятия</h2>
|
||||||
<div>
|
<div>
|
||||||
<a href="/admin/ivent/edit/" class="btn btn-primary">Добавить продукт</a>
|
<a href="/admin/ivent/edit/" class="btn btn-primary">Добавить мероприятие</a>
|
||||||
</div>
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<caption></caption>
|
<caption></caption>
|
||||||
@ -21,6 +21,7 @@
|
|||||||
<th scope="col" class="w-10">ID</th>
|
<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-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>
|
||||||
<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>
|
<th scope="row" th:text="${ivent.id}"></th>
|
||||||
<td th:text="${ivent.name}"></td>
|
<td th:text="${ivent.name}"></td>
|
||||||
<td th:text="${ivent.typeName}"></td>
|
<td th:text="${ivent.typeName}"></td>
|
||||||
|
<td th:text="${ivent.placeName}"></td>
|
||||||
<td th:text="${ivent.price}"></td>
|
<td th:text="${ivent.price}"></td>
|
||||||
<td>
|
<td>
|
||||||
<form th:action="@{/admin/ivent/edit/{id}(id=${ivent.id})}" method="get">
|
<form th:action="@{/admin/ivent/edit/{id}(id=${ivent.id})}" method="get">
|
@ -4,7 +4,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<main layout:fragment="content">
|
<main layout:fragment="content">
|
||||||
<button class="btn btn-link button-link" onclick="history.back()">Назад</button>
|
<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()}">
|
<th:block th:switch="${items.size()}">
|
||||||
<h2 th:case="0">Товары заказа отсутствуют</h2>
|
<h2 th:case="0">Товары заказа отсутствуют</h2>
|
||||||
<th:block th:case="*">
|
<th:block th:case="*">
|
||||||
@ -12,16 +12,16 @@
|
|||||||
<caption></caption>
|
<caption></caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="w-auto">Название товара</th>
|
<th scope="col" class="w-auto" style="color:#faebd7;">Название товара</th>
|
||||||
<th scope="col" class="w-10">Цена</th>
|
<th scope="col" class="w-10" style="color:#faebd7;">Цена</th>
|
||||||
<th scope="col" class="w-10">Количество</th>
|
<th scope="col" class="w-10" style="color:#faebd7;">Количество</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="item : ${items}">
|
<tr th:each="item : ${items}">
|
||||||
<td th:text="${item.iventName}"></td>
|
<td th:text="${item.iventName}" style="color:#faebd7;"></td>
|
||||||
<td th:text="${#numbers.formatDecimal(item.iventPrice, 1, 2)}"></td>
|
<td th:text="${#numbers.formatDecimal(item.iventPrice, 1, 2)}" style="color:#faebd7;"></td>
|
||||||
<td th:text="${item.quantity}"></td>
|
<td th:text="${item.quantity}" style="color:#faebd7;"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -30,7 +30,7 @@
|
|||||||
url='',
|
url='',
|
||||||
totalPages=${totalPages},
|
totalPages=${totalPages},
|
||||||
currentPage=${currentPage}) }" />
|
currentPage=${currentPage}) }" />
|
||||||
<h2>Итого: [[${#numbers.formatDecimal(order.total, 1, 2)}]] руб</h2>
|
<h2 style="color:#faebd7;">Итого: [[${#numbers.formatDecimal(order.total, 1, 2)}]] руб</h2>
|
||||||
</th:block>
|
</th:block>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Заказы</title>
|
<title>Личный кабинет - Заказы</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
29
src/main/resources/templates/place-edit.html
Normal file
29
src/main/resources/templates/place-edit.html
Normal 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>
|
55
src/main/resources/templates/place.html
Normal file
55
src/main/resources/templates/place.html
Normal 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>
|
@ -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>
|
|
@ -14,9 +14,14 @@
|
|||||||
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
|
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="login" class="form-label">Логин</label>
|
<label for="handle" class="form-label">Логин</label>
|
||||||
<input type="text" th:field="*{login}" id="login" class="form-control">
|
<input type="text" th:field="*{handle}" id="handle" class="form-control">
|
||||||
<div th:if="${#fields.hasErrors('login')}" th:errors="*{login}" class="invalid-feedback"></div>
|
<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>
|
||||||
<div class="mb-3 visually-hidden">
|
<div class="mb-3 visually-hidden">
|
||||||
<label for="password" class="form-label">Пароль</label>
|
<label for="password" class="form-label">Пароль</label>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="user : ${items}">
|
<tr th:each="user : ${items}">
|
||||||
<th scope="row" th:text="${user.id}"></th>
|
<th scope="row" th:text="${user.id}"></th>
|
||||||
<td th:text="${user.login}"></td>
|
<td th:text="${user.handle}"></td>
|
||||||
<td>
|
<td>
|
||||||
<form th:action="@{/admin/user/edit/{id}(id=${user.id})}" method="get">
|
<form th:action="@{/admin/user/edit/{id}(id=${user.id})}" method="get">
|
||||||
<input type="hidden" th:name="page" th:value="${page}">
|
<input type="hidden" th:name="page" th:value="${page}">
|
||||||
|
@ -2,11 +2,8 @@ package com.example.demo;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
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.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.example.demo.ivents.model.IventEntity;
|
import com.example.demo.ivents.model.IventEntity;
|
||||||
import com.example.demo.ivents.service.IventService;
|
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.model.PlaceEntity;
|
||||||
import com.example.demo.places.service.PlaceService;
|
import com.example.demo.places.service.PlaceService;
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.types.model.TypeEntity;
|
||||||
|
import com.example.demo.types.service.TypeService;
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
@ -38,86 +31,30 @@ class IventServiceTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IventService iventService;
|
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
|
var ivent = iventService.create(new IventEntity(
|
||||||
void createData() {
|
"newIvent",
|
||||||
removeData();
|
|
||||||
|
|
||||||
final var type = typeService.create(new TypeEntity("Концерт"));
|
|
||||||
final var place = placeService.create(new PlaceEntity("USA, California"));
|
|
||||||
|
|
||||||
ivent = iventService.create(new IventEntity(
|
|
||||||
"Slipknot",
|
|
||||||
type,
|
type,
|
||||||
LocalDate.of(2023, 10, 15),
|
LocalDate.of(2024, 10, 15),
|
||||||
"Описание Slipknot",
|
"Описание Slipknot",
|
||||||
"Участники группы Slipknot",
|
"Участники группы Slipknot",
|
||||||
2500.33,
|
2500.33,
|
||||||
30,
|
30,
|
||||||
place,
|
place,
|
||||||
""));
|
null));
|
||||||
|
|
||||||
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());
|
|
||||||
Assertions.assertEquals(ivent, iventService.get(ivent.getId()));
|
Assertions.assertEquals(ivent, iventService.get(ivent.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@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() {
|
void createNullableTest() {
|
||||||
final IventEntity nullIvent = new IventEntity(
|
var type = typeService.create(new TypeEntity("qwe"));
|
||||||
|
var nullableIvent = new IventEntity(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -126,53 +63,40 @@ class IventServiceTests {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
"");
|
null);
|
||||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> iventService.create(nullIvent));
|
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
|
@Test
|
||||||
@Order(5)
|
@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() {
|
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());
|
iventService.delete(ivent.getId());
|
||||||
Assertions.assertEquals(2, iventService.getAll(0L, 0L, null, null).size());
|
Assertions.assertFalse(iventService.getAll(0L, 0L, null, null).stream().anyMatch(p -> p.getId().equals(ivent.getId())));
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
99
src/test/java/com/example/demo/OrderServiceTests.java
Normal file
99
src/test/java/com/example/demo/OrderServiceTests.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,81 +1,60 @@
|
|||||||
package com.example.demo;
|
package com.example.demo;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
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.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.places.model.PlaceEntity;
|
import com.example.demo.places.model.PlaceEntity;
|
||||||
import com.example.demo.places.service.PlaceService;
|
import com.example.demo.places.service.PlaceService;
|
||||||
import com.example.demo.types.model.TypeEntity;
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class PlaceServiceTests {
|
class PlaceServiceTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlaceService placeService;
|
private PlaceService placeService;
|
||||||
|
|
||||||
private PlaceEntity place;
|
|
||||||
|
|
||||||
@BeforeEach
|
@Test
|
||||||
void createData() {
|
@Order(1)
|
||||||
removeData();
|
void createTest() {
|
||||||
|
placeService.create(new PlaceEntity("place10"));
|
||||||
place = placeService.create(new PlaceEntity("USA, California"));
|
placeService.create(new PlaceEntity("place11"));
|
||||||
placeService.create(new PlaceEntity("Germany, Berlin"));
|
Assertions.assertEquals(10, placeService.getAll().size());
|
||||||
placeService.create(new PlaceEntity("UK, London"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@Test
|
||||||
void removeData() {
|
@Order(2)
|
||||||
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
|
|
||||||
void createNotUniqueTest() {
|
void createNotUniqueTest() {
|
||||||
final PlaceEntity nonUniquePlace = new PlaceEntity("USA, California");
|
final PlaceEntity nonUniquePlace = new PlaceEntity("Germany, Berlin");
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () -> placeService.create(nonUniquePlace));
|
Assertions.assertThrows(IllegalArgumentException.class, () -> placeService.create(nonUniquePlace));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(3)
|
||||||
void createNullableTest() {
|
void createNullableTest() {
|
||||||
final PlaceEntity nullablePlace= new PlaceEntity(null);
|
final PlaceEntity nullablePlace = new PlaceEntity(null);
|
||||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> placeService.create(nullablePlace));
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> placeService.create(nullablePlace));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateTest() {
|
@Order(4)
|
||||||
final String test = "TEST";
|
void updateTest() {
|
||||||
final String oldName = place.getName();
|
final PlaceEntity newEntity = placeService.update(19L, new PlaceEntity("TEST"));
|
||||||
final PlaceEntity newEntity = placeService.update(place.getId(), new PlaceEntity(test));
|
Assertions.assertEquals(10, placeService.getAll().size());
|
||||||
Assertions.assertEquals(3, placeService.getAll().size());
|
Assertions.assertEquals("TEST", newEntity.getName());
|
||||||
Assertions.assertEquals(newEntity, placeService.get(place.getId()));
|
Assertions.assertNotEquals("TESTS", newEntity.getName());
|
||||||
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(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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,79 +1,59 @@
|
|||||||
package com.example.demo;
|
package com.example.demo;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
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.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
|
||||||
import com.example.demo.types.model.TypeEntity;
|
import com.example.demo.types.model.TypeEntity;
|
||||||
import com.example.demo.types.service.TypeService;
|
import com.example.demo.types.service.TypeService;
|
||||||
import com.example.demo.core.error.NotFoundException;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class TypeServiceTests {
|
class TypeServiceTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private TypeService typeService;
|
private TypeService typeService;
|
||||||
|
|
||||||
private TypeEntity type;
|
|
||||||
|
|
||||||
@BeforeEach
|
@Test
|
||||||
void createData() {
|
@Order(1)
|
||||||
removeData();
|
void createTest() {
|
||||||
|
typeService.create(new TypeEntity("type10"));
|
||||||
type = typeService.create(new TypeEntity("USA, California"));
|
Assertions.assertEquals(10, typeService.getAll().size());
|
||||||
typeService.create(new TypeEntity("Germany, Berlin"));
|
|
||||||
typeService.create(new TypeEntity("UK, London"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@Test
|
||||||
void removeData() {
|
@Order(2)
|
||||||
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
|
|
||||||
void createNotUniqueTest() {
|
void createNotUniqueTest() {
|
||||||
final TypeEntity nonUniqueType = new TypeEntity("USA, California");
|
final TypeEntity nonUniqueType = new TypeEntity("Концерт");
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () -> typeService.create(nonUniqueType));
|
Assertions.assertThrows(IllegalArgumentException.class, () -> typeService.create(nonUniqueType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(3)
|
||||||
void createNullableTest() {
|
void createNullableTest() {
|
||||||
final TypeEntity nullableType= new TypeEntity(null);
|
final TypeEntity nullableType = new TypeEntity(null);
|
||||||
Assertions.assertThrows(DataIntegrityViolationException.class, () -> typeService.create(nullableType));
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> typeService.create(nullableType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateTest() {
|
@Order(4)
|
||||||
final String test = "TEST";
|
void updateTest() {
|
||||||
final String oldName = type.getName();
|
final TypeEntity newEntity = typeService.update(3L, new TypeEntity("TEST"));
|
||||||
final TypeEntity newEntity = typeService.update(type.getId(), new TypeEntity(test));
|
Assertions.assertEquals(10, typeService.getAll().size());
|
||||||
Assertions.assertEquals(3, typeService.getAll().size());
|
Assertions.assertEquals("TEST", newEntity.getName());
|
||||||
Assertions.assertEquals(newEntity, typeService.get(type.getId()));
|
Assertions.assertNotEquals("TESTS", newEntity.getName());
|
||||||
Assertions.assertEquals(test, newEntity.getName());
|
}
|
||||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteTest() {
|
@Order(5)
|
||||||
typeService.delete(type.getId());
|
void deleteTest() {
|
||||||
Assertions.assertEquals(2, typeService.getAll().size());
|
var del = typeService.create(new TypeEntity("TESTSSS"));
|
||||||
|
var test = typeService.get(del.getId());
|
||||||
final TypeEntity newEntity = typeService.create(new TypeEntity(type.getName()));
|
typeService.delete(test.getId());
|
||||||
Assertions.assertEquals(3, typeService.getAll().size());
|
Assertions.assertEquals(10, typeService.getAll().size());
|
||||||
Assertions.assertNotEquals(type.getId(), newEntity.getId());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,86 +1,51 @@
|
|||||||
package com.example.demo;
|
package com.example.demo;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
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.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.example.demo.users.model.UserEntity;
|
import com.example.demo.users.model.UserEntity;
|
||||||
import com.example.demo.users.service.UserService;
|
import com.example.demo.users.service.UserService;
|
||||||
import com.example.demo.core.error.NotFoundException;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class UserServiceTests {
|
class UserServiceTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
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
|
@Test
|
||||||
|
@Order(1)
|
||||||
void createTest() {
|
void createTest() {
|
||||||
Assertions.assertEquals(3, userService.getAll().size());
|
Assertions.assertEquals(4, 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(2)
|
||||||
void createNullableTest() {
|
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));
|
Assertions.assertThrows(DataIntegrityViolationException.class, () -> userService.create(nullableUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(3)
|
||||||
void updateTest() {
|
void updateTest() {
|
||||||
final String test = "TEST";
|
var user = userService.create(new UserEntity("userTest2", "userTest2@mail.com", "pswrd"));
|
||||||
final String oldLogin = user.getHandle();
|
var newEntity = userService.update(user.getId(),new UserEntity("userTest2123", "userTest2@mail.com", "password"));
|
||||||
final UserEntity newEntity = userService.update(user.getId(),
|
Assertions.assertEquals(5, userService.getAll().size());
|
||||||
new UserEntity(test, "admin@gmail.com", "admin"));
|
Assertions.assertEquals("userTest2123", newEntity.getHandle());
|
||||||
Assertions.assertEquals(3, userService.getAll().size());
|
Assertions.assertEquals("password", newEntity.getPassword());
|
||||||
Assertions.assertEquals(newEntity, userService.get(user.getId()));
|
|
||||||
Assertions.assertEquals(test, newEntity.getHandle());
|
|
||||||
Assertions.assertNotEquals(oldLogin, newEntity.getHandle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Order(4)
|
||||||
void deleteTest() {
|
void deleteTest() {
|
||||||
|
var user = userService.create(new UserEntity("Delete", "Delete", "Delete"));
|
||||||
userService.delete(user.getId());
|
userService.delete(user.getId());
|
||||||
Assertions.assertEquals(2, userService.getAll().size());
|
Assertions.assertFalse(userService.getAll().stream().anyMatch(p -> p.getId().equals(user.getId())));
|
||||||
|
|
||||||
final UserEntity newEntity = userService
|
|
||||||
.create(new UserEntity("Admin", "admin@gmail.com", "admin"));
|
|
||||||
Assertions.assertEquals(3, userService.getAll().size());
|
|
||||||
Assertions.assertNotEquals(user.getId(), newEntity.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/test/java/resources/application.properties
Normal file
14
src/test/java/resources/application.properties
Normal 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
|
Loading…
Reference in New Issue
Block a user