Skip to content

Commit

Permalink
provide database connection for all gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
YifanLiu2 committed Jul 19, 2023
1 parent d0e4054 commit 2ff9336
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,5 +33,9 @@ public String getPassword(int userId) {
@Override
public void updateQuestionList(Question question) {

}
@Override
public void addUser(User user) {

}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -32,4 +35,9 @@ public String getPassword(int userId) {
public void updateQuestionList(Question question) {

}

@Override
public void addUser(User user) {

}
}
4 changes: 4 additions & 0 deletions src/main/java/gateway/DatabaseConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gateway;

public class DatabaseConnection {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package questiongateway;
package gateway;

import questionentities.Post;
import questionentities.Question;
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/gateway/QuestionRepo.java
Original file line number Diff line number Diff line change
@@ -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<Question> getAllQuestion() {
return null;
}

@Override
public List<Question> getNotTakenQuestion() {
return null;
}

@Override
public List<Question> 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) {

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package usergateway;
package gateway;

import userentities.User;
import questionentities.Question;
Expand All @@ -9,4 +9,5 @@ public interface UserGateway {
User getUser(int userId);
String getPassword(int userId);
void updateQuestionList(Question question);
void addUser(User user);
}
25 changes: 25 additions & 0 deletions src/main/java/gateway/UserGatewayFactory.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 0 additions & 4 deletions src/main/java/questiongateway/QuestionRepo.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/usergateway/UserGatewayFactory.java

This file was deleted.

0 comments on commit 2ff9336

Please sign in to comment.