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

Implement Report generator #1286

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

Implement Report generator #1286

wants to merge 10 commits into from

Conversation

euulu
Copy link

@euulu euulu commented Jan 29, 2025

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! There are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the PurchaseOperation class should include a check to prevent negative inventory values, and the file path for reading the CSV should be correctly set. Additionally, ensure that the getOperationByCode method handles all operation codes appropriately. Once these issues are resolved, your code will be in great shape! Keep up the great work! 😊

✨ 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.

return;
}
String operationCode = parts[0];
Operation operation = getOperationByCode(operationCode);

Choose a reason for hiding this comment

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

Ensure that the getOperationByCode method handles all possible operation codes defined in the FruitTransaction.Operation enum. Currently, it returns null if the code is not found, which is handled by skipping the transaction. Consider logging or handling unexpected operation codes more explicitly if needed.

public class Main {
public static void main(String[] args) {
FileReader fileReader = new CsvFileReader();
List<String> inputReport = fileReader.read("");

Choose a reason for hiding this comment

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

The file path for reading the input CSV file is currently an empty string. Replace it with the actual file path to ensure the program reads the correct file.

int quantity = transaction.getQuantity();
Storage.fruitStorage.put(
fruit,
Storage.fruitStorage.getOrDefault(fruit, 0) - quantity

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 ensure that the resulting quantity in storage does not become negative. If the purchase quantity exceeds the available stock, you might want to throw an exception or handle it appropriately.

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 implementing the solution! 🎉 Your code is well-structured and adheres to the task requirements for the most part. However, there are a few critical points to address:

  1. Negative Inventory Check: Ensure that the PurchaseOperation class includes a check to prevent negative inventory values. This is crucial for maintaining accurate stock levels.

  2. CSV File Path: Make sure all file operations use relative paths and are placed in the src/main/resources folder for consistency and ease of access.

  3. Handling All Operation Codes: The getOperationByCode method in the FruitTransaction class should handle all operation codes appropriately, throwing an IllegalArgumentException for unknown codes.

These issues are important for the functionality of your code, so please review and address them in future iterations. Keep up the good work, and continue learning from these experiences to enhance your coding skills! 🚀

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

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! Let’s improve your solution ;)

List<FruitTransaction> transactions = new ArrayList<>();
for (int i = 1; i < data.size(); i++) {
String line = data.get(i);
String[] parts = line.trim().split(",");

Choose a reason for hiding this comment

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

Suggested change
String[] parts = line.trim().split(",");
String[] parts = line.split(",");

Remove trim everywhere, It’s invalid data. Move separator to the constant fields

Comment on lines 21 to 25
try {
operation = Operation.getOperationByCode(operationCode);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e.getMessage(), e);
}

Choose a reason for hiding this comment

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

remove try-catch here

Comment on lines 27 to 29
if (fruit.isEmpty()) {
continue;
}

Choose a reason for hiding this comment

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

is it expected behavior? you should throw an exception if you have invalid data in the input file

try {
quantity = Integer.parseInt(parts[2].trim());
} catch (NumberFormatException e) {
continue;

Choose a reason for hiding this comment

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

the same

Comment on lines 10 to 14
StringBuilder reportBuilder = new StringBuilder("fruit,quantity\n");
String reportBody = inventory.entrySet()
.stream()
.map(entry -> entry.getKey() + "," + entry.getValue())
.collect(Collectors.joining("\n"));

Choose a reason for hiding this comment

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

move literals to the constant fields. Use System.lineseparator


public class ReportGeneratorImpl implements ReportGenerator {
@Override
public String generateReport(Map<String, Integer> inventory) {

Choose a reason for hiding this comment

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

Suggested change
public String generateReport(Map<String, Integer> inventory) {
public String generateReport() {

Don't pass storage as a parameter. You can call it directly


@Override
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.

better add a null check for the handler. and throw an exception if the handler doesn’t exist

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.

4 participants