Skip to content

Commit

Permalink
Feat: New row for user and feedback can now be set when getting chari…
Browse files Browse the repository at this point in the history
…ties from db.
  • Loading branch information
AdrianBalunan committed Apr 9, 2026
1 parent abc92c0 commit cfeaa5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ FOREIGN KEY (`user_id`)
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `apbaluna`.`User` (
`UUID_User` CHAR(36) NOT NULL,
`user_displayname` VARCHAR(255) NOT NULL,
`user_name` VARCHAR(255) NOT NULL,
`user_email` VARCHAR(255) NOT NULL,
`user_password` VARCHAR(255) NOT NULL,
Expand Down Expand Up @@ -419,6 +420,9 @@ public CharityRegistry getCharitiesFromDB() {
rs.getString("charity_name"),
rs.getBoolean("pre_approved"),
rs.getString("status"));
ArrayList<Feedback> feedbacks = getFeedbackforChairtyUUID(charity.getUUID().toString());
charity.setFeedbacks(feedbacks);

registry.addCharity(charity);
}
} catch (SQLException e) {
Expand Down Expand Up @@ -460,7 +464,7 @@ public UserRegistry getUsersFromDB(){
return registry;
}

public User getUserFromDBUuid(UUID uuid){
public User getUserFromDBUuid(String user_id){
User user = null;
Connection conn = null;
try {
Expand All @@ -471,7 +475,7 @@ public User getUserFromDBUuid(UUID uuid){
WHERE UUID_User = ?;
""";
PreparedStatement stmt = conn.prepareStatement(sql_query);
stmt.setString(1, uuid.toString());
stmt.setString(1, user_id);
stmt.setMaxRows(1);
ResultSet rs = stmt.executeQuery();

Expand Down Expand Up @@ -608,36 +612,37 @@ public DonationRegistry getDonationFromDB() {
}
return registry;
}
public ArrayList<Feedback> setFeedbackforChairty(Charity charity){
/*

public ArrayList<Feedback> getFeedbackforChairtyUUID(String charity_uuid) {
ArrayList<Feedback> Feedbacks = new ArrayList<>();
Connection conn = null;
try {
conn = connection.getMySqlConnection();
String sql_query =
"""
SELECT
*
FROM Feedback f
UUID_feedback, feedback_comment, feedback_date, isAnonymous, charity_id, user_id
FROM Feedback
WHERE f.charity_id = ?;
""";
PreparedStatement stmt = conn.prepareStatement(sql_query);
stmt.setString(1, charity.getUUID().toString());
stmt.setString(1, charity_uuid);
ResultSet rs = stmt.executeQuery(sql_query);

while (rs.next()){
while (rs. next()){
Feedback feedback = new Feedback(
)
rs.getString("UUID_feedback"),
getUserFromDBUuid(rs.getString("user_id")),
rs.getString("feedback_comment"),
LocalDate.parse(rs.getString("feedback_date"))
);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
conn = null;
}
*/
return null;
}
}
return Feedbacks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Feedback {
private boolean isAnonymous;

/**
* Constructor for creating a new feedback.
* Constructor for creating a new feedback now.
*
* @param user The user who gives the feedback.
* @param comment The content of the feedback.
Expand All @@ -33,19 +33,19 @@ public Feedback(User user, String comment) {
this.user = user;
this.comment = comment;
this.date = LocalDate.now();

this.isAnonymous = user.getSettings().isAnonymous();
}

/**
* Constructor for creating a new feedback, based on getting the data from DATABASE.
* Constructor for creating a new feedback, based on making a feedback previously made.
*
* @param user The user who gives the feedback.
* @param comment The content of the feedback.
*/
public Feedback(User user_id, String feedback_comment, LocalDate feedback_date) {
* @param feedback_date The content of the feedback.
this.feedbackId = UUID.randomUUID();
*/
public Feedback(String feedback_id, User user, String feedback_comment, LocalDate feedback_date) {
this.feedbackId = UUID.fromString(feedback_id);
this.user = user;
this.comment = comment;
this.date = feedback_date;
Expand Down

0 comments on commit cfeaa5d

Please sign in to comment.