подправил заказ
This commit is contained in:
parent
884b2aaad6
commit
386203ef31
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.2.4'
|
||||
id 'org.springframework.boot' version '3.2.5'
|
||||
id 'io.spring.dependency-management' version '1.1.4'
|
||||
}
|
||||
|
||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -61,13 +61,13 @@ public class OrderService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<OrderEntity> createAll(long userId, List<OrderEntity> entities) {
|
||||
if (entities == null || entities.isEmpty()) {
|
||||
public OrderEntity createAll(long userId, OrderEntity entitiy) {
|
||||
if (entitiy == null) {
|
||||
throw new IllegalArgumentException("Orders list is null or empty");
|
||||
}
|
||||
final UserEntity existsUser = userService.get(userId);
|
||||
entities.forEach(entity -> entity.setUser(existsUser));
|
||||
return StreamSupport.stream(repository.saveAll(entities).spliterator(), false).toList();
|
||||
entitiy.setUser(existsUser);
|
||||
return repository.save(entitiy);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -67,18 +67,23 @@ public class UserCartController {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private List<OrderEntity> toOrderEntities(Collection<UserCartDto> dtos) {
|
||||
// private List<GameEntity> toGameEntities(Collection<UserCartDto> dtos){
|
||||
// final GameEntity entity = modelMapper.map(dto, GameEntity.class);
|
||||
// entity.setType(typeService.get(dto.getTypeId()));
|
||||
// var genres = dto.getGenres();
|
||||
// List<GenreEntity> genresList = genreService.getAllById(genres);
|
||||
// for (var genre : genresList) {
|
||||
// entity.setGenres(genre);
|
||||
// }
|
||||
// return entity;
|
||||
// }
|
||||
|
||||
private OrderEntity toOrderEntities(Collection<UserCartDto> dtos) {
|
||||
final Set<Long> gameIds = dtos.stream()
|
||||
.map(UserCartDto::getGame)
|
||||
.collect(Collectors.toSet());
|
||||
final Map<Long, GameEntity> games = gameService.getByIds(gameIds).stream()
|
||||
.collect(Collectors.toMap(GameEntity::getId, Function.identity()));
|
||||
return dtos.stream()
|
||||
.map(dto -> {
|
||||
final OrderEntity entity = modelMapper.map(dto, OrderEntity.class);
|
||||
entity.setGames(games.get(dto.getGame()));
|
||||
return entity;
|
||||
}).toList();
|
||||
final List<GameEntity> games = gameService.getByIds(gameIds);
|
||||
return new OrderEntity(games);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -115,7 +120,7 @@ public class UserCartController {
|
||||
public String saveCart(
|
||||
Model model,
|
||||
@AuthenticationPrincipal UserPrincipal principal) {
|
||||
orderService.createAll(principal.getId(), toOrderEntities(cart.values()));
|
||||
orderService.create(principal.getId(), toOrderEntities(cart.values()));
|
||||
cart.clear();
|
||||
return Constants.REDIRECT_VIEW + URL;
|
||||
}
|
||||
|
36
src/main/resources/templates/game-edit.html
Normal file
36
src/main/resources/templates/game-edit.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!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/game/edit/{id}(id=${type.id})}" th:object="${type}" 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-2">
|
||||
<label for="type" class="form-label">Тип</label>
|
||||
<select th:field="*{type}" id="type" 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('type')}" th:errors="*{type}" 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/type">Отмена</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user