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

first_attempt #1283

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

Conversation

dantesworld
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 meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the PurchaseOperation class should check for negative balances and throw a RuntimeException if necessary. Additionally, exception handling in FileWriterImpl should be improved by including the exception object for better error tracking. Please also ensure that file paths are relative and that the package structure aligns with the checklist. 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.

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

Something went wrong while processing the review.
[CODE: 3]

If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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 addressing the previous review comments and aligning your code with the task requirements! 🎉 Your implementation is well-structured, and the package organization is on point. Here are a few key points from the review:

  • PurchaseOperation Class: You've successfully implemented a check for negative balances, throwing a RuntimeException when necessary. This is crucial for maintaining data integrity during purchase operations.

  • FileWriterImpl Class: The improvement in exception handling by including the exception object in the RuntimeException is a significant enhancement for error tracking.

  • Relative File Paths: Using relative paths ensures that your project is accessible and runnable by anyone, which is a great practice.

  • Package Structure: Your classes are well-organized into appropriate packages, which enhances the readability and maintainability of your code.

While the code meets the task requirements, remember to address any critical issues in future projects to avoid similar problems. For instance, ensure that exception handling in all classes, such as FileReaderImpl, includes the exception object for detailed error information. This will help you provide more context about errors and improve debugging.

Keep up the great 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! ✨

Comment on lines 16 to 17
} catch (IOException e) {
throw new RuntimeException("Error reading file: " + fileName);

Choose a reason for hiding this comment

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

The exception handling here should include the exception object e in the RuntimeException to provide more detailed error information. Modify the line to: throw new RuntimeException("Error reading file: " + fileName, e);

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 ;)

import java.util.ArrayList;
import java.util.List;

public class FileReaderImpl implements FileReaderMy {

Choose a reason for hiding this comment

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

Suggested change
public class FileReaderImpl implements FileReaderMy {
public class CustomFileReaderImpl implements CustomFileReader {

import java.io.BufferedWriter;
import java.io.IOException;

public class FileWriterImpl implements FileWriterMy {

Choose a reason for hiding this comment

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

the same

try (BufferedWriter bufferedWriter = new BufferedWriter(new java.io.FileWriter(fileName))) {
bufferedWriter.write(info);
} catch (IOException e) {
throw new RuntimeException("Impossible to write in this file " + fileName, e);

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("Impossible to write in this file " + fileName, e);
throw new RuntimeException("Can’t write file with path: " + fileName, e);

Make the message more formal


@Override
public String getReport(Map<String, Integer> storage) {
StringJoiner report = new StringJoiner("\n");

Choose a reason for hiding this comment

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

better use System.lineseparator()

Comment on lines 11 to 14
report.add("fruit,quantity");

for (Map.Entry<String, Integer> entry : storage.entrySet()) {
report.add(entry.getKey() + "," + entry.getValue());

Choose a reason for hiding this comment

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

make header and separator constant fields

inputReport.stream()
.skip(1L)
.map(line -> line.split(","))
.filter(parts -> parts.length == 3)

Choose a reason for hiding this comment

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

you should throw an exception for invalid data


public class BalanceOperation implements OperationHandler {
@Override
public void handle(Map<String, Integer> storage, FruitTransaction transaction) {

Choose a reason for hiding this comment

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

Storage imitates real databases. So create a Storage class with a public static map

Comment on lines 8 to 9
public void handle(Map<String, Integer> storage, FruitTransaction transaction) {
storage.put(transaction.getFruit(), transaction.getQuantity());

Choose a reason for hiding this comment

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

Suggested change
public void handle(Map<String, Integer> storage, FruitTransaction transaction) {
storage.put(transaction.getFruit(), transaction.getQuantity());
public void handle(FruitTransaction transaction) {
Storage.storage.put(transaction.getFruit(), transaction.getQuantity());


@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 check that strategy return handler

}

@Override
public Map<String, Integer> process(List<FruitTransaction> transactions) {

Choose a reason for hiding this comment

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

Suggested change
public Map<String, Integer> process(List<FruitTransaction> transactions) {
public void process(List<FruitTransaction> transactions) {

use Storage

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