Skip to content

Commit

Permalink
MessageService implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 30, 2024
1 parent 10024e0 commit 44017ae
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/java/Service/MessageService.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 44017ae

Please sign in to comment.