diff --git a/README.md b/README.md index 5a465b0..87645f1 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,18 @@ ## Заметки 1. При старте приложения база наполняется тестовыми данными +2. Используется Java 8 ## Запуск 1. Скомпилировать проект (включить Annotation Processor для Lombok и поставить Lombok Plugin для IDEA) 2. Запустить из IDE через MobileServicesApplication#main или после сборки из target с помощью java -jar mobile-services-1.0.jar ## Использование -1. WebUI для встроенной базы данных: http://localhost:8080/h2-console/ -JDBC Url: jdbc:h2:mem:test -User: sa -Password: - -2. API доступно на порту 8080 +- WebUI для встроенной базы данных: http://localhost:8080/h2-console/ + - JDBC Url: jdbc:h2:mem:test + - User: sa + - Password: +- API доступно на порту 8080 | Метод | Тело запроса | Адрес | Описание | | --------| ----------------------- | ----------------------------------------------------------- | -------------------------------- | diff --git a/pom.xml b/pom.xml index f2bc9ee..7b699dc 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.2.RELEASE + 2.1.7.RELEASE @@ -60,7 +60,6 @@ - org.projectlombok lombok @@ -80,25 +79,11 @@ - org.springframework.boot spring-boot-starter-test test - - - org.powermock - powermock-module-junit4 - 2.0.2 - test - - - org.powermock - powermock-api-mockito2 - 2.0.2 - test - diff --git a/src/main/java/ru/muchnik/yota/mobileservices/MobileServicesApplication.java b/src/main/java/ru/muchnik/yota/mobileservices/MobileServicesApplication.java index 394df08..b1b7ff3 100644 --- a/src/main/java/ru/muchnik/yota/mobileservices/MobileServicesApplication.java +++ b/src/main/java/ru/muchnik/yota/mobileservices/MobileServicesApplication.java @@ -16,6 +16,7 @@ import java.util.Arrays; /** + * Basic CRUD service that allows to work with mobile phone services (like internet traffic / minutes) * Application for "YOTA" test task, see readme.md for more information * * @author Muchnik Andrey muchnik.ak@gmail.com diff --git a/src/main/java/ru/muchnik/yota/mobileservices/configuration/AspectJConfiguration.java b/src/main/java/ru/muchnik/yota/mobileservices/configuration/AspectJConfiguration.java deleted file mode 100644 index 65a2d2a..0000000 --- a/src/main/java/ru/muchnik/yota/mobileservices/configuration/AspectJConfiguration.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.muchnik.yota.mobileservices.configuration; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; - -/** - * Common configuration for aspectj - * - * @apiNote needed to exclude autoconfiguration in test environment - */ -@Configuration -@EnableAspectJAutoProxy -public class AspectJConfiguration { -} diff --git a/src/main/java/ru/muchnik/yota/mobileservices/configuration/WebMvcConfiguration.java b/src/main/java/ru/muchnik/yota/mobileservices/configuration/WebMvcConfiguration.java deleted file mode 100644 index fd9786e..0000000 --- a/src/main/java/ru/muchnik/yota/mobileservices/configuration/WebMvcConfiguration.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.muchnik.yota.mobileservices.configuration; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -/** - * Common configuration for web mvc - * - * @apiNote needed to exclude autoconfiguration in test environment - */ -@Configuration -@EnableWebMvc -public class WebMvcConfiguration { -} diff --git a/src/main/java/ru/muchnik/yota/mobileservices/service/BaseDetailsService.java b/src/main/java/ru/muchnik/yota/mobileservices/service/BaseDetailsService.java index feac291..2fd8f64 100644 --- a/src/main/java/ru/muchnik/yota/mobileservices/service/BaseDetailsService.java +++ b/src/main/java/ru/muchnik/yota/mobileservices/service/BaseDetailsService.java @@ -19,16 +19,14 @@ public abstract class BaseDetailsService new NotFoundException("Details for package is not found!")); + return doGetDetails(id); } @Transactional(isolation = Isolation.READ_COMMITTED) public void updateAmount(@NonNull final String detailsId, final int addition) { - Type details = getDetails(detailsId); + Type details = doGetDetails(detailsId); doValidate(details, addition); - int amountLeft = details.getAmountLeft(); - amountLeft += addition; - details.setAmountLeft(amountLeft); + doUpdateAmount(addition, details); } @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) @@ -36,6 +34,16 @@ public List getAllActivePackages(@NonNull final String number) { return repository.findAllActive(number, LocalDateTime.now()); } + private Type doGetDetails(@NonNull final String id) { + return repository.findById(id).orElseThrow(() -> new NotFoundException("Details for package is not found!")); + } + + private void doUpdateAmount(final int addition, final Type details) { + int amountLeft = details.getAmountLeft(); + amountLeft += addition; + details.setAmountLeft(amountLeft); + } + private void doValidate(@NonNull final Type details, final int addition) { doValidateExpiration(details); doValidateAddition(details, addition); diff --git a/src/main/java/ru/muchnik/yota/mobileservices/service/SimCardService.java b/src/main/java/ru/muchnik/yota/mobileservices/service/SimCardService.java index 04e8c61..3f04d11 100644 --- a/src/main/java/ru/muchnik/yota/mobileservices/service/SimCardService.java +++ b/src/main/java/ru/muchnik/yota/mobileservices/service/SimCardService.java @@ -24,17 +24,17 @@ public class SimCardService { @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public SimCard getSimCard(@NonNull final String number) { - return simCardRepository.getByNumber(number).orElseThrow(() -> new NotFoundException("Sim Card is not found!")); + return doGetSimCard(number); } @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public boolean getSimCardStatus(@NonNull final String number) { - return getSimCard(number).isActive(); + return doGetSimCard(number).isActive(); } @Transactional(isolation = Isolation.READ_COMMITTED) public SimCard updateSimCardStatus(@NonNull final String number, final boolean status) { - SimCard simCard = getSimCard(number); + SimCard simCard = doGetSimCard(number); simCard.setActive(status); return simCard; } @@ -52,7 +52,7 @@ public MinutesDetails addPackageOfMinutesToSimCard(@NonNull final String number, @NonNull final String basePackageId, final int minutes, final int daysToLive) { - final SimCard simCard = getSimCard(number); + final SimCard simCard = doGetSimCard(number); final MinutesPackageCatalog basePackage = minutesPackageService.getPackage(basePackageId); final MinutesDetails details = new MinutesDetails(basePackage, minutes, daysToLive); details.setSimCard(simCard); @@ -73,11 +73,15 @@ public TrafficDetails addTrafficPackageToSimCard(@NonNull final String number, @NonNull final String basePackageId, final int traffic, final int daysToLive) { - final SimCard simCard = getSimCard(number); + final SimCard simCard = doGetSimCard(number); final TrafficPackageCatalog basePackage = trafficPackageService.getPackage(basePackageId); final TrafficDetails details = new TrafficDetails(basePackage, traffic, daysToLive); details.setSimCard(simCard); simCard.getTrafficDetails().add(details); return details; } + + private SimCard doGetSimCard(@NonNull final String number) { + return simCardRepository.getByNumber(number).orElseThrow(() -> new NotFoundException("Sim Card is not found!")); + } }