Skip to content

Conversation

@jacsimas
Copy link
Owner

@jacsimas jacsimas commented Jul 4, 2025

Summary

I added Flyway migrations tool, connected it to the postgreSQL database. I added a new table to the database to test out if migrations work correctly. I refactored DBRepository, I made this class into two separate repositories, CustomerEntityRepository and TransfersRepository.

@jacsimas jacsimas requested a review from ganiulis July 4, 2025 16:37
public class CurrencyAPI {

private static final String url_str = "https://v6.exchangerate-api.com/v6/79f34354ceb4dc1276fecca5/latest/USD";
private static final String url_str = System.getenv("currencyAPI");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environmental variables use SCREAMING_SNAKE_CASE

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +9 to +11
private final String url = System.getenv("DBurl"); // put into properties file
private final String username = System.getenv("DBuser");
private final String password = System.getenv("DBpassword");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCREAMING_SNAKE_CASE


public class CustomerEntityRepository {

DriverManagerDB drivermanagerdb = new DriverManagerDB();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You keep doing this, but it's not right. When are you planning to apply dependency inversion principle?


DriverManagerDB drivermanagerdb = new DriverManagerDB();

Connection connection = drivermanagerdb.connect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this logic every unique repository will have its own active database connection regardless if it's used or now. Use dependency inversion.


Connection connection = drivermanagerdb.connect();

final Logger logger = LoggerFactory.getLogger(TransfersRepository.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Dependency inversion.

Comment on lines +62 to +65
id = rs.getInt("id"); // error here probably
name = rs.getString("nickname");
money = rs.getInt("money");
cusPassword = rs.getString("password");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you return a Customer here instead of at the bottom of the function?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public Customer returnRecord(int customerId) throws SQLException {
    
    String sql = "SELECT id, nickname, money, password FROM customers WHERE id = ?";

    try (
            PreparedStatement ps = connection.prepareStatement(sql)) {
        ps.setLong(1, customerId);

        ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            return new Customer(rs.getInt("id"), rs.getString("nickname"), rs.getInt("money"), rs.getString("password"));
        }
        //TODO: make this code with error logging
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
    return null;
}

You are indeed correct sir

}

public int findCustomerByUsername(String name){
int id = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should not be a default return value. You should use nullable Integer class and return null if it does not find a customer.

Also, you have a Customer class, and findCustomerByUsername I assume I'll get some sort of object back... but I get an integer? It's false naming.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the naming, yes it was indeed incorrect

}


public boolean updateCustomerFunds(int customerId, int newAmount) { //void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns boolean but comment here states void?

Also, despite previous times I made comments about it you continue returning true/false as some sort of sanity check for yourself but this kind of convention isn't used anywhere outside of command-line programs, and even then it's not true/false but 1/2/3 and the shell handles the return values as special codes to interpret whether the program succeeded or failed. In your case your functions aren't programs—they're just functions that return an arbitrary value that means nothing.

Stop doing this, because you're already getting yourself used to doing something that will give you lots of problems in the future.

Comment on lines +107 to +109
return false;
}
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return anything? What's the point?

return true;
}

public boolean checkIfHasFriend(int senderId, int receiverId) throws SQLException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be hasFriend.

@@ -0,0 +1,5 @@
CREATE TABLE transaction_category (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see V2 and V3.... where's V1? Where's V0?

int money = 18500;
String password = "pass4";
dbcontroller.addCustomerRecord(name,money, password);
customerentityrepository.addCustomerRecord(name,money, password);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase for variables. I notice you sometimes remember to do this and sometimes forget.

// int getmoney = customer.getMoneyInCents();

Customer returnedCustomer = dbcontroller.returnRecord(customerId);
Customer returnedCustomer = customerentityrepository.returnRecord(customerId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

int newAmount = 27000;

dbcontroller.updateCustomerFunds(customerId, newAmount);
customerentityrepository.updateCustomerFunds(customerId, newAmount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

String name = "jennifer";

int returnedId = dbcontroller.findCustomerByUsername(name);
int returnedId = customerentityrepository.findCustomerByUsername(name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

int receiverId = 3;

dbcontroller.insertIntoFriendships(senderId, receiverId);
dbrepository.insertIntoFriendships(senderId, receiverId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

@Test
public void checkIfHasFriendTest() throws SQLException {
boolean isfriend = dbcontroller.checkIfHasFriend(7, 5);
boolean isfriend = customerentityrepository.checkIfHasFriend(7, 5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

@Test
public void returnAuditRecordTest() throws SQLException {
DBRepository dbcontroller = new DBRepository();
TransfersRepository dbcontroller = new TransfersRepository();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

Copy link
Collaborator

@ganiulis ganiulis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs improvement.

Removing .idea from version history is good.

I have a hard time understanding the purpose of this PR. It's labeled migrations but there's only two and there's lots of unrelated code. Why? Create separate PRs or rename to include all this.

@jacsimas jacsimas changed the title Migrations Migrations and DBrep refactory Jul 9, 2025
@jacsimas jacsimas changed the title Migrations and DBrep refactory Migrations and DBrepository refactory Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants