Начал работу над обработкой комментариев

This commit is contained in:
Mark Struchkov 2019-02-07 00:05:10 +03:00
parent 3b29921d2e
commit 85a9849c0a
14 changed files with 105 additions and 23 deletions

View File

@ -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);
}
}

View File

@ -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> {

View File

@ -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;

View File

@ -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> {

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
package org.sadtech.vkbot.core.repository;
import org.sadtech.vkbot.core.entity.Comment;
public interface CommentRepository {
void add(Comment comment);
}

View File

@ -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);
}
}

View File

@ -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> {
}

View File

@ -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);
}

View File

@ -1,4 +1,4 @@
package org.sadtech.vkbot.core.service.handlers;
package org.sadtech.vkbot.core.service.distribution;
import java.util.List;

View File

@ -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);
}
}

View File

@ -0,0 +1,7 @@
package org.sadtech.vkbot.core.service.distribution.impl;
public interface EventService<T> {
void add(T event);
}

View File

@ -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;

View File

@ -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);
}