Skip to content

Commit

Permalink
add attorney registration
Browse files Browse the repository at this point in the history
  • Loading branch information
YifanLiu2 committed Aug 15, 2023
1 parent 7176ecd commit 179f38d
Show file tree
Hide file tree
Showing 22 changed files with 629 additions and 303 deletions.
11 changes: 7 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import adapters.controllers.*;
import adapters.presenters.*;
import entities.factories.AttorneyFactory;
import infrastructure.screens.UIFactory;
import usecases.gateway.*;
import usecases.inputboundary.*;
Expand All @@ -9,7 +10,6 @@
import infrastructure.database.*;
import infrastructure.screens.utils.UIDesign;
import infrastructure.screens.utils.UIManager;
import entities.user.Attorney;
import entities.factories.ClientFactory;
import entities.factories.PostFactory;
import entities.factories.QuestionFactory;
Expand All @@ -24,6 +24,7 @@ public static void main(String[] args) {
ClientGateway clientGateway = new ClientRepository();
AttorneyGateway attorneyGateway = new AttorneyRepository();
ClientFactory clientFactory = new ClientFactory();
AttorneyFactory attorneyFactory = new AttorneyFactory();

QuestionFactory questionFactory = new QuestionFactory();
QuestionGateway questionGateway = new QuestionRepo();
Expand Down Expand Up @@ -63,8 +64,10 @@ public static void main(String[] args) {
UserLoginInputBoundary userLoginInteractor = new UserLoginInteractor(gatewayFactory, homePageOutputBoundary);
UserLoginControl loginControl = new UserLoginControl(userLoginInteractor);

UserRegisterInputBoundary clientRegisterInteractor = new ClientRegisterInteractor(clientGateway, clientFactory, registerOutputBoundary);
ClientRegisterControl registerControl = new ClientRegisterControl(clientRegisterInteractor);
UserRegisterInputBoundary clientRegisterInteractor = new ClientRegisterInteractor(clientGateway, registerOutputBoundary, clientFactory);
UserRegisterInputBoundary attorneyRegisterInteractor = new AttorneyRegisterInteractor(attorneyGateway, registerOutputBoundary, attorneyFactory);
RegisterControl registerControl = new RegisterControl(clientRegisterInteractor);
RegisterControl attorneyRegisterControl = new RegisterControl(attorneyRegisterInteractor);

QuestionInputBoundary questionInteractor = new AskQuestionInteractor(questionGateway, theQuestionOutputBoundary,
questionFactory, clientGateway);
Expand Down Expand Up @@ -100,7 +103,7 @@ public static void main(String[] args) {
//control container
ControlContainer controlContainer = new ControlContainer(registerControl, closeQuestionControl,
postControl, questionControl, rateControl, selectQuestionControl, loginControl, viewQuestionControl,
browseQuestionControl, recommendationControl);
browseQuestionControl, recommendationControl, attorneyRegisterControl);

//feed control container into the response formatter
UIManager.setControlContainer(controlContainer);
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/adapters/controllers/ClientRegisterControl.java

This file was deleted.

77 changes: 23 additions & 54 deletions src/main/java/adapters/controllers/ControlContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* It is responsible for managing different aspects of the application.
*/
public class ControlContainer {
ClientRegisterControl clientRegisterControl;
RegisterControl clientRegisterControl;
RegisterControl attorneyRegisterControl;
CloseQuestionControl closeQuestionControl;
PostControl postControl;
QuestionControl questionControl;
Expand All @@ -19,23 +20,25 @@ public class ControlContainer {
/**
* Constructor to initialize the ControlContainer with instances of various control classes.
*
* @param clientRegisterControl The control class for client registration.
* @param closeQuestionControl The control class for closing questions.
* @param postControl The control class for handling posts.
* @param questionControl The control class for question management.
* @param rateControl The control class for rating questions.
* @param selectQuestionControl The control class for selecting questions.
* @param userLoginControl The control class for user login.
* @param viewQuestionControl The control class for viewing questions.
* @param browseQuestionControl The control class for browsing questions.
* @param recommendationControl The control class for viewing recommended questions.
* @param clientRegisterControl The control class for client registration.
* @param closeQuestionControl The control class for closing questions.
* @param postControl The control class for handling posts.
* @param questionControl The control class for question management.
* @param rateControl The control class for rating questions.
* @param selectQuestionControl The control class for selecting questions.
* @param userLoginControl The control class for user login.
* @param viewQuestionControl The control class for viewing questions.
* @param browseQuestionControl The control class for browsing questions.
* @param recommendationControl The control class for viewing recommended questions.
* @param attorneyRegisterControl The control class for attorney registration
*/
public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl,
public ControlContainer(RegisterControl clientRegisterControl, CloseQuestionControl closeQuestionControl,
PostControl postControl, QuestionControl questionControl, RateControl rateControl,
SelectQuestionControl selectQuestionControl, UserLoginControl userLoginControl,
ViewQuestionControl viewQuestionControl, ViewQuestionControl browseQuestionControl,
ViewQuestionControl recommendationControl) {
ViewQuestionControl recommendationControl, RegisterControl attorneyRegisterControl) {
this.clientRegisterControl = clientRegisterControl;
this.attorneyRegisterControl = attorneyRegisterControl;
this.closeQuestionControl = closeQuestionControl;
this.postControl = postControl;
this.questionControl = questionControl;
Expand All @@ -47,79 +50,45 @@ public ControlContainer(ClientRegisterControl clientRegisterControl, CloseQuesti
this.recommendationControl = recommendationControl;
}

/**
* Get the control class for client registration.
*
* @return The client registration control class.
*/
public ClientRegisterControl getClientRegisterControl() {

public RegisterControl getClientRegisterControl() {
return clientRegisterControl;
}

/**
* Get the control class for closing questions.
*
* @return The close question control class.
*/

public CloseQuestionControl getCloseQuestionControl() {
return closeQuestionControl;
}

/**
* Get the control class for handling posts.
*
* @return The post control class.
*/

public PostControl getPostControl() {
return postControl;
}

/**
* Get the control class for question management.
*
* @return The question control class.
*/

public QuestionControl getQuestionControl() {
return questionControl;
}

/**
* Get the control class for rating questions.
*
* @return The rate control class.
*/
public RateControl getRateControl() {
return rateControl;
}

/**
* Get the control class for selecting questions.
*
* @return The select question control class.
*/
public SelectQuestionControl getSelectQuestionControl() {
return selectQuestionControl;
}

/**
* Get the control class for user login.
*
* @return The user login control class.
*/
public UserLoginControl getUserLoginControl() {
return userLoginControl;
}

/**
* Get the control class for viewing questions.
*
* @return The view question control class.
*/
public ViewQuestionControl getViewQuestionControl() {
return viewQuestionControl;
}

public ViewQuestionControl getBrowseQuestionControl() {return browseQuestionControl;}

public ViewQuestionControl getRecommendationControl() {return recommendationControl;}

public RegisterControl getAttorneyRegisterControl() {return attorneyRegisterControl;}
}
30 changes: 30 additions & 0 deletions src/main/java/adapters/controllers/RegisterControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package adapters.controllers;

import usecases.inputboundary.UserRegisterInputBoundary;
import usecases.requests.RegistrationData;
import usecases.responses.BaseResponseModel;

/**
* This class represents responsible for handling user registration.
*/
public class RegisterControl {
private final UserRegisterInputBoundary inputBoundary;

/**
* Constructs a new instance of ClientRegisterControl.
*
* @param inputBoundary The input boundary for user registration.
*/
public RegisterControl(UserRegisterInputBoundary inputBoundary) {
this.inputBoundary = inputBoundary;
}

/**
* Creates a new user registration based on the provided information.
*
* @param requestModel @return A RegisterResponseModel indicating the result of the registration attempt.
*/
public BaseResponseModel create(RegistrationData requestModel){
return inputBoundary.create(requestModel);
}
}
1 change: 1 addition & 0 deletions src/main/java/entities/factories/AttorneyFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entities.factories;

import usecases.requests.AttorneyRegistrationData;
import usecases.requests.RegistrationData;
import entities.user.Attorney;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/entities/factories/ClientFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entities.factories;

import usecases.requests.ClientRegistrationData;
import usecases.requests.RegistrationData;
import entities.user.Client;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/entities/factories/UserFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entities.factories;

import entities.user.User;
import usecases.requests.RegistrationData;
import entities.user.UserImp;

Expand All @@ -8,7 +9,7 @@
*
* @param <T> The type of user to create, extending UserImp.
*/
public interface UserFactory<T extends UserImp> {
public interface UserFactory<T extends User> {

/**
* Creates a user instance based on the provided registration data.
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/infrastructure/screens/RegisterUI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package infrastructure.screens;

import adapters.controllers.ClientRegisterControl;
import adapters.controllers.RegisterControl;
import adapters.controllers.ControlContainer;
import infrastructure.screens.utils.UIManager;
import usecases.requests.ClientRegistrationData;
import usecases.requests.RegistrationData;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -147,15 +149,20 @@ public void actionPerformed(ActionEvent e) {
ControlContainer controlContainer = uiManager.getControlContainer();
JPanel screens = uiManager.getScreens();
CardLayout cardLayout = uiManager.getCardLayout();
ClientRegisterControl clientRegisterControl = controlContainer.getClientRegisterControl();
RegisterControl registerControl = controlContainer.getClientRegisterControl();
switch (actionCommand) {
case REGISTER_BUTTON_NAME:
try {
clientRegisterControl.create(userName.getText(), email.getText(), String.valueOf(password1.getPassword()),
String.valueOf(password2.getPassword()), stateAbb.getText(), postalCode.getText(),
(String) ethnicity.getSelectedItem(), Integer.parseInt(age.getText()), (String) gender.getSelectedItem(),
(String) maritalStatus.getSelectedItem(), Integer.parseInt(numberOfHousehold.getText()),
Float.parseFloat(annualIncome.getText()));
RegistrationData registrationData = new RegistrationData(userName.getText(), email.getText(), String.valueOf(password1.getPassword()), String.valueOf(password2.getPassword()), stateAbb.getText(), postalCode.getText());
ClientRegistrationData clientRegistrationData = new ClientRegistrationData.Builder(registrationData)
.ethnicity((String) ethnicity.getSelectedItem())
.age(Integer.parseInt(age.getText()))
.gender((String) gender.getSelectedItem())
.maritalStatus((String) maritalStatus.getSelectedItem())
.numberOfHousehold(Integer.parseInt(numberOfHousehold.getText()))
.annualIncome(Float.parseFloat(annualIncome.getText()))
.build();
registerControl.create(clientRegistrationData);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/usecases/interactors/AttorneyRegisterInteractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package usecases.interactors;

import entities.factories.AttorneyFactory;
import entities.factories.UserFactory;
import entities.user.Attorney;
import usecases.gateway.AttorneyGateway;
import usecases.gateway.UserGateway;
import usecases.outputboundary.BaseOutputBoundary;

public class AttorneyRegisterInteractor extends UserRegisterInteractor<AttorneyGateway, AttorneyFactory, Attorney> {
public AttorneyRegisterInteractor(AttorneyGateway userGateway, BaseOutputBoundary outputBoundary, AttorneyFactory userFactory) {
super(userGateway, outputBoundary, userFactory);
}
}
Loading

0 comments on commit 179f38d

Please sign in to comment.