Package com.cis.gorecipe.controller
Class FoodImageController
java.lang.Object
com.cis.gorecipe.controller.FoodImageController
This class handles the API endpoints related to uploading images of ingredients and the processing of
those images
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClarifaiServiceHandles all interactions with the Clarifai Food Recognition APIprivate FoodImageRepositoryFor interfacing with the FoodImage table in the databaseprivate IngredientRepositoryFor interfacing with the Ingredient table in the databaseprivate org.slf4j.LoggerFor logging any errors that occur during runtime (e.g.private S3ServiceHandles all interactions with AWS S3private UserRepositoryFor interfacing with the User table in the database -
Constructor Summary
ConstructorsConstructorDescriptionFoodImageController(FoodImageRepository foodImageRepository, UserRepository userRepository, IngredientRepository ingredientRepository, S3Service s3Service, ClarifaiService clarifaiService) -
Method Summary
Modifier and TypeMethodDescriptiongetUserImages(Long id)org.springframework.http.ResponseEntity<FoodImage>updateImageIngredients(String id, List<String> ingredients)This method allows users to correct misclassification of ingredients in images by supplying their owl list of ingredientsorg.springframework.http.ResponseEntity<FoodImage>uploadImage(org.springframework.web.multipart.MultipartFile image, Long userId)
-
Field Details
-
logger
private final org.slf4j.Logger loggerFor logging any errors that occur during runtime (e.g. a user is not found) -
foodImageRepository
For interfacing with the FoodImage table in the database -
userRepository
For interfacing with the User table in the database -
ingredientRepository
For interfacing with the Ingredient table in the database -
s3Service
Handles all interactions with AWS S3 -
clarifaiService
Handles all interactions with the Clarifai Food Recognition API
-
-
Constructor Details
-
FoodImageController
public FoodImageController(FoodImageRepository foodImageRepository, UserRepository userRepository, IngredientRepository ingredientRepository, S3Service s3Service, ClarifaiService clarifaiService)
-
-
Method Details
-
uploadImage
@PostMapping(path="/upload/{userId}", consumes="multipart/form-data") public org.springframework.http.ResponseEntity<FoodImage> uploadImage(@RequestPart("image") org.springframework.web.multipart.MultipartFile image, @PathVariable("userId") Long userId) throws IOException- Parameters:
image- a JPEG imageuserId- the ID of the user who uploaded the image- Returns:
- the ingredient that GoRecipe has determined to be in the image
- Throws:
IOException
-
getUserImages
@GetMapping("/user/{id}") public org.springframework.http.ResponseEntity<List<FoodImage>> getUserImages(@PathVariable("id") Long id)- Parameters:
id- the ID of a user- Returns:
- a list of images uploaded by the specified user
-
getImage
- Parameters:
id- the FoodImage/AWS S3 object ID of the image- Returns:
- the URL of the image specified by the id
-
updateImageIngredients
@PostMapping("/{id}") public org.springframework.http.ResponseEntity<FoodImage> updateImageIngredients(@PathVariable String id, @RequestBody List<String> ingredients)This method allows users to correct misclassification of ingredients in images by supplying their owl list of ingredients- Parameters:
id- the ID of the image objectingredients- the list of new ingredients to associate with the image- Returns:
- the updated image object
-