Skip to content

Commit

Permalink
Merge pull request #61 from zzz403/profile
Browse files Browse the repository at this point in the history
Profile
  • Loading branch information
zzz403 authored Jul 18, 2024
2 parents 5d8a2f7 + e9b452d commit 58266bb
Show file tree
Hide file tree
Showing 13 changed files with 689 additions and 43 deletions.
Binary file modified database/academia_imperial.mv.db
Binary file not shown.
285 changes: 285 additions & 0 deletions database/academia_imperial.trace.db

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,54 @@
import com.imperial.academia.use_case.profile.ProfileInputBoundry;
import com.imperial.academia.use_case.profile.ProfileInputData;

public class ProfileController{
/**
* The ProfileController class handles user interactions related to profile operations.
* It interacts with the use case layer to perform profile-related tasks such as showing a profile and initiating a chat.
*/
public class ProfileController {

/**
* The interactor for profile operations.
*/
private final ProfileInputBoundry profileInteractor;

/**
* The interactor for chat coordination operations.
*/
private final ChatCoordinatorInputBoundary chatCoordinatorInteractor;

/**
* Constructs a new ProfileController and initializes the interactors for profile and chat operations.
*/
public ProfileController() {
this.profileInteractor = UsecaseFactory.getProfileInteractor();
this.chatCoordinatorInteractor = UsecaseFactory.getChatCoordinatorInteractor();
}


public void showProfile(int userId){
/**
* Shows the profile of the user with the specified user ID.
*
* @param userId the ID of the user whose profile is to be shown
*/
public void showProfile(int userId) {
ProfileInputData profileInputData = new ProfileInputData(userId);
profileInteractor.excute(profileInputData);
}

public void chat(int userId){
/**
* Initiates a chat with the user with the specified user ID.
*
* @param userId the ID of the user to chat with
*/
public void chat(int userId) {
chatCoordinatorInteractor.toPrivateChat(userId);
}

public void edit(){
// editInteractor.set
/**
* Placeholder for the edit functionality.
* This method is currently not implemented.
*/
public void edit() {
// editInteractor.set
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@
import com.imperial.academia.use_case.profile.ProfileOutputBoundry;
import com.imperial.academia.use_case.profile.ProfileOutputData;

/**
* The ProfilePresenter class implements the ProfileOutputBoundry interface
* and is responsible for presenting profile data to the ProfileViewModel.
*/
public class ProfilePresenter implements ProfileOutputBoundry {

/**
* The view model for the profile data.
*/
private final ProfileViewModel profileViewModel;

/**
* Constructs a new ProfilePresenter with the specified profile view model.
*
* @param profileViewModel the view model for the profile data
*/
public ProfilePresenter(ProfileViewModel profileViewModel) {
this.profileViewModel = profileViewModel;
}


/**
* Presents the profile output data by updating the ProfileViewModel.
*
* @param profileOutputData the profile data to be presented
*/
@Override
public void present(ProfileOutputData profileOutputData){
public void present(ProfileOutputData profileOutputData) {
ProfileState profileState = profileViewModel.getProfileState();
profileState.setEmail(profileOutputData.getEmail());
profileState.setId(profileOutputData.getId());
Expand All @@ -26,9 +43,13 @@ public void present(ProfileOutputData profileOutputData){
profileViewModel.firePropertyChanged();
}


/**
* Presents an error message by resetting the ProfileViewModel state.
*
* @param error the error message to be presented
*/
@Override
public void presentError(String error){
public void presentError(String error) {
profileViewModel.setProfileState(new ProfileState());
profileViewModel.firePropertyChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,53 @@

import java.sql.Timestamp;

/**
* The ProfileState class represents the state of a user's profile.
* It includes user information such as ID, username, email, role, avatar URL, registration date, and a flag indicating if the profile belongs to the current user.
*/
public class ProfileState {

/**
* The ID of the user.
*/
private int id = -1;

/**
* The username of the user.
*/
private String username = "";

/**
* The email of the user.
*/
private String email = "";

/**
* The role of the user.
*/
private String role = "";

/**
* The avatar URL of the user.
*/
private String avatarUrl = "";

/**
* The registration date of the user.
*/
private Timestamp registrationDate = new Timestamp(System.currentTimeMillis());

/**
* A flag indicating if the profile belongs to the current user.
*/
private boolean isMe = true;

public ProfileState (ProfileState copy){
/**
* Constructs a new ProfileState by copying another ProfileState instance.
*
* @param copy the ProfileState instance to copy
*/
public ProfileState(ProfileState copy) {
this.id = copy.id;
this.username = copy.username;
this.email = copy.email;
Expand All @@ -20,64 +57,135 @@ public ProfileState (ProfileState copy){
this.registrationDate = copy.registrationDate;
this.isMe = copy.isMe;
}
public ProfileState(){}

/**
* Constructs a new, empty ProfileState.
*/
public ProfileState() {}

/**
* Returns the ID of the user.
*
* @return the user ID
*/
public int getId() {
return id;
}

/**
* Returns the username of the user.
*
* @return the username
*/
public String getUsername() {
return username;
}

/**
* Returns the email of the user.
*
* @return the email
*/
public String getEmail() {
return email;
}

/**
* Returns the role of the user.
*
* @return the role
*/
public String getRole() {
return role;
}

/**
* Returns the avatar URL of the user.
*
* @return the avatar URL
*/
public String getAvatarUrl() {
return avatarUrl;
}

/**
* Returns the registration date of the user.
*
* @return the registration date
*/
public Timestamp getRegistrationDate() {
return registrationDate;
}

public boolean isMe(){
/**
* Returns a flag indicating if the profile belongs to the current user.
*
* @return true if the profile belongs to the current user, false otherwise
*/
public boolean isMe() {
return isMe;
}



/**
* Sets the ID of the user.
*
* @param id the user ID
*/
public void setId(int id) {
this.id = id;
}

/**
* Sets the username of the user.
*
* @param username the username
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Sets the email of the user.
*
* @param email the email
*/
public void setEmail(String email) {
this.email = email;
}

/**
* Sets the role of the user.
*
* @param role the role
*/
public void setRole(String role) {
this.role = role;
}

/**
* Sets the avatar URL of the user.
*
* @param avatarUrl the avatar URL
*/
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}

/**
* Sets the registration date of the user.
*
* @param registrationDate the registration date
*/
public void setRegistrationDate(Timestamp registrationDate) {
this.registrationDate = registrationDate;
}

public void setIsMe(boolean isMe){
/**
* Sets the flag indicating if the profile belongs to the current user.
*
* @param isMe true if the profile belongs to the current user, false otherwise
*/
public void setIsMe(boolean isMe) {
this.isMe = isMe;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,60 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
* The ProfileViewModel class extends the ViewModel class and manages the state of the profile view.
* It supports property change listeners to notify changes in the profile state.
*/
public class ProfileViewModel extends ViewModel {

/**
* The current state of the profile.
*/
private ProfileState profileState = new ProfileState();

/**
* The support for property change listeners.
*/
private final PropertyChangeSupport support = new PropertyChangeSupport(this);

/**
* Constructs a new ProfileViewModel with the default view name "profile".
*/
public ProfileViewModel() {
super("profile");
}

/**
* Returns a copy of the current profile state.
*
* @return a copy of the profile state
*/
public ProfileState getProfileState() {
return new ProfileState(profileState);
}

/**
* Sets the profile state and notifies listeners of the change.
*
* @param profileState the new profile state
*/
public void setProfileState(ProfileState profileState) {
this.profileState = profileState;
}

/**
* Fires a property change event to notify listeners of a change in the profile state.
*/
@Override
public void firePropertyChanged() {
support.firePropertyChange("state", null, this.profileState);
}

/**
* Adds a property change listener to be notified of changes in the profile state.
*
* @param listener the property change listener to add
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.imperial.academia.use_case.profile;

/**
* The ProfileInputBoundry interface provides a contract for executing profile-related operations.
* Implementations of this interface should define the specific logic for handling profile input data.
*/
public interface ProfileInputBoundry {
void excute (ProfileInputData profileInputData);

/**
* Executes an operation with the given profile input data.
*
* @param profileInputData the data required to perform the profile operation
*/
void excute(ProfileInputData profileInputData);
}
Loading

0 comments on commit 58266bb

Please sign in to comment.