Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLID #1256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

SOLID #1256

wants to merge 4 commits into from

Conversation

alisahoys
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Thank you for your hard work on this project! 😊 While your code is well-structured and mostly meets the requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Absolute Path Usage: The use of an absolute path in Main.java for reading the CSV file is not recommended. Please switch to a relative path to ensure the project can be run by anyone without modifications.

  2. Package Structure: The current package structure does not adhere to the recommended organization. Consider organizing your code into packages like db, model, service, service.impl, and strategy for better maintainability and clarity.

  3. Handling Purchase Operation: The PurchaseOperation class currently does not check if the resulting balance is positive before subtracting the quantity. This is crucial to prevent invalid storage states. Please ensure that a RuntimeException is thrown if the balance becomes negative.

  4. Input and Output File Location: Ensure that input and output files are placed in the src/main/resources folder as per the checklist.

By addressing these issues, your code will be more robust and aligned with best practices. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.


public class PurchaseOperation implements OperationHandler {
public void handle(FruitTransaction transaction) {
Storage.subtract(transaction.getFruit(), transaction.getQuantity());

Choose a reason for hiding this comment

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

Ensure that the resulting balance in the storage is not negative after a purchase. If it is, throw a RuntimeException as per the checklist requirement: 'Handling Purchase operation. Check result balance before saving it in the Storage - it should be positive. Throw RuntimeException in case the balance is negative.'

Comment on lines 13 to 14
public static void subtract(String fruit, int quantity) {
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity);

Choose a reason for hiding this comment

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

Ensure that the resulting quantity after subtraction is not negative. If it is, throw a RuntimeException to prevent invalid storage states. This aligns with the checklist requirement: 'Handling Purchase operation. Check result balance before saving it in the Storage - it should be positive. Throw RuntimeException in case the balance is negative.'

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Great job on your progress! 🎉 While there are still a few critical issues to address, such as ensuring file paths are relative for portability and adding necessary checks to prevent invalid states or exceptions, your implementation is on the right track.

Here are some key points to focus on:

  1. File Paths: Ensure both input and output file paths are relative to make your project more portable. Consider using paths like "src/main/resources/input.csv" and "src/main/resources/finalReport.csv".

  2. Data Validation: Add validation in DataConverterImpl.java to handle potential parsing errors, ensuring that the input data is well-formed and any exceptions are managed gracefully.

  3. Operation Handling: In OperationStrategyImpl.java, add checks to handle cases where an operation might not have a corresponding handler to prevent NullPointerException.

  4. Storage Integrity: Update the subtract method in Storage.java to check for negative quantities and throw an exception if necessary, maintaining data integrity.

These improvements will enhance the robustness and reliability of your code. Keep up the good work, and make sure to address these issues in future iterations to avoid similar problems. Your dedication to learning and improving is commendable! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

String finalReport = reportGenerator.getReport();

MyFileWriter fileWriter = new FileWriterImpl();
fileWriter.write(finalReport, "src/main/resources/finalReport.csv");

Choose a reason for hiding this comment

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

The output file path should be relative to ensure the project can be run by anyone without modifications. Consider using a path like "src/main/resources/finalReport.csv".

}

public static void subtract(String fruit, int quantity) {
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity);

Choose a reason for hiding this comment

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

The subtract method should check if the resulting quantity is negative before updating the storage. Consider throwing a RuntimeException if the subtraction would result in a negative quantity, to prevent invalid storage states.

Comment on lines +12 to +18
for (int i = 1; i < rawData.size(); i++) {
String[] parts = rawData.get(i).split(",");
FruitTransaction.Operation operation = FruitTransaction.Operation.fromCode(parts[0]);
String fruit = parts[1];
int quantity = Integer.parseInt(parts[2]);
fruitTransactions.add(new FruitTransaction(operation, fruit, quantity));
}

Choose a reason for hiding this comment

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

The current implementation assumes that the input data is always well-formed. Consider adding validation to handle potential parsing errors, such as checking if parts has the expected length and catching NumberFormatException when parsing the quantity.

}

public OperationHandler getOperationHandler(FruitTransaction.Operation operation) {
return operationHandlers.get(operation);

Choose a reason for hiding this comment

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

Consider adding a check to handle cases where the operationHandlers map does not contain a handler for the given operation. You might want to throw an exception or return a default handler in such cases.

Comment on lines +15 to +17
OperationHandler handler = operationStrategy
.getOperationHandler(transaction.getOperation());
handler.handle(transaction);

Choose a reason for hiding this comment

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

Consider adding a check to handle cases where getOperationHandler might return null if a handler is not found for a given operation. This will prevent potential NullPointerException and improve robustness.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Thank you for your hard work on this project! 🎉 Your code is well-structured and mostly meets the task requirements. However, there are a few critical issues that need attention to ensure the functionality and robustness of your code:

  1. File Path Management: Ensure both the input (toRead.csv) and output (finalReport.csv) files are placed in the src/main/resources folder. This will help avoid file path issues and make your code more portable.

  2. Error Handling in Data Parsing: The DataConverterImpl.java assumes that the raw data is always correctly formatted. Consider adding error handling to manage cases where the data might be malformed, such as catching ArrayIndexOutOfBoundsException or NumberFormatException.

  3. Operation Handler Strategy: In OperationStrategyImpl.java, add a check to handle cases where an operation does not have a corresponding handler in the map. This will prevent potential NullPointerException and improve the robustness of your code.

  4. Storage Integrity: In Storage.java, ensure the subtract method checks if the resulting quantity is negative before updating the map. Throw a RuntimeException if the quantity becomes negative to maintain data integrity.

These improvements are crucial for the functionality of your application. Please address these issues in future iterations to enhance your code quality. Keep up the great work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

String finalReport = reportGenerator.getReport();

MyFileWriter fileWriter = new FileWriterImpl();
fileWriter.write(finalReport, "src/main/resources/finalReport.csv");

Choose a reason for hiding this comment

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

The output file path should be relative and placed in the src/main/resources folder as per the checklist. Consider changing the path to src/main/resources/finalReport.csv.

Comment on lines +13 to +14
public static void subtract(String fruit, int quantity) {
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity);

Choose a reason for hiding this comment

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

The subtract method should check if the resulting quantity is negative before updating the map. If the quantity becomes negative, consider throwing a RuntimeException to prevent invalid states in the storage.

Comment on lines +13 to +16
String[] parts = rawData.get(i).split(",");
FruitTransaction.Operation operation = FruitTransaction.Operation.fromCode(parts[0]);
String fruit = parts[1];
int quantity = Integer.parseInt(parts[2]);

Choose a reason for hiding this comment

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

The current implementation assumes that the raw data is always correctly formatted. Consider adding error handling to manage cases where the data might be malformed, such as catching ArrayIndexOutOfBoundsException or NumberFormatException.

Comment on lines +13 to +14
public OperationHandler getOperationHandler(FruitTransaction.Operation operation) {
return operationHandlers.get(operation);

Choose a reason for hiding this comment

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

Consider adding a check to handle cases where an operation does not have a corresponding handler in the map. You could throw an exception or return a default handler to prevent potential NullPointerException.

Comment on lines +15 to +17
OperationHandler handler = operationStrategy
.getOperationHandler(transaction.getOperation());
handler.handle(transaction);

Choose a reason for hiding this comment

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

Consider adding a check to handle cases where getOperationHandler returns null. This could happen if a transaction's operation does not have a corresponding handler, leading to a NullPointerException when calling handle.

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