feat(client/service/shop): functional service backend
This commit is contained in:
parent
c0107d752a
commit
21b2465b91
5 changed files with 94 additions and 2 deletions
|
|
@ -21,8 +21,9 @@ import client.scenes.nutrition.NutritionDetailsCtrl;
|
|||
import client.scenes.nutrition.NutritionViewCtrl;
|
||||
import client.scenes.recipe.IngredientListCtrl;
|
||||
import client.scenes.recipe.RecipeStepListCtrl;
|
||||
import client.service.NonFunctionalShoppingListService;
|
||||
import client.scenes.shopping.ShoppingListCtrl;
|
||||
import client.service.ShoppingListService;
|
||||
import client.service.ShoppingListServiceImpl;
|
||||
import client.service.ShoppingListViewModel;
|
||||
import client.utils.ConfigService;
|
||||
import client.utils.LocaleManager;
|
||||
|
|
@ -60,8 +61,9 @@ public class MyModule implements Module {
|
|||
binder.bind(new TypeLiteral<WebSocketDataService<Long, Recipe>>() {}).toInstance(
|
||||
new WebSocketDataService<>()
|
||||
);
|
||||
binder.bind(ShoppingListCtrl.class).in(Scopes.SINGLETON);
|
||||
binder.bind(ShoppingListViewModel.class).toInstance(new ShoppingListViewModel());
|
||||
binder.bind(ShoppingListService.class).to(NonFunctionalShoppingListService.class);
|
||||
binder.bind(ShoppingListService.class).to(ShoppingListServiceImpl.class);
|
||||
binder.bind(new TypeLiteral<WebSocketDataService<Long, Ingredient>>() {}).toInstance(
|
||||
new WebSocketDataService<>()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package client.service;
|
||||
|
||||
import commons.FormalIngredient;
|
||||
public class ShoppingListItem {
|
||||
private FormalIngredient i;
|
||||
}
|
||||
|
|
@ -14,6 +14,15 @@ public abstract class ShoppingListService {
|
|||
public ShoppingListService(ShoppingListViewModel viewModel) {
|
||||
this.viewModel = viewModel;
|
||||
}
|
||||
|
||||
public ShoppingListViewModel getViewModel() {
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public void setViewModel(ShoppingListViewModel viewModel) {
|
||||
this.viewModel = viewModel;
|
||||
}
|
||||
|
||||
public abstract void putIngredient(FormalIngredient ingredient);
|
||||
public abstract void putIngredient(FormalIngredient ingredient, Recipe recipe);
|
||||
public abstract void putIngredient(FormalIngredient ingredient, String recipeName);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package client.service;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import commons.FormalIngredient;
|
||||
import commons.Recipe;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ShoppingListServiceImpl extends ShoppingListService {
|
||||
private final Logger logger = Logger.getLogger(ShoppingListServiceImpl.class.getName());
|
||||
@Inject
|
||||
public ShoppingListServiceImpl(
|
||||
ShoppingListViewModel model
|
||||
) {
|
||||
super(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putIngredient(FormalIngredient ingredient) {
|
||||
getViewModel().getListItems().add(new Pair<>(ingredient, Optional.empty()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putIngredient(FormalIngredient ingredient, Recipe recipe) {
|
||||
Pair<FormalIngredient, Optional<String>> val = new Pair<>(ingredient, Optional.of(recipe.getName()));
|
||||
logger.info("putting ingredients into shopping list: " + val);
|
||||
getViewModel().getListItems().add(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putIngredient(FormalIngredient ingredient, String recipeName) {
|
||||
getViewModel().getListItems().add(new Pair<>(ingredient, Optional.of(recipeName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putArbitraryItem(String name) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalIngredient purgeIngredient(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalIngredient purgeIngredient(String ingredientName) {
|
||||
FormalIngredient fi = getViewModel().getListItems().stream()
|
||||
.filter(i ->
|
||||
i.getKey().getIngredient().getName().equals(ingredientName))
|
||||
.findFirst().orElseThrow(NullPointerException::new).getKey();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
getViewModel().getListItems().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<FormalIngredient, Optional<String>>> getItems() {
|
||||
return getViewModel().getListItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String makePrintable() {
|
||||
return "TODO";
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import commons.FormalIngredient;
|
|||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
|
|
@ -19,4 +20,7 @@ public class ShoppingListViewModel {
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ObservableList<Pair<FormalIngredient, Optional<String>>> getListItems() {
|
||||
return listItems.get();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue