Class FoodImageController

java.lang.Object
com.cis.gorecipe.controller.FoodImageController

@RestController @RequestMapping("/api/images") public class FoodImageController extends Object
This class handles the API endpoints related to uploading images of ingredients and the processing of those images
  • Field Details

    • logger

      private final org.slf4j.Logger logger
      For logging any errors that occur during runtime (e.g. a user is not found)
    • foodImageRepository

      private final FoodImageRepository foodImageRepository
      For interfacing with the FoodImage table in the database
    • userRepository

      private final UserRepository userRepository
      For interfacing with the User table in the database
    • ingredientRepository

      private final IngredientRepository ingredientRepository
      For interfacing with the Ingredient table in the database
    • s3Service

      private final S3Service s3Service
      Handles all interactions with AWS S3
    • clarifaiService

      private final ClarifaiService clarifaiService
      Handles all interactions with the Clarifai Food Recognition API
  • Constructor Details

  • 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 image
      userId - 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

      @GetMapping("/{id}") public String getImage(@PathVariable("id") String id)
      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 object
      ingredients - the list of new ingredients to associate with the image
      Returns:
      the updated image object