Skip to content

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
suoapvs committed Jun 20, 2017
1 parent 3b74223 commit 5dc16e8
Show file tree
Hide file tree
Showing 25 changed files with 274 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see MainRepository
* @see Category
*/
public interface CategoryRepository extends MainRepository<Category, Long> {
public interface CategoryRepository extends MainRepository<Category> {
/**
* Возвращает категорию из базы данных, у которой совпадает параметр url.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ua.com.alexcoffee.repository;

import org.springframework.data.repository.NoRepositoryBean;
import ua.com.alexcoffee.model.Model;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -14,7 +15,6 @@
* того типа которым есть id нашей сущности (обязательно).
*
* @param <T> Тип (класс) сущности.
* @param <E> Тип id сущности.
* @author Yurii Salimov ([email protected])
* @version 1.2
* @see CategoryRepository
Expand All @@ -27,5 +27,6 @@
* @see UserRepository
* @see Model
*/
public interface MainRepository<T extends Model, E extends Number> extends JpaRepository<T, E> {
@NoRepositoryBean
public interface MainRepository<T extends Model> extends JpaRepository<T, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see MainRepository
* @see Order
*/
public interface OrderRepository extends MainRepository<Order, Long> {
public interface OrderRepository extends MainRepository<Order> {
/**
* Возвращает заказ из базы даных, у которого совпадает
* уникальный номером с значением входящего параметра.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see MainRepository
* @see Photo
*/
public interface PhotoRepository extends MainRepository<Photo, Long> {
public interface PhotoRepository extends MainRepository<Photo> {
/**
* Возвращает объект-изображение из базы даных, у которого совпадает уникальное
* название с значением входящего параметра.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @see MainRepository
* @see Product
*/
public interface ProductRepository extends MainRepository<Product, Long> {
public interface ProductRepository extends MainRepository<Product> {
/**
* Возвращает товар из базы данных, у которого совпадает параметр url.
*
Expand Down Expand Up @@ -45,6 +45,22 @@ public interface ProductRepository extends MainRepository<Product, Long> {
*/
void deleteByArticle(int article);

/**
* Удаляет товар из базы данных, которые пренадлежат категории
* с уникальным URL - входным параметром.
*
* @param url URL категории.
*/
void deleteByCategoryUrl(String url);

/**
* Удаляет товар из базы данных, которые пренадлежат категории
* с уникальным кодом - входным параметром.
*
* @param id Код категории.
*/
void deleteByCategoryId(long id);

/**
* Возвращает список товаров, которые пренадлежат категории
* с уникальным кодом - входным параметром.
Expand All @@ -53,4 +69,13 @@ public interface ProductRepository extends MainRepository<Product, Long> {
* @return Объект типа {@link List} - список товаров.
*/
List<Product> findByCategoryId(long id);

/**
* Возвращает список товаров, которые пренадлежат категории
* с уникальным URL - входным параметром.
*
* @param url URL категории.
* @return Объект типа {@link List} - список товаров.
*/
List<Product> findByCategoryUrl(String url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @see MainRepository
* @see Role
*/
public interface RoleRepository extends MainRepository<Role, Long> {
public interface RoleRepository extends MainRepository<Role> {
/**
* Возвращает роль из базы даных по названию, которое может принимать
* одно из значений перечисления {@link RoleEnum}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
* @see MainRepository
* @see SalePosition
*/
public interface SalePositionRepository extends MainRepository<SalePosition, Long> {
public interface SalePositionRepository extends MainRepository<SalePosition> {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.com.alexcoffee.dao.interfaces;
package ua.com.alexcoffee.repository;

import ua.com.alexcoffee.model.SalePosition;
import ua.com.alexcoffee.model.ShoppingCart;
Expand All @@ -10,10 +10,10 @@
*
* @author Yurii Salimov ([email protected])
* @version 1.2
* @see ua.com.alexcoffee.dao.impl.ShoppingCartDAOImpl
* @see ShoppingCartRepositoryImpl
* @see SalePosition
*/
public interface ShoppingCartDAO {
public interface ShoppingCartRepository {
/**
* Возвращает список всех торговых позиций в корзине.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package ua.com.alexcoffee.dao.impl;
package ua.com.alexcoffee.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Repository;
import ua.com.alexcoffee.dao.interfaces.ShoppingCartDAO;
import ua.com.alexcoffee.model.SalePosition;
import ua.com.alexcoffee.model.ShoppingCart;

import java.util.List;

/**
* Класс реализует методы интерфейса {@link ShoppingCartDAO} для работы с корзиной.
* Класс реализует методы интерфейса {@link ShoppingCartRepository} для работы с корзиной.
*
* @author Yurii Salimov ([email protected])
* @version 1.2
* @see ShoppingCartDAO
* @see ShoppingCartRepository
* @see ShoppingCart
*/
@Repository
@ComponentScan(basePackages = "ua.com.alexcoffee.model")
public final class ShoppingCartDAOImpl implements ShoppingCartDAO {
public final class ShoppingCartRepositoryImpl implements ShoppingCartRepository {
/**
* Объект корзина, в которой
* хранятся торговые позиции клиента.
Expand All @@ -35,7 +34,7 @@ public final class ShoppingCartDAOImpl implements ShoppingCartDAO {
* корзиной.
*/
@Autowired
public ShoppingCartDAOImpl(final ShoppingCart shoppingCart) {
public ShoppingCartRepositoryImpl(final ShoppingCart shoppingCart) {
this.shoppingCart = shoppingCart;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @see MainRepository
* @see Status
*/
public interface StatusRepository extends MainRepository<Status, Long> {
public interface StatusRepository extends MainRepository<Status> {
/**
* Возвращает статус из базы даных по названию, которое может принимать
* одно из значений перечисления {@link StatusEnum}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* @see MainRepository
* @see User
*/
public interface UserRepository
extends MainRepository<User, Long> {
public interface UserRepository extends MainRepository<User> {
/**
* Возвращает пользователя из базы даных, у которого совпадает
* имя с значением входящего параметра.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ua.com.alexcoffee.dao.interfaces.CategoryDAO;
import ua.com.alexcoffee.model.Category;
import ua.com.alexcoffee.exception.BadRequestException;
import ua.com.alexcoffee.exception.WrongInformationException;
import ua.com.alexcoffee.model.Category;
import ua.com.alexcoffee.repository.CategoryRepository;
import ua.com.alexcoffee.service.interfaces.CategoryService;

import static org.apache.commons.lang3.StringUtils.isBlank;
Expand All @@ -28,29 +28,30 @@
* @see MainServiceImpl
* @see CategoryService
* @see Category
* @see CategoryDAO
* @see CategoryRepository
*/
@Service
@ComponentScan(basePackages = "ua.com.alexcoffee.dao")
@ComponentScan(basePackages = "ua.com.alexcoffee.repository")
public final class CategoryServiceImpl extends MainServiceImpl<Category> implements CategoryService {
/**
* Реализация интерфейса {@link CategoryDAO} для работы категорий с базой данных.
* Реализация интерфейса {@link CategoryRepository}
* для работы категорий с базой данных.
*/
private final CategoryDAO dao;
private final CategoryRepository repository;

/**
* Конструктор для инициализации основных переменных сервиса.
* Помечаный аннотацией @Autowired, которая позволит Spring
* автоматически инициализировать объект.
*
* @param dao Реализация интерфейса {@link CategoryDAO}
* для работы категорий с базой данных.
* @param repository Реализация интерфейса {@link CategoryRepository}
* для работы категорий с базой данных.
*/
@Autowired
@SuppressWarnings("SpringJavaAutowiringInspection")
public CategoryServiceImpl(final CategoryDAO dao) {
super(dao);
this.dao = dao;
public CategoryServiceImpl(final CategoryRepository repository) {
super(repository);
this.repository = repository;
}

/**
Expand All @@ -70,7 +71,7 @@ public Category get(final String url) throws WrongInformationException, BadReque
if (isBlank(url)) {
throw new WrongInformationException("No category URL!");
}
final Category category = this.dao.get(url);
final Category category = this.repository.findByUrl(url);
if (category == null) {
throw new BadRequestException("Can't find category by url " + url + "!");
}
Expand All @@ -90,6 +91,6 @@ public void remove(final String url) throws WrongInformationException {
if (isBlank(url)) {
throw new WrongInformationException("No category URL!");
}
this.dao.remove(url);
this.repository.deleteByUrl(url);
}
}
Loading

0 comments on commit 5dc16e8

Please sign in to comment.