diff --git a/backend/src/main/whattocook/Controller/SpoonacularController.java b/backend/src/main/whattocook/Controller/SpoonacularController.java index 3a22222..e91c4fb 100644 --- a/backend/src/main/whattocook/Controller/SpoonacularController.java +++ b/backend/src/main/whattocook/Controller/SpoonacularController.java @@ -6,36 +6,39 @@ import org.json.JSONException; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; -import org.springframework.stereotype.Controller; + import org.springframework.web.bind.annotation.GetMapping; -import whattocook.services.ApiService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import whattocook.services.SpoonacularApiService; import whattocook.repositories.ItemRepository; import java.io.IOException; import java.util.LinkedList; -@Controller +@RestController +@RequestMapping("/recipes") public class SpoonacularController { private int nextRecepies=10; private int nextRecepiesForOneRandom=20; @Autowired private ItemRepository itemRepository; @Autowired - private ApiService service; + private SpoonacularApiService service; - @GetMapping("api/forFridge") + @GetMapping("forFridge") public HttpEntity getForFridge() throws IOException, InterruptedException, JSONException { return new HttpEntity(service.getForIngridients(itemRepository.findAll(), nextRecepies)); } - @GetMapping("api/random") + @GetMapping("random") public HttpEntity getRandom() throws IOException, InterruptedException, JSONException { return new HttpEntity(service.getRandom(new LinkedList<>(), nextRecepies)); //when user has food preferences apply instead of linked list. } - @GetMapping("api/oneFridge" ) + @GetMapping("oneFridge") public HttpEntity getOneFridge() throws IOException, InterruptedException, JSONException { return new HttpEntity(service.getOneForIngridients(itemRepository.findAll(), nextRecepiesForOneRandom)); } diff --git a/backend/src/main/whattocook/implementation/ApiServiceImpl.java b/backend/src/main/whattocook/implementation/SpoonacularApiServiceImpl.java similarity index 86% rename from backend/src/main/whattocook/implementation/ApiServiceImpl.java rename to backend/src/main/whattocook/implementation/SpoonacularApiServiceImpl.java index 3a3e24e..557f2cc 100644 --- a/backend/src/main/whattocook/implementation/ApiServiceImpl.java +++ b/backend/src/main/whattocook/implementation/SpoonacularApiServiceImpl.java @@ -3,7 +3,7 @@ package whattocook.implementation; import org.springframework.stereotype.Service; import whattocook.models.Item; -import whattocook.services.ApiService; +import whattocook.services.SpoonacularApiService; import org.json.*; import java.io.IOException; @@ -15,7 +15,7 @@ import java.util.Iterator; import java.util.Random; @Service -public class ApiServiceImpl implements ApiService { +public class SpoonacularApiServiceImpl implements SpoonacularApiService { private final String KEY = "85cc006d508b447a88e659cd748899db"; private final String RANKING = "2"; private final boolean IGNOREPANTRY = true; @@ -82,11 +82,5 @@ public class ApiServiceImpl implements ApiService { - public static void main(String[] args) throws IOException, InterruptedException { - HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create("https://api.spoonacular.com/recipes/random?apiKey=" + "85cc006d508b447a88e659cd748899db" + "&number=" + 10)) - .method("GET", HttpRequest.BodyPublishers.noBody()) - .build(); - HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); - } + } diff --git a/backend/src/main/whattocook/services/ApiService.java b/backend/src/main/whattocook/services/SpoonacularApiService.java similarity index 93% rename from backend/src/main/whattocook/services/ApiService.java rename to backend/src/main/whattocook/services/SpoonacularApiService.java index b8af462..8e18814 100644 --- a/backend/src/main/whattocook/services/ApiService.java +++ b/backend/src/main/whattocook/services/SpoonacularApiService.java @@ -5,7 +5,7 @@ import org.json.JSONException; import org.json.JSONObject; import whattocook.models.Item; -public interface ApiService { +public interface SpoonacularApiService { JSONArray getForIngridients(Iterable items, int number) throws java.io.IOException, InterruptedException, JSONException; JSONObject getOneForIngridients(Iterable items, int number) throws java.io.IOException, InterruptedException, JSONException;