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;
|
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 app.mealsmadeeasy.api.user.UserService;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
@ -16,15 +19,23 @@ public class MealsMadeEasyApiApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final RecipeService recipeService;
|
||||||
|
|
||||||
public MealsMadeEasyApiApplication(UserService userService) {
|
public MealsMadeEasyApiApplication(UserService userService, RecipeService recipeService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
this.recipeService = recipeService;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CommandLineRunner addTestUser() {
|
public CommandLineRunner addTestData() {
|
||||||
return args -> {
|
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
|
@Override
|
||||||
public String toString() {
|
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> {
|
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||||
Optional<UserEntity> findByUsername(String username);
|
Optional<UserEntity> findByUsername(String username);
|
||||||
|
UserEntity getByUsername(String username);
|
||||||
boolean existsByUsername(String username);
|
boolean existsByUsername(String username);
|
||||||
boolean existsByEmail(String email);
|
boolean existsByEmail(String email);
|
||||||
void deleteByUsername(String username);
|
void deleteByUsername(String username);
|
||||||
|
@ -11,6 +11,8 @@ public interface UserService {
|
|||||||
return this.createUser(username, email, rawPassword, Set.of());
|
return this.createUser(username, email, rawPassword, Set.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User getUser(String username);
|
||||||
|
|
||||||
User updateUser(User user);
|
User updateUser(User user);
|
||||||
void deleteUser(User user);
|
void deleteUser(User user);
|
||||||
void deleteUser(String username);
|
void deleteUser(String username);
|
||||||
|
@ -40,6 +40,11 @@ public final class UserServiceImpl implements UserService {
|
|||||||
return this.userRepository.save(draft);
|
return this.userRepository.save(draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getUser(String username) {
|
||||||
|
return this.userRepository.getByUsername(username);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User updateUser(User user) {
|
public User updateUser(User user) {
|
||||||
return this.userRepository.save((UserEntity) user);
|
return this.userRepository.save((UserEntity) user);
|
||||||
|
Loading…
Reference in New Issue
Block a user