Class UserController

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

@RestController @RequestMapping("/api/users") public class UserController extends Object
This class handles the API endpoints related to user account management
  • Field Details

    • logger

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

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

      private final RecipeRepository recipeRepository
      For interfacing with the Recipe table in the database
    • ingredientRepository

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

      private final org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder bCryptPasswordEncoder
      Handles hashing passwords and checking password equality
    • calendarRepository

      private final RecipeCalendarItemRepository calendarRepository
      For interfacing with the RecipeCalendarItem table in the database
    • s3Service

      private final S3Service s3Service
    • formatter

      private final SimpleDateFormat formatter
      For parsing dates
    • restrictions

      String[] restrictions
  • Constructor Details

  • Method Details

    • uploadProfilePicture

      @PostMapping("/{id}/profile-picture") public org.springframework.http.ResponseEntity<User> uploadProfilePicture(@RequestPart("image") org.springframework.web.multipart.MultipartFile image, @PathVariable("id") Long id) throws IOException
      Throws:
      IOException
    • createUser

      @PostMapping("/") public org.springframework.http.ResponseEntity<UserDTO> createUser(@RequestBody User user)
      Parameters:
      user - the data from which a new user should be created
      Returns:
      a DTO representing the newly created user
    • deleteUser

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteUser(@PathVariable Long id)
      Parameters:
      id - the id of the user to be deleted
      Returns:
      an HTTP response confirming if the user has been removed from the system
    • updateUser

      @PatchMapping("/{id}") public org.springframework.http.ResponseEntity<UserDTO> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO)
      Parameters:
      userDTO - the data which should be used to update an existing user
      Returns:
      a DTO representing the newly modified user
    • getUser

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<UserDTO> getUser(@PathVariable Long id)
      Parameters:
      id - the id of the user to be fetched
      Returns:
      a DTO representing the requested user
    • login

      @PostMapping("/login") public org.springframework.http.ResponseEntity<UserDTO> login(@RequestParam("username") String username, @RequestParam("password") String password)
      Parameters:
      username - the username of some user in the system
      password - a plaintext password corresponding to the user with the specified username
      Returns:
      an HTTP response that contains a DTO of the specified user if the login was successful and an error message if it failed
    • addRecipeToUsersCalendar

      @PostMapping("/{userId}/calendar/{recipeId}") public org.springframework.http.ResponseEntity<Void> addRecipeToUsersCalendar(@RequestBody String dateAsString, @PathVariable Long userId, @PathVariable Long recipeId)
      Parameters:
      dateAsString - the date on which the user wants to cook a recipe
      userId - the user who wants to cook the recipe
      recipeId - the recipe which the user wants to cook
      Returns:
      an HTTP status indicating if the item was saved or not
    • deleteRecipeFromDate

      @DeleteMapping("/calendar/{id}") public org.springframework.http.ResponseEntity<Void> deleteRecipeFromDate(@PathVariable Long id)
      Parameters:
      id - the ID of the calendar item to remove
      Returns:
      an HTTP response indicating if the item has successfully been deleted
    • getUsersCalendar

      @GetMapping("/{userId}/calendar") public org.springframework.http.ResponseEntity<List<RecipeCalendarItem>> getUsersCalendar(@PathVariable Long userId)
      Parameters:
      userId - the ID of the user whose calendar we want
      Returns:
      a list of all items saved to the user's calendar
    • getSavedRecipes

      @GetMapping("/{userId}/recipes") public org.springframework.http.ResponseEntity<List<Recipe>> getSavedRecipes(@PathVariable Long userId)
      Parameters:
      userId - the id of the user who's saved recipes are being requested
      Returns:
      a list of recipes that the specified user saved
    • saveRecipeToAccount

      @PostMapping("/{userId}/recipes/{recipeId}") public org.springframework.http.ResponseEntity<Void> saveRecipeToAccount(@PathVariable Long userId, @PathVariable Long recipeId)
      Parameters:
      userId - the id of the user who is saving the specified recipe
      recipeId - the id of the recipe which the user is attempting to save
      Returns:
      an HTTP response that confirms if the recipe has been saved to the user's account
    • removeSavedRecipeFromAccount

      @DeleteMapping("/{userId}/recipes/{recipeId}") public org.springframework.http.ResponseEntity<Void> removeSavedRecipeFromAccount(@PathVariable Long userId, @PathVariable Long recipeId)
      Parameters:
      userId - the id of the user who is removing the specified recipe
      recipeId - the id of the recipe which the user is attempting to remove from their account
      Returns:
      an HTTP response that confirms if the recipe has been unsaved to the user's account
    • addDietaryRestrictionToAccount

      @PostMapping("/{userId}/dietary-restrictions") public org.springframework.http.ResponseEntity<Void> addDietaryRestrictionToAccount(@PathVariable Long userId, @RequestParam String dietaryRestriction)
      Parameters:
      userId - the id of the user who is adding a dietary restriction to their account
      dietaryRestriction - the id of the dietary restriction that the user is attempting to add to their account
      Returns:
      an HTTP response that confirms if the dietary restriction has been added to the user's account
    • removeDietaryRestrictionFromAccount

      @DeleteMapping("/{userId}/dietary-restrictions") public org.springframework.http.ResponseEntity<Void> removeDietaryRestrictionFromAccount(@PathVariable Long userId, @RequestParam String dietaryRestriction)
      Parameters:
      userId - the id of the user who is removing a dietary restriction from their account
      dietaryRestriction - the id of the dietary restriction that the user is attempting to remove from their account
      Returns:
      an HTTP response that confirms if the dietary restriction has been removed from the user's account