Package com.cis.gorecipe.controller
Class UserController
java.lang.Object
com.cis.gorecipe.controller.UserController
This class handles the API endpoints related to user account management
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.springframework.security.crypto.bcrypt.BCryptPasswordEncoderHandles hashing passwords and checking password equalityprivate RecipeCalendarItemRepositoryFor interfacing with the RecipeCalendarItem table in the databaseprivate SimpleDateFormatFor parsing datesprivate IngredientRepositoryFor interfacing with the Ingredient table in the databaseprivate org.slf4j.LoggerFor logging any errors that occur during runtime (e.g.private RecipeRepositoryFor interfacing with the Recipe table in the database(package private) String[]private S3Serviceprivate UserRepositoryFor interfacing with the User table in the database -
Constructor Summary
ConstructorsConstructorDescriptionUserController(UserRepository userRepository, RecipeRepository recipeRepository, IngredientRepository ingredientRepository, RecipeCalendarItemRepository calendarRepository, S3Service s3Service) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Void>addDietaryRestrictionToAccount(Long userId, String dietaryRestriction)org.springframework.http.ResponseEntity<Void>addRecipeToUsersCalendar(String dateAsString, Long userId, Long recipeId)org.springframework.http.ResponseEntity<UserDTO>createUser(User user)org.springframework.http.ResponseEntity<Void>deleteRecipeFromDate(Long id)org.springframework.http.ResponseEntity<Void>deleteUser(Long id)getSavedRecipes(Long userId)org.springframework.http.ResponseEntity<UserDTO>org.springframework.http.ResponseEntity<List<RecipeCalendarItem>>getUsersCalendar(Long userId)org.springframework.http.ResponseEntity<UserDTO>org.springframework.http.ResponseEntity<Void>removeDietaryRestrictionFromAccount(Long userId, String dietaryRestriction)org.springframework.http.ResponseEntity<Void>removeSavedRecipeFromAccount(Long userId, Long recipeId)org.springframework.http.ResponseEntity<Void>saveRecipeToAccount(Long userId, Long recipeId)org.springframework.http.ResponseEntity<UserDTO>updateUser(Long id, UserDTO userDTO)org.springframework.http.ResponseEntity<User>uploadProfilePicture(org.springframework.web.multipart.MultipartFile image, Long id)
-
Field Details
-
logger
private final org.slf4j.Logger loggerFor logging any errors that occur during runtime (e.g. a user is not found) -
userRepository
For interfacing with the User table in the database -
recipeRepository
For interfacing with the Recipe table in the database -
ingredientRepository
For interfacing with the Ingredient table in the database -
bCryptPasswordEncoder
private final org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder bCryptPasswordEncoderHandles hashing passwords and checking password equality -
calendarRepository
For interfacing with the RecipeCalendarItem table in the database -
s3Service
-
formatter
For parsing dates -
restrictions
String[] restrictions
-
-
Constructor Details
-
UserController
public UserController(UserRepository userRepository, RecipeRepository recipeRepository, IngredientRepository ingredientRepository, RecipeCalendarItemRepository calendarRepository, S3Service s3Service)
-
-
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 systempassword- 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 recipeuserId- the user who wants to cook the reciperecipeId- 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 reciperecipeId- 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 reciperecipeId- 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 accountdietaryRestriction- 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 accountdietaryRestriction- 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
-