Рефакторинг

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; 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 org.sadtech.bot.core.domain.keyboard.KeyBoard;
import java.util.Objects; 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; import org.sadtech.bot.core.exception.AppBotException;
public class EmptyContent extends Content { public class EmptyContent extends Content {

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.core.domain.content; 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.time.LocalDateTime;
import java.util.List; 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 { 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 { 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.net.URL;
import java.util.Objects; import java.util.Objects;

View File

@ -1,6 +1,4 @@
package org.sadtech.bot.core.domain.attachment; package org.sadtech.bot.core.domain.content.attachment;
import org.sadtech.bot.core.domain.content.GeoCoordinate;
import java.util.Objects; 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 { public class GeoCoordinate {

View File

@ -2,6 +2,6 @@ package org.sadtech.bot.core.domain.money;
public enum AccountStatus { 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; package org.sadtech.bot.core.repository.impl;
import org.sadtech.bot.core.domain.money.Account; 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 org.sadtech.bot.core.repository.AccountRepository;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class AccountRepositoryMap implements AccountRepository { public class AccountRepositoryMap implements AccountRepository {
private final Map<Integer, Account> saveMap = new HashMap<>(); private final Map<Integer, Account> saveMap = new HashMap<>();
private Integer id = 0; private Integer id = 1;
@Override @Override
public Integer add(Account account) { public Integer add(Account account) {
account.setId(id); if (check(account.getId())) {
saveMap.put(id, account); account.setId(id);
return id++; saveMap.put(id, account);
return id++;
} else {
throw new AccessException(312, "Счет " + account.getId() + " уже существует");
}
} }
@Override @Override
public void edit(Integer accountId, Account account) { public void edit(Integer accountId, Account account) {
account.setId(accountId); if (check(id)) {
saveMap.put(accountId, account); account.setId(accountId);
saveMap.put(accountId, account);
} else {
throw new NotFoundException(491, "Счет " + accountId + " не найден");
}
} }
@Override @Override
public Account findById(Integer accountId) { 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; package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Content;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public interface EventService<T> { public interface EventService<T extends Content> {
void add(T event); 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; import org.sadtech.bot.core.domain.content.Content;
@FunctionalInterface
public interface Filter<T extends Content> { public interface Filter<T extends Content> {
void processing(T content); void processing(T content);

View File

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

View File

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

View File

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