Рефакторинг

This commit is contained in:
Mark Struchkov 2019-05-26 22:15:47 +03:00
parent dfc4f36e55
commit 8e5edc1e9e
17 changed files with 53 additions and 30 deletions

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.core.domain;
import org.sadtech.bot.core.domain.content.GeoCoordinate;
import org.sadtech.bot.core.domain.content.attachment.GeoCoordinate;
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
import java.util.Objects;

View File

@ -1,6 +1,5 @@
package org.sadtech.bot.core.domain;
package org.sadtech.bot.core.domain.content;
import org.sadtech.bot.core.domain.content.Content;
import org.sadtech.bot.core.exception.AppBotException;
public class EmptyContent extends Content {

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.core.domain.content;
import org.sadtech.bot.core.domain.attachment.Attachment;
import org.sadtech.bot.core.domain.content.attachment.Attachment;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.core.domain.attachment;
package org.sadtech.bot.core.domain.content.attachment;
public abstract class Attachment {

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.core.domain.attachment;
package org.sadtech.bot.core.domain.content.attachment;
public enum AttachmentType {

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.core.domain.attachment;
package org.sadtech.bot.core.domain.content.attachment;
import java.net.URL;
import java.util.Objects;

View File

@ -1,6 +1,4 @@
package org.sadtech.bot.core.domain.attachment;
import org.sadtech.bot.core.domain.content.GeoCoordinate;
package org.sadtech.bot.core.domain.content.attachment;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.core.domain.content;
package org.sadtech.bot.core.domain.content.attachment;
public class GeoCoordinate {

View File

@ -2,6 +2,6 @@ package org.sadtech.bot.core.domain.money;
public enum AccountStatus {
EXPOSED, CLOSED, CANCELLED, EXCEPTION;
EXPOSED, CLOSED, CANCELLED, EXCEPTION
}

View File

@ -0,0 +1,7 @@
package org.sadtech.bot.core.exception;
public class AccessException extends AppBotException {
public AccessException(Integer code, String message) {
super(code, message);
}
}

View File

@ -0,0 +1,7 @@
package org.sadtech.bot.core.exception;
public class NotFoundException extends AppBotException {
public NotFoundException(Integer code, String message) {
super(code, message);
}
}

View File

@ -1,31 +1,48 @@
package org.sadtech.bot.core.repository.impl;
import org.sadtech.bot.core.domain.money.Account;
import org.sadtech.bot.core.exception.AccessException;
import org.sadtech.bot.core.exception.NotFoundException;
import org.sadtech.bot.core.exception.PaymentException;
import org.sadtech.bot.core.repository.AccountRepository;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class AccountRepositoryMap implements AccountRepository {
private final Map<Integer, Account> saveMap = new HashMap<>();
private Integer id = 0;
private Integer id = 1;
@Override
public Integer add(Account account) {
if (check(account.getId())) {
account.setId(id);
saveMap.put(id, account);
return id++;
} else {
throw new AccessException(312, "Счет " + account.getId() + " уже существует");
}
}
@Override
public void edit(Integer accountId, Account account) {
if (check(id)) {
account.setId(accountId);
saveMap.put(accountId, account);
} else {
throw new NotFoundException(491, "Счет " + accountId + " не найден");
}
}
@Override
public Account findById(Integer accountId) {
return saveMap.get(accountId);
return Optional.ofNullable(saveMap.get(accountId)).orElseThrow(() -> new PaymentException(43, "Счет " + accountId + " не найден"));
}
private boolean check(Integer id) {
return saveMap.containsKey(id);
}
}

View File

@ -1,9 +1,11 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Content;
import java.time.LocalDateTime;
import java.util.List;
public interface EventService<T> {
public interface EventService<T extends Content> {
void add(T event);

View File

@ -1,7 +1,8 @@
package org.sadtech.bot.core.service.filter;
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Content;
@FunctionalInterface
public interface Filter<T extends Content> {
void processing(T content);

View File

@ -1,7 +1,6 @@
package org.sadtech.bot.core.service;
import com.google.gson.JsonObject;
import org.sadtech.bot.core.repository.EventRepository;
import java.util.Queue;
@ -13,6 +12,4 @@ public interface RawEventService {
Queue<JsonObject> getJsonObjects();
EventRepository getEventRepository();
}

View File

@ -35,9 +35,4 @@ public class RawEventServiceImpl implements RawEventService {
return eventRepository.getEventQueue();
}
@Override
public EventRepository getEventRepository() {
return eventRepository;
}
}

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.core.utils;
import org.sadtech.bot.core.domain.EmptyContent;
import org.sadtech.bot.core.domain.content.EmptyContent;
public class Contents {