Skip to content

Commit

Permalink
Fix: Maven clean and correct functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 12, 2026
1 parent 8d26537 commit a9d8680
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 645 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
/**
* Data access class responsible for reading donation data from the database.
*
* <p>Retrieves donations along with their associated charity information by
* performing an INNER JOIN between the {@code Donations} and {@code Charities} tables.
* Only donations that have a matching charity record are returned.</p>
* <p>Retrieves donations along with their associated charity information by performing an INNER
* JOIN between the {@code Donations} and {@code Charities} tables. Only donations that have a
* matching charity record are returned.
*/

public class DonationSelect {

/** The database connection used for all queries in this class. */
Expand All @@ -25,23 +24,22 @@ public class DonationSelect {
/**
* Constructs a new {@code DonationSelect} with the given database connection.
*
* @param connection the {@link DatabaseConnection} to use for executing queries;
* must not be {@code null}
* @param connection the {@link DatabaseConnection} to use for executing queries; must not be
* {@code null}
*/
public DonationSelect(DatabaseConnection connection) {
this.connection = connection;
}

/**
* Retrieves all donations from the database, each populated with its associated
* {@link Charity}.
* Retrieves all donations from the database, each populated with its associated {@link Charity}.
*
* <p>The query performs an INNER JOIN between the {@code Donations} and
* {@code Charities} tables on the charity UUID foreign key. Donations without a
* matching charity are excluded from the result.</p>
* <p>The query performs an INNER JOIN between the {@code Donations} and {@code Charities} tables
* on the charity UUID foreign key. Donations without a matching charity are excluded from the
* result.
*
* @return a {@link DonationRegistry} containing all matched donations;
* never {@code null}, but may be empty if no rows are returned
* @return a {@link DonationRegistry} containing all matched donations; never {@code null}, but
* may be empty if no rows are returned
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
public DonationRegistry getDonationFromDB() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,41 @@
/**
* Data access class responsible for reading user-related data from the database.
*
* <p>Provides methods to retrieve individual users (by credentials or UUID),
* all users, a user's settings, and a user's inbox. Queries use LEFT JOINs
* across the {@code User}, {@code Settings}, and {@code Messages} tables to
* assemble fully populated {@link User} objects in a single round trip where
* possible.</p>
* <p>Provides methods to retrieve individual users (by credentials or UUID), all users, a user's
* settings, and a user's inbox. Queries use LEFT JOINs across the {@code User}, {@code Settings},
* and {@code Messages} tables to assemble fully populated {@link User} objects in a single round
* trip where possible.
*/

public class UserSelect {
/** The database connection used for all queries in this class. */
private final DatabaseConnection connection;

/**
* Constructs a new {@code UserSelect} with the given database connection.
*
* @param connection the {@link DatabaseConnection} to use for executing queries;
* must not be {@code null}
* @param connection the {@link DatabaseConnection} to use for executing queries; must not be
* {@code null}
*/
public UserSelect(DatabaseConnection connection) {
this.connection = connection;
}

/**
* Retrieves a single {@link User} from the database matching the given username
* and password.
* Retrieves a single {@link User} from the database matching the given username and password.
*
* <p>The password is hashed via {@link PasswordHasher} before being compared
* against the stored value. If a matching user is found, their {@link Settings}
* (when present) and {@link Inbox} (including any {@link Message} objects) are
* also populated. Returns {@code null} if no matching user is found.</p>
* <p>The password is hashed via {@link PasswordHasher} before being compared against the stored
* value. If a matching user is found, their {@link Settings} (when present) and {@link Inbox}
* (including any {@link Message} objects) are also populated. Returns {@code null} if no matching
* user is found.
*
* <p><strong>Note:</strong> the current SQL query compares both parameters against
* {@code user_password}; the {@code user_name} column is not yet included in the
* WHERE clause, which may be a bug.</p>
* <p><strong>Note:</strong> the current SQL query compares both parameters against {@code
* user_password}; the {@code user_name} column is not yet included in the WHERE clause, which may
* be a bug.
*
* @param username the plain-text username to look up
* @param password the plain-text password; hashed internally before the query runs
* @return the matching {@link User} with settings and inbox populated,
* or {@code null} if no match is found
* @return the matching {@link User} with settings and inbox populated, or {@code null} if no
* match is found
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
public User getUserFromDBUsernameAndPassword(String username, String password) {
Expand Down Expand Up @@ -122,13 +119,13 @@ public User getUserFromDBUsernameAndPassword(String username, String password) {
/**
* Retrieves a single {@link User} from the database by their UUID.
*
* <p>The returned user is fully populated with {@link Settings} (when present)
* and an {@link Inbox} containing any associated {@link Message} objects.
* Returns {@code null} if no user with the given UUID exists.</p>
* <p>The returned user is fully populated with {@link Settings} (when present) and an {@link
* Inbox} containing any associated {@link Message} objects. Returns {@code null} if no user with
* the given UUID exists.
*
* @param user_id the UUID string of the user to retrieve; must not be {@code null}
* @return the matching {@link User} with settings and inbox populated,
* or {@code null} if no user is found
* @return the matching {@link User} with settings and inbox populated, or {@code null} if no user
* is found
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
public User getUserFromDBUuid(String user_id) {
Expand Down Expand Up @@ -195,15 +192,15 @@ public User getUserFromDBUuid(String user_id) {
}

/**
* Retrieves all users from the database, each fully populated with their
* {@link Settings} and {@link Inbox}.
* Retrieves all users from the database, each fully populated with their {@link Settings} and
* {@link Inbox}.
*
* <p>The query LEFT JOINs {@code User}, {@code Settings}, and {@code Messages}.
* Multiple rows for the same user UUID (due to multiple messages) are collapsed
* into a single {@link User} object with all messages appended to its inbox.</p>
* <p>The query LEFT JOINs {@code User}, {@code Settings}, and {@code Messages}. Multiple rows for
* the same user UUID (due to multiple messages) are collapsed into a single {@link User} object
* with all messages appended to its inbox.
*
* @return a {@link UserRegistry} containing all users found in the database;
* never {@code null}, but may be empty if no users exist
* @return a {@link UserRegistry} containing all users found in the database; never {@code null},
* but may be empty if no users exist
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
public UserRegistry getUsersFromDB() {
Expand Down Expand Up @@ -274,11 +271,11 @@ public UserRegistry getUsersFromDB() {
/**
* Retrieves the {@link Settings} for a specific user by their UUID.
*
* <p>At most one row is fetched (via {@code setMaxRows(1)}). Returns {@code null}
* if no settings row exists for the given user.</p>
* <p>At most one row is fetched (via {@code setMaxRows(1)}). Returns {@code null} if no settings
* row exists for the given user.
*
* @param user_id the UUID string of the user whose settings should be retrieved;
* must not be {@code null}
* @param user_id the UUID string of the user whose settings should be retrieved; must not be
* {@code null}
* @return the user's {@link Settings}, or {@code null} if none are found
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
Expand Down Expand Up @@ -315,16 +312,14 @@ public Settings getSettingsForUser(String user_id) {
}

/**
* Retrieves the {@link Inbox} for a specific user by their UUID, populated with
* all of their {@link Message} objects.
* Retrieves the {@link Inbox} for a specific user by their UUID, populated with all of their
* {@link Message} objects.
*
* <p>Returns an empty {@link Inbox} (never {@code null}) if no messages exist
* for the given user.</p>
* <p>Returns an empty {@link Inbox} (never {@code null}) if no messages exist for the given user.
*
* @param user_id the UUID string of the user whose inbox should be retrieved;
* must not be {@code null}
* @return an {@link Inbox} containing all messages for the user;
* empty if no messages are found
* @param user_id the UUID string of the user whose inbox should be retrieved; must not be {@code
* null}
* @return an {@link Inbox} containing all messages for the user; empty if no messages are found
* @throws RuntimeException if a {@link SQLException} occurs while executing the query
*/
public Inbox getInboxForUser(String user_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
* @author Robin Strand Prestmo
*/
public enum Language {
NORWEGIAN,
ENGLISH
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import static org.junit.jupiter.api.Assertions.*;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.CharityRegistry;
import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.*;

Expand Down Expand Up @@ -45,7 +43,6 @@ void createCharitiesTableShouldCreateTableSuccessfully() throws SQLException {
}
}


@Test
void tempTableShouldNotExistAfterUpdating() throws SQLException {
Charity charity = new Charity("99999", "https://temp.no", "Temp Charity", false, "approved");
Expand Down
Loading

0 comments on commit a9d8680

Please sign in to comment.