Merge pull request #40 from cato447/remove-used-ingredients
Implement first draft to remove used ingredients
This commit is contained in:
39
backend/src/main/spoonaccular/AmountConversion.java
Normal file
39
backend/src/main/spoonaccular/AmountConversion.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package spoonaccular;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import spoonaccular.models.amount_conversion.ConvertedAmount;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AmountConversion {
|
||||
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final Dotenv dotenv = Dotenv.configure().ignoreIfMissing().ignoreIfMalformed().load();
|
||||
|
||||
private AmountConversion(){
|
||||
}
|
||||
|
||||
public static double convertAmount(String ingrdientName, Double sourceAmount, String sourceUnit, String targetUnit) throws IOException {
|
||||
Request request = APIAuthentication.addAuthHeaders(
|
||||
new Request.Builder()
|
||||
.url("https://" + dotenv.get("X-RapidAPI-Host") +
|
||||
"/recipes/convert?ingredientName=" + ingrdientName +
|
||||
"&targetUnit=" + targetUnit +
|
||||
"&sourceUnit=" + sourceUnit +
|
||||
"&sourceAmount=" + sourceAmount)
|
||||
).build();
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseString = response.body().string();
|
||||
try {
|
||||
return new ObjectMapper().readValue(responseString, ConvertedAmount.class).getTargetAmount();
|
||||
} catch (Exception e){
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,10 @@ import io.github.cdimascio.dotenv.Dotenv;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
import spoonaccular.models.ingredients_by_id.Ingredient;
|
||||
import spoonaccular.models.recipe_by_ingredient.ExtendedRecipeByIngredient;
|
||||
import spoonaccular.models.recipe_by_ingredient.RecipeByIngredient;
|
||||
import spoonaccular.models.recipe_information.Recipe;
|
||||
@@ -37,6 +40,16 @@ public class RecipeInformation {
|
||||
return new ObjectMapper().readValue(queryInformationBulk(idsString).body().string(), new TypeReference<>() {});
|
||||
}
|
||||
|
||||
public static List<Ingredient> getIngredientList(int recipeId) throws IOException, JSONException {
|
||||
Request request = APIAuthentication.addAuthHeaders(new Request.Builder()
|
||||
.url("https://" + dotenv.get("X-RapidAPI-Host") +
|
||||
"/recipes/" + recipeId + "/ingredientWidget.json"))
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
||||
return new ObjectMapper().readValue(jsonObject.getJSONArray("ingredients").toString(), new TypeReference<>() {});
|
||||
}
|
||||
|
||||
private static Response queryInformationBulk(String idsString) throws IOException {
|
||||
Request request = APIAuthentication.addAuthHeaders(new Request.Builder()
|
||||
.url("https://" + dotenv.get("X-RapidAPI-Host") +
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package spoonaccular.models.amount_conversion;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Generated;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"sourceAmount",
|
||||
"sourceUnit",
|
||||
"targetAmount",
|
||||
"targetUnit",
|
||||
"answer",
|
||||
"type"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class ConvertedAmount {
|
||||
|
||||
@JsonProperty("sourceAmount")
|
||||
private Double sourceAmount;
|
||||
@JsonProperty("sourceUnit")
|
||||
private String sourceUnit;
|
||||
@JsonProperty("targetAmount")
|
||||
private Double targetAmount;
|
||||
@JsonProperty("targetUnit")
|
||||
private String targetUnit;
|
||||
@JsonProperty("answer")
|
||||
private String answer;
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
|
||||
@JsonProperty("sourceAmount")
|
||||
public Double getSourceAmount() {
|
||||
return sourceAmount;
|
||||
}
|
||||
|
||||
@JsonProperty("sourceAmount")
|
||||
public void setSourceAmount(Double sourceAmount) {
|
||||
this.sourceAmount = sourceAmount;
|
||||
}
|
||||
|
||||
@JsonProperty("sourceUnit")
|
||||
public String getSourceUnit() {
|
||||
return sourceUnit;
|
||||
}
|
||||
|
||||
@JsonProperty("sourceUnit")
|
||||
public void setSourceUnit(String sourceUnit) {
|
||||
this.sourceUnit = sourceUnit;
|
||||
}
|
||||
|
||||
@JsonProperty("targetAmount")
|
||||
public Double getTargetAmount() {
|
||||
return targetAmount;
|
||||
}
|
||||
|
||||
@JsonProperty("targetAmount")
|
||||
public void setTargetAmount(Double targetAmount) {
|
||||
this.targetAmount = targetAmount;
|
||||
}
|
||||
|
||||
@JsonProperty("targetUnit")
|
||||
public String getTargetUnit() {
|
||||
return targetUnit;
|
||||
}
|
||||
|
||||
@JsonProperty("targetUnit")
|
||||
public void setTargetUnit(String targetUnit) {
|
||||
this.targetUnit = targetUnit;
|
||||
}
|
||||
|
||||
@JsonProperty("answer")
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
@JsonProperty("answer")
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
@JsonProperty("type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@JsonProperty("type")
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return this.additionalProperties;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String name, Object value) {
|
||||
this.additionalProperties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
package spoonaccular.models.ingredients_by_id;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Generated;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"metric",
|
||||
"us"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class Amount {
|
||||
|
||||
@JsonProperty("metric")
|
||||
private Metric metric;
|
||||
@JsonProperty("us")
|
||||
private Us us;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
|
||||
@JsonProperty("metric")
|
||||
public Metric getMetric() {
|
||||
return metric;
|
||||
}
|
||||
|
||||
@JsonProperty("metric")
|
||||
public void setMetric(Metric metric) {
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
@JsonProperty("us")
|
||||
public Us getUs() {
|
||||
return us;
|
||||
}
|
||||
|
||||
@JsonProperty("us")
|
||||
public void setUs(Us us) {
|
||||
this.us = us;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return this.additionalProperties;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String name, Object value) {
|
||||
this.additionalProperties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
package spoonaccular.models.ingredients_by_id;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Generated;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"name",
|
||||
"image",
|
||||
"amount"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class Ingredient {
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("image")
|
||||
private String image;
|
||||
@JsonProperty("amount")
|
||||
private Amount amount;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
|
||||
@JsonProperty("name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonProperty("name")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonProperty("image")
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
@JsonProperty("image")
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@JsonProperty("amount")
|
||||
public Amount getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@JsonProperty("amount")
|
||||
public void setAmount(Amount amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return this.additionalProperties;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String name, Object value) {
|
||||
this.additionalProperties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
package spoonaccular.models.ingredients_by_id;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Generated;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"value",
|
||||
"unit"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class Metric {
|
||||
|
||||
@JsonProperty("value")
|
||||
private Double value;
|
||||
@JsonProperty("unit")
|
||||
private String unit;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
|
||||
@JsonProperty("value")
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonProperty("unit")
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@JsonProperty("unit")
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return this.additionalProperties;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String name, Object value) {
|
||||
this.additionalProperties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
package spoonaccular.models.ingredients_by_id;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Generated;
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"value",
|
||||
"unit"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class Us {
|
||||
|
||||
@JsonProperty("value")
|
||||
private Double value;
|
||||
@JsonProperty("unit")
|
||||
private String unit;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
|
||||
@JsonProperty("value")
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonProperty("unit")
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@JsonProperty("unit")
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return this.additionalProperties;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String name, Object value) {
|
||||
this.additionalProperties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user