Skip to content

Commit

Permalink
add finance_management
Browse files Browse the repository at this point in the history
  • Loading branch information
Freezepop committed Dec 8, 2024
1 parent 1e046ac commit 83d3c55
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/finance_management/processsing_handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public interface processsing_handler {

static String getUserUUID(Connection cursor, String name) throws SQLException {

String insertSQL = "SELECT uuid FROM users WHERE name = ?";
String sql = "SELECT uuid FROM users WHERE name = ?";

try (PreparedStatement pstmt = cursor.prepareStatement(insertSQL)) {
try (PreparedStatement pstmt = cursor.prepareStatement(sql)) {
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
return rs.getString("uuid");
Expand All @@ -34,9 +34,9 @@ static void writeIncome(Connection cursor, String category_uuid, String value) t

static void writeExpense(Connection cursor, String category_uuid, String value) throws SQLException {

String sql = "INSERT INTO transactions (category_uuid, value, income) VALUES (?, ?, false)";
String insertSQL = "INSERT INTO transactions (category_uuid, value, income) VALUES (?, ?, false)";

try (PreparedStatement insert_pstmt = cursor.prepareStatement(sql)) {
try (PreparedStatement insert_pstmt = cursor.prepareStatement(insertSQL)) {
insert_pstmt.setString(1, category_uuid);
insert_pstmt.setString(2, value);
insert_pstmt.executeUpdate();
Expand All @@ -45,9 +45,9 @@ static void writeExpense(Connection cursor, String category_uuid, String value)

static String checkCategory(Connection cursor, String category, String user_uuid) throws SQLException {

String insertSQL = "SELECT uuid FROM categories WHERE name = ? AND user_uuid = ?";
String sql = "SELECT uuid FROM categories WHERE name = ? AND user_uuid = ?";

try (PreparedStatement pstmt = cursor.prepareStatement(insertSQL)) {
try (PreparedStatement pstmt = cursor.prepareStatement(sql)) {
pstmt.setString(1, category);
pstmt.setString(2, user_uuid);
ResultSet rs = pstmt.executeQuery();
Expand All @@ -59,11 +59,11 @@ static void createCategory(Connection cursor, String user_uuid, String category_

String sql = "INSERT INTO categories (user_uuid, name, limit_value) VALUES (?, ?, ?)";

try (PreparedStatement insert_pstmt = cursor.prepareStatement(sql)) {
insert_pstmt.setString(1, user_uuid);
insert_pstmt.setString(2, category_name);
insert_pstmt.setInt(3, Integer.parseInt(limit_value));
insert_pstmt.executeUpdate();
try (PreparedStatement pstmt = cursor.prepareStatement(sql)) {
pstmt.setString(1, user_uuid);
pstmt.setString(2, category_name);
pstmt.setInt(3, Integer.parseInt(limit_value));
pstmt.executeUpdate();
}
}

Expand Down Expand Up @@ -183,15 +183,16 @@ static int sbp(Connection cursor, String user_uuid, String friend_name, String v
String friend_uuid = rs_get_friend.getString("uuid");
String category_friend_uuid = checkCategory(cursor, "bro_bonus", friend_uuid);
String category_my_uuid = checkCategory(cursor, "bro_bonus", user_uuid);

if (category_my_uuid == null){
createCategory(cursor, user_uuid, "bro_bonus", "-1");
category_my_uuid = checkCategory(cursor, "bro_bonus", user_uuid);

}
if (category_friend_uuid == null) {
createCategory(cursor, friend_uuid, "bro_bonus", "-1");
category_friend_uuid = checkCategory(cursor, "bro_bonus", friend_uuid);
}

writeIncome(cursor, category_friend_uuid, value);
writeExpense(cursor, category_my_uuid, value);
return 1;
Expand Down

0 comments on commit 83d3c55

Please sign in to comment.