Skip to content

Commit

Permalink
Merge pull request #155 from J0shuaLeong/master
Browse files Browse the repository at this point in the history
Solve storage load error and force quit storage saving
  • Loading branch information
J0shuaLeong authored Nov 2, 2023
2 parents d088998 + 055df39 commit 1b118c7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/fittrack/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import fittrack.parser.CommandParser;
import fittrack.parser.PatternMatchFailException;

import java.io.IOException;


public class ExitCommand extends Command {
public static final String COMMAND_WORD = "exit";
Expand All @@ -21,6 +23,11 @@ public static boolean isExit(Command command) {

@Override
public CommandResult execute() {
try {
storage.save(userProfile, mealList, workoutList);
} catch (IOException e) {
System.out.println("Failed to save to storage.");
}
return new CommandResult(MESSAGE_EXIT);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fittrack/data/Meal.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Meal(String name, Calories calories, Date date) {
}

public String formatToFile() {
return String.format("%s | %s| %s", name, calories, date);
return String.format("%s | %s | %s", name, calories, date);
}

public Calories getCalories() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fittrack/storage/MealListDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class MealListDecoder {

private static final Pattern MEAL_PATTERN = Pattern.compile(
"(?<name>[^|]+)\\s*\\|\\s*(?<calories>\\d+\\.\\d+)kcal\\s*\\|\\s*(?<date>\\S+)"
"(?<name>\\S+)\\s*\\|\\s*(?<calories>\\S+)kcal\\s*\\|\\s*(?<date>\\S+)"
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fittrack/storage/WorkoutListDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class WorkoutListDecoder {

private static final Pattern WORKOUT_PATTERN = Pattern.compile(
"(?<name>[^|]+)\\s*\\|\\s*(?<calories>\\d+\\.\\d+)kcal\\s*\\|\\s*(?<date>\\S+)"
"(?<name>\\S+)\\s*\\|\\s*(?<calories>\\S+)kcal\\s*\\|\\s*(?<date>\\S+)" // add \\d+\\.\\d+ if got decimal
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/fittrack/data/MealTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void constructor_null_assert() {

@Test
void formatToFile_tm_success() {
assertEquals("meal | 100kcal| 2023-10-30", tm.formatToFile());
assertEquals("meal | 100kcal | 2023-10-30", tm.formatToFile());
}

@Test
Expand Down

0 comments on commit 1b118c7

Please sign in to comment.