Basic set up of testing data and communication with front-end for recipe info.
This commit is contained in:
		
							parent
							
								
									1137f390b7
								
							
						
					
					
						commit
						2c897d6d50
					
				| @ -1,5 +1,8 @@ | ||||
| package app.mealsmadeeasy.api; | ||||
| 
 | ||||
| import app.mealsmadeeasy.api.recipe.Recipe; | ||||
| import app.mealsmadeeasy.api.recipe.RecipeService; | ||||
| import app.mealsmadeeasy.api.user.User; | ||||
| import app.mealsmadeeasy.api.user.UserService; | ||||
| import org.springframework.boot.CommandLineRunner; | ||||
| import org.springframework.boot.SpringApplication; | ||||
| @ -16,15 +19,23 @@ public class MealsMadeEasyApiApplication { | ||||
| 	} | ||||
| 
 | ||||
| 	private final UserService userService; | ||||
| 	private final RecipeService recipeService; | ||||
| 
 | ||||
| 	public MealsMadeEasyApiApplication(UserService userService) { | ||||
| 	public MealsMadeEasyApiApplication(UserService userService, RecipeService recipeService) { | ||||
| 		this.userService = userService; | ||||
|         this.recipeService = recipeService; | ||||
|     } | ||||
| 
 | ||||
| 	@Bean | ||||
| 	public CommandLineRunner addTestUser() { | ||||
| 	public CommandLineRunner addTestData() { | ||||
| 		return args -> { | ||||
| 			this.userService.createUser("test", "test@test.com", "test", Set.of()); | ||||
| 			final User testUser = this.userService.createUser( | ||||
| 					"test", "test@test.com", "test", Set.of() | ||||
| 			); | ||||
| 			final Recipe recipe = this.recipeService.create(testUser, "Test Recipe", "Hello, World!"); | ||||
| 			this.recipeService.setPublic(recipe, testUser, true); | ||||
| 			System.out.println("Created " + testUser); | ||||
| 			System.out.println("Created " + recipe); | ||||
| 		}; | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -177,7 +177,7 @@ public final class UserEntity implements User { | ||||
| 
 | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "User(" + this.id + ", " + this.username + ", " + this.email + ")"; | ||||
|         return "UserEntity(" + this.id + ", " + this.username + ", " + this.email + ")"; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -6,6 +6,7 @@ import java.util.Optional; | ||||
| 
 | ||||
| public interface UserRepository extends JpaRepository<UserEntity, Long> { | ||||
|     Optional<UserEntity> findByUsername(String username); | ||||
|     UserEntity getByUsername(String username); | ||||
|     boolean existsByUsername(String username); | ||||
|     boolean existsByEmail(String email); | ||||
|     void deleteByUsername(String username); | ||||
|  | ||||
| @ -11,6 +11,8 @@ public interface UserService { | ||||
|         return this.createUser(username, email, rawPassword, Set.of()); | ||||
|     } | ||||
| 
 | ||||
|     User getUser(String username); | ||||
| 
 | ||||
|     User updateUser(User user); | ||||
|     void deleteUser(User user); | ||||
|     void deleteUser(String username); | ||||
|  | ||||
| @ -40,6 +40,11 @@ public final class UserServiceImpl implements UserService { | ||||
|         return this.userRepository.save(draft); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public User getUser(String username) { | ||||
|         return this.userRepository.getByUsername(username); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public User updateUser(User user) { | ||||
|         return this.userRepository.save((UserEntity) user); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Jesse Brault
						Jesse Brault