Skip to content

Commit

Permalink
Fixed readme.md
Browse files Browse the repository at this point in the history
Removed unnesessary configurations
Removed unnesessary dependencies
Minor refactoring
  • Loading branch information
muchnik committed Sep 1, 2019
1 parent 96881c8 commit c6b2edb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 60 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

| Метод | Тело запроса | Адрес | Описание |
| --------| ----------------------- | ----------------------------------------------------------- | -------------------------------- |
Expand Down
17 changes: 1 addition & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.7.RELEASE</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -60,7 +60,6 @@
</dependency>

<!-- Utility -->

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -80,25 +79,11 @@
</dependency>

<!-- Testing -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>[email protected]</b>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,31 @@ public abstract class BaseDetailsService<Type extends IDetails, Repository exten

@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public Type getDetails(@NonNull final String id) {
return repository.findById(id).orElseThrow(() -> 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)
public List<Type> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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!"));
}
}

0 comments on commit c6b2edb

Please sign in to comment.