Рефакторинг
This commit is contained in:
parent
dfc4f36e55
commit
8e5edc1e9e
@ -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;
|
||||
|
@ -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 {
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.domain.attachment;
|
||||
package org.sadtech.bot.core.domain.content.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 {
|
||||
|
@ -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;
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
package org.sadtech.bot.core.domain.content.attachment;
|
||||
|
||||
public class GeoCoordinate {
|
||||
|
@ -2,6 +2,6 @@ package org.sadtech.bot.core.domain.money;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
@ -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();
|
||||
|
||||
}
|
@ -35,9 +35,4 @@ public class RawEventServiceImpl implements RawEventService {
|
||||
return eventRepository.getEventQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventRepository getEventRepository() {
|
||||
return eventRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user