Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create tests #9

Open
wants to merge 2 commits into
base: market-new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Он-лайн магазин продуктов

Функции у пользователя:
1) Поиск товара по категориям, цене названию;
2) Добавление товара в корзину, оформление заказа;
3) В личном кобинете можно посмотреть список всех заказов;
4) Можно оставлять и смотреть коментарии к товару;

Функции у администратора:
1) Добавление новых, редактирование и удаление товаров;
2) Можно оставлять, смотреть, удалять комментарии;
3) Можно заблокировать/разблокировать пользователей;

Примечание:
Администратор: логин:ggg пароль:ggg
Пользователь: логин:fff пароль:fff
http://localhost:8080/product/list
3 changes: 0 additions & 3 deletions src/main/java/com/example/springmvc/SpringMvcApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
public class SpringMvcApplication {

public static void main(String[] args) {
// Flyway flyway = Flyway.configure().dataSource(
// "jdbc:postgresql://localhost:5435/spring", "postgres", "postgrespass").load();
// flyway.migrate();
SpringApplication.run(SpringMvcApplication.class, args);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,4 @@ public String createOrder(@ModelAttribute Address address,
orderService.save(shoppingCart, address, name);
return "redirect:/order/list";
}

// @PostMapping(FORM)
// public String updateStatusOrder(@ModelAttribute Address address) {
// String name = SecurityContextHolder.getContext().getAuthentication().getName();
// return "redirect:/order/list";
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ public String getUserAccount(Model model) {
model.addAttribute("user", user);
return "user/personalAccount";
}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.example.springmvc.mvcLayer.domain.search;

import com.example.springmvc.mvcLayer.domain.dto.ProductDto;
import lombok.Data;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;

import java.util.Collections;
import java.util.List;

@Data
public class ProductSearchCondition {
private Sort.Direction sortDirection=Sort.Direction.ASC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ public interface CategoryRepository extends JpaRepository<Category, Integer> {

Optional<Category> findCategoryByTitle(String title);


Set<Category> findCategoryByIdIn(Set<Integer> ids);

// Page<Product> findProductsByIdCategory(Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -30,8 +29,4 @@ Page<Product> findProductsByTitleContainingIgnoreCaseAndPriceBetween(
@Modifying
@Query("update Product p set p.countProduct = :count where p.id = :id")
void updateCount(@Param("id")Integer id, @Param("count")Integer count);

@Modifying
@Query("update Product p set p.countProduct = p.countProduct +1 where p.id = :id")
void plusCount(@Param("id")Integer id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public interface ReviewRepository extends JpaRepository<ProductReview, Integer>

List<ProductReview>findProductReviewsByProduct_id(Integer productId);


void deleteProductReviewsByProduct_Id(Integer productId);

void deleteProductReviewById(Integer id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface OrderService {

void save(ShoppingCart shoppingCart, Address address, String name );
void save(ShoppingCart shoppingCart, Address address, String name);

List<Order> getAllOrders(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ Page<Product> findProductsByTitleAndByMaxAndMinPriceBySearchConditional(

void pagination(ProductSearchCondition searchCondition, Model model, Page<Product> page);


void updateCountInProduct(Integer id, Integer count);

// void plusCountProduct(Integer productId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;

public interface ReviewService {
List<ProductReview> findAllReview();

List<ProductReview> findReviewByProductId(Integer id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -25,9 +24,7 @@
public class OrderServiceImpl implements OrderService {

private final OrderRepository orderRepository;

private final UserService userService;

private final AddressRepository addressRepository;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.example.springmvc.mvcLayer.service.ProductService;
import com.example.springmvc.mvcLayer.service.ReviewService;
import lombok.AllArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -37,8 +36,6 @@ public class ProductServiceImpl implements ProductService {
private final FileService fileService;
private final ReviewService reviewService;

private final ModelMapper modelMapper;

@Override
@Transactional
public Product saveProductAndImage(ProductDto productDto, MultipartFile image) {
Expand All @@ -63,14 +60,11 @@ private Product choosingActionOrCreatingOrUpdating(ProductDto productDto) {
}

private Product dtoProductConvertToProduct(ProductDto productDto) {
Product product = modelMapper.map(productDto, Product.class);
product.setCategories(categoryService.findCategoryById(productDto.getCategoryDto()));
return product;
// return Product.builder().title(productDto.getTitle())
// .price(productDto.getPrice())
// .categories(categoryService.findCategoryById(productDto.getCategoryDto()))
// .countProduct(productDto.getCountProduct())
// .build();
return Product.builder().title(productDto.getTitle())
.price(productDto.getPrice())
.categories(categoryService.findCategoryById(productDto.getCategoryDto()))
.countProduct(productDto.getCountProduct())
.build();
}

@Override
Expand All @@ -86,40 +80,19 @@ public ProductDto findProductDtoById(Integer id) {
} else throw new NoSuchElementException("Продукт был удален администратором");
}

// @Override
// @Transactional
// public void minusOneProductInCount(Integer id, Integer count) {
//// Optional<Product> byId = productRepository.findById(id);
//// byId.ifPresent(product -> productRepository.updateCount(product, count));
// productRepository.updateCount(id, count);
// }

// @Override
// @Transactional
// public void plusCountProduct(Integer productId) {
// Optional<Product> byId = productRepository.findById(productId);
// Integer countProduct = byId.get().getCountProduct()+1;
// productRepository.updateCount(productId, countProduct);
//// productRepository.plusCount(productId);
// }

@Override
@Transactional
public void updateCountInProduct(Integer id, Integer count) {
productRepository.updateCount(id, count);
}

private ProductDto productConvertToDTOProduct(Product entity) {
ProductDto productDto = modelMapper.map(entity, ProductDto.class);
productDto.setCategoryDto(categoryService.getCategoryIdList(entity.getCategories()));
System.err.println(productDto.getCategoryDto().toString());
return productDto;
// return ProductDto.builder().id(entity.getId())
// .title(entity.getTitle())
// .price(entity.getPrice())
// .categoryDto(categoryService.getCategoryIdList(entity.getCategories()))
// .countProduct(entity.getCountProduct())
// .build();
return ProductDto.builder().id(entity.getId())
.title(entity.getTitle())
.price(entity.getPrice())
.categoryDto(categoryService.getCategoryIdList(entity.getCategories()))
.countProduct(entity.getCountProduct())
.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class ReviewServiceImpl implements ReviewService {
private final ReviewRepository reviewRepository;
private final UserService userService;

@Override
public List<ProductReview> findAllReview() {
return reviewRepository.findAll();
}

@Override
public List<ProductReview> findReviewByProductId(Integer id) {
return reviewRepository.findProductReviewsByProduct_id(id);
Expand Down
Loading