Skip to content

Commit

Permalink
Add delete dietSession
Browse files Browse the repository at this point in the history
  • Loading branch information
zsk612 committed Oct 15, 2020
1 parent 8288eb4 commit e2aea22
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
7 changes: 1 addition & 6 deletions saves/diet/unspecified 2020-10-15.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"foodList": [
{
"name": "ad ",
"calories": 4324.0
}
],
"foodList": [],
"dateInput": "10-15-2020",
"typeInput": "unspecified",
"date": {
Expand Down
29 changes: 29 additions & 0 deletions saves/workout/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,34 @@
"nano": 511306700
}
}
},
{
"filePath": "saves/workout/workoutSession/13.json",
"creationTime": {
"date": {
"year": 2020,
"month": 10,
"day": 15
},
"time": {
"hour": 23,
"minute": 15,
"second": 59,
"nano": 780775900
}
},
"lastEditTime": {
"date": {
"year": 2020,
"month": 10,
"day": 15
},
"time": {
"hour": 23,
"minute": 15,
"second": 59,
"nano": 781404500
}
}
}
]
2 changes: 2 additions & 0 deletions src/main/java/diet/dietmanager/CommandLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import diet.dietmanager.command.Command;
import diet.dietmanager.command.DietSessionCreate;
import diet.dietmanager.command.DietSessionDelete;
import diet.dietmanager.command.DietSessionList;
import diet.dietmanager.command.DietSessionLoad;
import diet.dietmanager.command.DietSessionWrong;
Expand All @@ -20,6 +21,7 @@ public void initDietManagerCL() {
this.library.put("list", new DietSessionList());
this.library.put("meal", new DietSessionCreate());
this.library.put("load", new DietSessionLoad());
this.library.put("delete", new DietSessionDelete());
}

public Command get(String keyword) {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/diet/dietmanager/command/DietSessionDelete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package diet.dietmanager.command;

import diet.dietsession.Food;
import storage.diet.Storage;

import java.io.File;

public class DietSessionDelete implements Command {
static final String FILEPATH = "saves/diet/";

@Override
public void execute(String input, Storage storage) {
File folder = new File(FILEPATH);
File[] listOfFiles = folder.listFiles();
try {
assert !input.isEmpty();
int index = Integer.parseInt(input);
assert listOfFiles != null;
String fileName = listOfFiles[Integer.parseInt(input) - 1].getName();
System.out.println("Oh no! You have deleted " + fileName);
listOfFiles[Integer.parseInt(input) - 1].delete();
} catch (IndexOutOfBoundsException | NumberFormatException e) {
System.out.println("Sorry! It seems like you've entered an invalid number or input!");
}
}
}

0 comments on commit e2aea22

Please sign in to comment.