Рефакторинг
This commit is contained in:
parent
dfc4f36e55
commit
8e5edc1e9e
@ -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;
|
||||||
|
@ -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 {
|
@ -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;
|
||||||
|
@ -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 {
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -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;
|
@ -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;
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.sadtech.bot.core.exception;
|
||||||
|
|
||||||
|
public class AccessException extends AppBotException {
|
||||||
|
public AccessException(Integer code, String message) {
|
||||||
|
super(code, message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.sadtech.bot.core.exception;
|
||||||
|
|
||||||
|
public class NotFoundException extends AppBotException {
|
||||||
|
public NotFoundException(Integer code, String message) {
|
||||||
|
super(code, message);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
@ -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();
|
|
||||||
|
|
||||||
}
|
}
|
@ -35,9 +35,4 @@ public class RawEventServiceImpl implements RawEventService {
|
|||||||
return eventRepository.getEventQueue();
|
return eventRepository.getEventQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EventRepository getEventRepository() {
|
|
||||||
return eventRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user