From 44017ae4f78b05b94d986e6b2271e0c2841e5530 Mon Sep 17 00:00:00 2001 From: Jon Sundin Date: Tue, 30 Jan 2024 00:40:13 +0000 Subject: [PATCH] MessageService implementation --- src/main/java/Service/MessageService.java | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/Service/MessageService.java diff --git a/src/main/java/Service/MessageService.java b/src/main/java/Service/MessageService.java new file mode 100644 index 0000000..c802e20 --- /dev/null +++ b/src/main/java/Service/MessageService.java @@ -0,0 +1,36 @@ +package Service; + +import Model.Message; +import DAO.MessageDAO; +import DAO.AccountDAO; + +public class MessageService { + MessageDAO messageDAO; + AccountDAO accountDAO; + + public MessageService() { + messageDAO = new MessageDAO(); + accountDAO = new AccountDAO(); + } + + public MessageService(MessageDAO messageDAO){ + this.messageDAO = messageDAO; + accountDAO = new AccountDAO(); + } + + public MessageService(MessageDAO messageDAO, AccountDAO accountDAO) { + this.messageDAO = messageDAO; + this.accountDAO = accountDAO; + } + + public boolean messageIsValid(int posted_by, String message_text) { + if (message_text.length() == 0 || message_text.length() > 255) return false; + else if (accountDAO.findAccountByAccountId(posted_by) == null) return false; + else return true; + } + + public Message insertMessage(int posted_by, String message_text, long time_posted_epoch) { + return messageDAO.insertMessage(posted_by, message_text, time_posted_epoch); + } + +}