-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from cathrkri/feature/implement-more-DAO's
Feature/implement more dao's
- Loading branch information
Showing
20 changed files
with
115 additions
and
20 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/UserDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package ntnu.systemutvikling.team6.DAO; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.user.User; | ||
|
|
||
| /** | ||
| * This class is responsible for sending concurrent information about the user to the User | ||
| * database, and user settings to the settings database. | ||
| * | ||
| * @author Robin Strand Prestmo | ||
| */ | ||
| public class UserDAO { | ||
|
|
||
| private static final DatabaseConnection connection = new DatabaseConnection(); | ||
|
|
||
| /** | ||
| * Gets the user and settings information and sends it to the database through MySQL. | ||
| * | ||
| * @param user the user to be saved in the database. | ||
| * @throws RuntimeException if a database error occurs during the operation | ||
| */ | ||
| public static void registerUser(User user) { | ||
|
|
||
| String userSql = | ||
| """ | ||
| INSERT INTO User ( | ||
| UUID_User, | ||
| user_displayname, | ||
| user_name, | ||
| user_email, | ||
| user_password, | ||
| role | ||
| ) | ||
| VALUES (?, ?, ?, ?, ?, ?) | ||
| """; | ||
|
|
||
| String settingsSql = | ||
| """ | ||
| INSERT INTO Settings ( | ||
| User_UUID_User, | ||
| isAnonymous, | ||
| language, | ||
| lightmode | ||
| ) | ||
| VALUES (?, ?, ?, ?) | ||
| """; | ||
|
|
||
| try (Connection conn = connection.getMySqlConnection()) { | ||
|
|
||
| conn.setAutoCommit(false); | ||
|
|
||
| try (PreparedStatement psUser = conn.prepareStatement(userSql)) { | ||
|
|
||
| psUser.setString(1, user.getId().toString()); | ||
| psUser.setString(2, user.getName()); // display name | ||
| psUser.setString(3, user.getName()); // username | ||
| psUser.setString(4, user.getEmail()); | ||
| psUser.setString(5, user.getPasswordHash()); | ||
| psUser.setString(6, user.getRole().name()); | ||
|
|
||
| psUser.executeUpdate(); | ||
| } | ||
|
|
||
| try (PreparedStatement psSettings = conn.prepareStatement(settingsSql)) { | ||
|
|
||
| psSettings.setString(1, user.getId().toString()); | ||
| psSettings.setBoolean(2, user.getSettings().isAnonymous()); | ||
| psSettings.setString(3, user.getSettings().getLanguage().name()); | ||
| psSettings.setBoolean(4, user.getSettings().isLightMode()); | ||
|
|
||
| psSettings.executeUpdate(); | ||
| } | ||
|
|
||
| conn.commit(); | ||
|
|
||
| } catch (SQLException e) { | ||
| throw new RuntimeException("Failed to insert user into database", e); | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...vikling/team6/models/CharityRegistry.java → ...eam6/models/registry/CharityRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ikling/team6/models/DonationRegistry.java → ...am6/models/registry/DonationRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mutvikling/team6/models/UserRegistry.java → ...g/team6/models/registry/UserRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters