diff --git a/build.gradle b/build.gradle index 233f023..e7d1be3 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/data.mv.db b/data.mv.db index 75e0800..ef94f3e 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/example/demo/orders/service/OrderService.java b/src/main/java/com/example/demo/orders/service/OrderService.java index 210ec35..780152f 100644 --- a/src/main/java/com/example/demo/orders/service/OrderService.java +++ b/src/main/java/com/example/demo/orders/service/OrderService.java @@ -61,13 +61,13 @@ public class OrderService { } @Transactional - public List createAll(long userId, List 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 diff --git a/src/main/java/com/example/demo/users/api/UserCartController.java b/src/main/java/com/example/demo/users/api/UserCartController.java index 3be1044..5499f2a 100644 --- a/src/main/java/com/example/demo/users/api/UserCartController.java +++ b/src/main/java/com/example/demo/users/api/UserCartController.java @@ -67,18 +67,23 @@ public class UserCartController { return dto; } - private List toOrderEntities(Collection dtos) { + // private List toGameEntities(Collection dtos){ + // final GameEntity entity = modelMapper.map(dto, GameEntity.class); + // entity.setType(typeService.get(dto.getTypeId())); + // var genres = dto.getGenres(); + // List genresList = genreService.getAllById(genres); + // for (var genre : genresList) { + // entity.setGenres(genre); + // } + // return entity; + // } + + private OrderEntity toOrderEntities(Collection dtos) { final Set gameIds = dtos.stream() .map(UserCartDto::getGame) .collect(Collectors.toSet()); - final Map 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 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; } diff --git a/src/main/resources/templates/game-edit.html b/src/main/resources/templates/game-edit.html new file mode 100644 index 0000000..9c4353f --- /dev/null +++ b/src/main/resources/templates/game-edit.html @@ -0,0 +1,36 @@ + + + + + Редакторовать игру + + + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ + Отмена +
+
+
+ + + \ No newline at end of file