From 2ff933649aa98de350b7396dd3bb5c43e140b40a Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Wed, 19 Jul 2023 13:43:25 -0400 Subject: [PATCH] provide database connection for all gateway --- .../AttorneyRepository.java | 12 +++- .../ClientRepository.java | 16 +++-- src/main/java/gateway/DatabaseConnection.java | 4 ++ .../QuestionGateway.java | 2 +- src/main/java/gateway/QuestionRepo.java | 64 +++++++++++++++++++ .../{usergateway => gateway}/UserGateway.java | 3 +- src/main/java/gateway/UserGatewayFactory.java | 25 ++++++++ .../java/questiongateway/QuestionRepo.java | 4 -- .../java/usergateway/UserGatewayFactory.java | 18 ------ 9 files changed, 119 insertions(+), 29 deletions(-) rename src/main/java/{usergateway => gateway}/AttorneyRepository.java (68%) rename src/main/java/{usergateway => gateway}/ClientRepository.java (68%) create mode 100644 src/main/java/gateway/DatabaseConnection.java rename src/main/java/{questiongateway => gateway}/QuestionGateway.java (96%) create mode 100644 src/main/java/gateway/QuestionRepo.java rename src/main/java/{usergateway => gateway}/UserGateway.java (85%) create mode 100644 src/main/java/gateway/UserGatewayFactory.java delete mode 100644 src/main/java/questiongateway/QuestionRepo.java delete mode 100644 src/main/java/usergateway/UserGatewayFactory.java diff --git a/src/main/java/usergateway/AttorneyRepository.java b/src/main/java/gateway/AttorneyRepository.java similarity index 68% rename from src/main/java/usergateway/AttorneyRepository.java rename to src/main/java/gateway/AttorneyRepository.java index 5c8b03f4..f2a879c5 100644 --- a/src/main/java/usergateway/AttorneyRepository.java +++ b/src/main/java/gateway/AttorneyRepository.java @@ -1,10 +1,16 @@ -package usergateway; +package gateway; import questionentities.Question; import userentities.User; // TODO: implement this class public class AttorneyRepository implements UserGateway{ + final DatabaseConnection databaseConnection; + + public AttorneyRepository(DatabaseConnection databaseConnection) { + this.databaseConnection = databaseConnection; + } + @Override public boolean existsById(int userId) { return false; @@ -27,5 +33,9 @@ public String getPassword(int userId) { @Override public void updateQuestionList(Question question) { + } + @Override + public void addUser(User user) { + } } diff --git a/src/main/java/usergateway/ClientRepository.java b/src/main/java/gateway/ClientRepository.java similarity index 68% rename from src/main/java/usergateway/ClientRepository.java rename to src/main/java/gateway/ClientRepository.java index 77ab7595..5e84c46f 100644 --- a/src/main/java/usergateway/ClientRepository.java +++ b/src/main/java/gateway/ClientRepository.java @@ -1,13 +1,16 @@ -package usergateway; +package gateway; import questionentities.Question; import userentities.User; -import java.util.HashMap; -import java.util.Map; - // TODO: implement this class public class ClientRepository implements UserGateway{ + final DatabaseConnection databaseConnection; + + public ClientRepository(DatabaseConnection databaseConnection) { + this.databaseConnection = databaseConnection; + } + @Override public boolean existsById(int userId) { return false; @@ -32,4 +35,9 @@ public String getPassword(int userId) { public void updateQuestionList(Question question) { } + + @Override + public void addUser(User user) { + + } } diff --git a/src/main/java/gateway/DatabaseConnection.java b/src/main/java/gateway/DatabaseConnection.java new file mode 100644 index 00000000..641d8b84 --- /dev/null +++ b/src/main/java/gateway/DatabaseConnection.java @@ -0,0 +1,4 @@ +package gateway; + +public class DatabaseConnection { +} diff --git a/src/main/java/questiongateway/QuestionGateway.java b/src/main/java/gateway/QuestionGateway.java similarity index 96% rename from src/main/java/questiongateway/QuestionGateway.java rename to src/main/java/gateway/QuestionGateway.java index 1ceef9de..37e6a941 100644 --- a/src/main/java/questiongateway/QuestionGateway.java +++ b/src/main/java/gateway/QuestionGateway.java @@ -1,4 +1,4 @@ -package questiongateway; +package gateway; import questionentities.Post; import questionentities.Question; diff --git a/src/main/java/gateway/QuestionRepo.java b/src/main/java/gateway/QuestionRepo.java new file mode 100644 index 00000000..2c3c94ff --- /dev/null +++ b/src/main/java/gateway/QuestionRepo.java @@ -0,0 +1,64 @@ +package gateway; + +import questionentities.Post; +import questionentities.Question; + +import java.util.List; + +public class QuestionRepo implements QuestionGateway{ + DatabaseConnection databaseConnection; + + public QuestionRepo(DatabaseConnection databaseConnection) { + this.databaseConnection = databaseConnection; + } + + @Override + public void saveQuestion(Question question) { + + } + + @Override + public Question getQuestion(int questionId) { + return null; + } + + @Override + public List getAllQuestion() { + return null; + } + + @Override + public List getNotTakenQuestion() { + return null; + } + + @Override + public List getNotClosedQuestion() { + return null; + } + + @Override + public void updateIsTaken(int questionId, boolean iaTaken) { + + } + + @Override + public void updateTakenByAttorney(int questionId, boolean attorneyId) { + + } + + @Override + public void updateIsClose(int questionId, boolean isClose) { + + } + + @Override + public void updateRating(int questionId, int rating) { + + } + + @Override + public void updatePosts(int questionId, Post post) { + + } +} diff --git a/src/main/java/usergateway/UserGateway.java b/src/main/java/gateway/UserGateway.java similarity index 85% rename from src/main/java/usergateway/UserGateway.java rename to src/main/java/gateway/UserGateway.java index adb10736..fd560062 100644 --- a/src/main/java/usergateway/UserGateway.java +++ b/src/main/java/gateway/UserGateway.java @@ -1,4 +1,4 @@ -package usergateway; +package gateway; import userentities.User; import questionentities.Question; @@ -9,4 +9,5 @@ public interface UserGateway { User getUser(int userId); String getPassword(int userId); void updateQuestionList(Question question); + void addUser(User user); } diff --git a/src/main/java/gateway/UserGatewayFactory.java b/src/main/java/gateway/UserGatewayFactory.java new file mode 100644 index 00000000..30899fe4 --- /dev/null +++ b/src/main/java/gateway/UserGatewayFactory.java @@ -0,0 +1,25 @@ +package gateway; + +public class UserGatewayFactory { + final DatabaseConnection databaseConnection; + + public UserGatewayFactory(DatabaseConnection databaseConnection) { + this.databaseConnection = databaseConnection; + } + + public UserGateway createUserGateway(int userId) { + UserGateway userGateway; + + if (isClient(userId)) { + userGateway = new ClientRepository(databaseConnection); + } else { + userGateway = new AttorneyRepository(databaseConnection); + } + return userGateway; + } + + // TODO: implement this method + private static boolean isClient(int userId) { + return false; + } +} diff --git a/src/main/java/questiongateway/QuestionRepo.java b/src/main/java/questiongateway/QuestionRepo.java deleted file mode 100644 index 48728846..00000000 --- a/src/main/java/questiongateway/QuestionRepo.java +++ /dev/null @@ -1,4 +0,0 @@ -package questiongateway; - -public class QuestionRepo { -} diff --git a/src/main/java/usergateway/UserGatewayFactory.java b/src/main/java/usergateway/UserGatewayFactory.java deleted file mode 100644 index 1cbd5950..00000000 --- a/src/main/java/usergateway/UserGatewayFactory.java +++ /dev/null @@ -1,18 +0,0 @@ -package usergateway; - -public class UserGatewayFactory { - public UserGateway createUserGateway(int userId) { - UserGateway userGateway; - if (isClient(userId)) { - userGateway = new ClientRepository(); - } else { - userGateway = new AttorneyRepository(); - } - return userGateway; - } - - // TODO: implement this method - private static boolean isClient(int userId) { - return false; - } -}