Начал работу над обработкой комментариев
This commit is contained in:
parent
3b29921d2e
commit
85a9849c0a
@ -1,13 +1,28 @@
|
||||
package org.sadtech.vkbot.core.distribution.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.vk.api.sdk.objects.wall.WallComment;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.sadtech.vkbot.core.distribution.EventDistributable;
|
||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||
import org.sadtech.vkbot.core.entity.Comment;
|
||||
import org.sadtech.vkbot.core.service.distribution.CommentService;
|
||||
|
||||
public class CommentSubscriber implements EventSubscribe<Comment> {
|
||||
|
||||
public class CommentSubscriber implements EventSubscribe<JsonObject> {
|
||||
|
||||
public static final Logger log = Logger.getLogger(CommentSubscriber.class);
|
||||
|
||||
private CommentService commentService;
|
||||
|
||||
public CommentSubscriber(EventDistributable distributable, CommentService commentService) {
|
||||
distributable.registerSubscriber("wall_reply_new", this);
|
||||
this.commentService = commentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Comment object) {
|
||||
|
||||
public void update(JsonObject object) {
|
||||
Gson gson = new Gson();
|
||||
WallComment wallComment = gson.fromJson(object, WallComment.class);
|
||||
log.info(wallComment);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package org.sadtech.vkbot.core.distribution.impl;
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.sadtech.vkbot.core.distribution.EventDistributable;
|
||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||
import org.sadtech.vkbot.core.service.handlers.MailService;
|
||||
import org.sadtech.vkbot.core.service.distribution.MailService;
|
||||
|
||||
public class MailChatSubscriber implements EventSubscribe<Message> {
|
||||
|
||||
|
@ -6,7 +6,7 @@ import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.sadtech.vkbot.core.distribution.EventDistributable;
|
||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||
import org.sadtech.vkbot.core.service.handlers.MailService;
|
||||
import org.sadtech.vkbot.core.service.distribution.MailService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -3,7 +3,7 @@ package org.sadtech.vkbot.core.distribution.impl;
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||
import org.sadtech.vkbot.core.service.handlers.MailService;
|
||||
import org.sadtech.vkbot.core.service.distribution.MailService;
|
||||
|
||||
public class TerminalSubscriber implements EventSubscribe<Message> {
|
||||
|
||||
|
@ -1,4 +1,10 @@
|
||||
package org.sadtech.vkbot.core.entity;
|
||||
|
||||
public class Comment {
|
||||
|
||||
private Integer postId;
|
||||
private Integer fromId;
|
||||
private String text;
|
||||
private Integer data;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.vkbot.core.repository;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.Comment;
|
||||
|
||||
public interface CommentRepository {
|
||||
|
||||
void add(Comment comment);
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package org.sadtech.vkbot.core.repository.impl;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.Comment;
|
||||
import org.sadtech.vkbot.core.repository.CommentRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentRepositoryList implements CommentRepository {
|
||||
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void add(Comment comment) {
|
||||
comments.add(comment);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.sadtech.vkbot.core.service.distribution;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.Comment;
|
||||
import org.sadtech.vkbot.core.service.distribution.impl.EventService;
|
||||
|
||||
public interface CommentService extends EventService<Comment> {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.sadtech.vkbot.core.service.distribution;
|
||||
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.sadtech.vkbot.core.entity.Mail;
|
||||
import org.sadtech.vkbot.core.service.distribution.impl.EventService;
|
||||
|
||||
public interface MailService extends EventService<Mail>, SortEventService<Mail> {
|
||||
|
||||
void add(Message message);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.core.service.handlers;
|
||||
package org.sadtech.vkbot.core.service.distribution;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.sadtech.vkbot.core.service.distribution.impl;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.Comment;
|
||||
import org.sadtech.vkbot.core.repository.CommentRepository;
|
||||
import org.sadtech.vkbot.core.service.distribution.CommentService;
|
||||
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
|
||||
private CommentRepository commentRepository;
|
||||
|
||||
public CommentServiceImpl(CommentRepository commentRepository) {
|
||||
this.commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Comment comment) {
|
||||
commentRepository.add(comment);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.vkbot.core.service.distribution.impl;
|
||||
|
||||
public interface EventService<T> {
|
||||
|
||||
void add(T event);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.core.service.handlers.impl;
|
||||
package org.sadtech.vkbot.core.service.distribution.impl;
|
||||
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -7,7 +7,7 @@ import org.sadtech.vkbot.core.entity.Person;
|
||||
import org.sadtech.vkbot.core.repository.MailRepository;
|
||||
import org.sadtech.vkbot.core.repository.impl.MailRepositoryList;
|
||||
import org.sadtech.vkbot.core.service.PersonService;
|
||||
import org.sadtech.vkbot.core.service.handlers.MailService;
|
||||
import org.sadtech.vkbot.core.service.distribution.MailService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
@ -1,12 +0,0 @@
|
||||
package org.sadtech.vkbot.core.service.handlers;
|
||||
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import org.sadtech.vkbot.core.entity.Mail;
|
||||
|
||||
public interface MailService extends SortEventService<Mail> {
|
||||
|
||||
void add(Mail mail);
|
||||
|
||||
void add(Message message);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user