Skip to content

Commit

Permalink
add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
RickBarretto committed Dec 7, 2024
1 parent a48560e commit dcf1259
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/java/passport/application/desktop/system/Infra.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
import passport.roles.repositories.Events;
import passport.roles.repositories.Users;

/**
* Represents the infrastructure layer of the PassPort application.
*
* @param users The repository of users.
* @param events The repository of events.
* @param emailService The email service used for sending emails.
* @param session The session management for the application.
*/
public record Infra(
Users users,
Events events,
EmailService emailService,
Session session) {
}
Session session) {}
21 changes: 20 additions & 1 deletion src/main/java/passport/application/desktop/system/Language.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package passport.application.desktop.system;

/**
* Represents the supported languages for the PassPort application.
*/
public enum Language {
ENGLISH("en", "English"),
PORTUGUESE("pt", "Português"),
Expand All @@ -9,13 +12,29 @@ public enum Language {
private final String code;
private final String displayName;

/**
* Constructs a Language enum with the specified code and display name.
*
* @param code The language code.
* @param displayName The display name of the language.
*/
Language(String code, String displayName) {
this.code = code;
this.displayName = displayName;
}

/**
* Gets the language code.
*
* @return The language code.
*/
public String code() { return code; }

/**
* Returns the display name of the language.
*
* @return The display name of the language.
*/
@Override
public String toString() { return displayName; }
}
}
98 changes: 98 additions & 0 deletions src/main/java/passport/application/desktop/system/PassPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,125 @@
import passport.application.desktop.ui.welcome.WelcomeWindow;
import passport.domain.models.events.Event;

/**
* The PassPort class acts as a controller in the MVC architecture. It manages
* the navigation and interaction between different views and the application's
* services. The controller is passed to the view (instead of getting the view),
* allowing the view to invoke controller methods for various actions.
*
* @param stage The primary stage of the application.
* @param services The services provided by the application.
* @param translator The translator for handling multilingual support.
*/
public record PassPort(Stage stage, Services services, Translator translator) {

/**
* Constructs a PassPort controller with the given services.
*
* @param services The services provided by the application.
*/
public PassPort(Services services) {
this(null, services, new Translator());
}

/**
* Returns a new PassPort instance with the specified stage.
*
* @param stage The primary stage of the application.
* @return A new PassPort instance with the specified stage.
*/
public PassPort withStage(Stage stage) {
return new PassPort(stage, services, translator);
}

/**
* Gets the current stage of the application.
*
* @return The current stage.
* @throws AssertionError if the stage is null.
*/
public Stage stage() {
assert stage != null;
return stage;
}

/**
* Navigates to the main window.
*/
public void toMain() {
toScene(new Scene(new MainWindow(this), 1200, 700));
}

/**
* Opens the purchase window for the specified event.
*
* @param event The event to purchase tickets for.
*/
public void toPurchaseOf(Event event) {
new PurchaseWindow(
this,
event,
this.services().login().current().get());
}

/**
* Opens the event purchase popup for the specified event.
*
* @param event The event to purchase tickets for.
*/
public void toEventPurchase(Event event) {
new EventPopup(this, event).forPurchasing();
}

/**
* Opens the event review popup for the specified event.
*
* @param event The event to review.
*/
public void toEventReview(Event event) {
new EventPopup(this, event).forReviewing();
}

/**
* Opens the profile editing window.
*/
public void toProfileEditing() { new EditProfile(this); }

/**
* Navigates to the welcome window.
*/
public void toWelcome() {
toScene(new Scene(new WelcomeWindow(this), 1200, 700));
}

/**
* Sets the specified scene on the current stage.
*
* @param scene The scene to set.
*/
public void toScene(Scene scene) {
Stage currentStage = (Stage) stage.getScene().getWindow();
currentStage.setScene(scene);
loadCss(scene);
}

/**
* Loads the CSS stylesheets for the specified scene.
*
* @param scene The scene to load stylesheets for.
*/
private void loadCss(Scene scene) {
this.addCSS(scene, "styles");
this.addCSS(scene, "language-selector");
this.addCSS(scene, "hero");
}

/**
* Adds a CSS stylesheet to the specified scene.
*
* @param scene The scene to add the stylesheet to.
* @param file The name of the stylesheet file.
*/
private void addCSS(Scene scene, String file) {
var css = scene.getStylesheets();
var module = this.getClass()
Expand All @@ -72,25 +139,56 @@ private void addCSS(Scene scene, String file) {
css.add(module);
}

/**
* The Warning class provides methods for displaying alerts and
* notifications.
*/
public class Warning {
/**
* Displays an error alert with the specified message key.
*
* @param messageKey The key of the message to display.
*/
public void error(String messageKey) {
show(messageKey, Alert.AlertType.ERROR);
}

/**
* Displays a success alert with the specified message key.
*
* @param messageKey The key of the message to display.
*/
public void success(String messageKey) {
show(messageKey, Alert.AlertType.INFORMATION);
}

/**
* Displays a notification with the specified title and message.
*
* @param title The title of the notification.
* @param message The message of the notification.
*/
public void notify(String title, String message) {
new Notification(title, message);
}

/**
* Displays an alert with the specified message key and alert type.
*
* @param messageKey The key of the message to display.
* @param type The type of the alert.
*/
private void show(String messageKey, Alert.AlertType type) {
var alert = new Alert(type);
alert.setContentText(translator.translationOf(messageKey));
alert.show();
}
}

/**
* Gets the Warning instance for displaying alerts and notifications.
*
* @return The Warning instance.
*/
public Warning warn() { return new Warning(); }
}
14 changes: 14 additions & 0 deletions src/main/java/passport/application/desktop/system/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
import passport.domain.contexts.user.UserEditing;
import passport.domain.contexts.user.UserLogin;

/**
* Provides access to various services within the PassPort application. These
* services encapsulate the business logic and interactions with different
* domains.
*
* @param signup The service for user sign-up.
* @param login The service for user login.
* @param eventsListing The service for listing available events.
* @param subscribedEvents The service for listing events subscribed.
* @param evaluationListing The service for listing event evaluations.
* @param evaluation The service for evaluating events.
* @param purchasing The service for buying tickets.
* @param profileEditing The service for editing user profiles.
*/
public record Services(
SigningUp signup,
UserLogin login,
Expand Down

0 comments on commit dcf1259

Please sign in to comment.