package io.github.javageeks.mase.web.util;

import io.github.javageeks.mase.model.Todo;
import io.github.javageeks.mase.service.TodoService;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
 * Utility bean used to populate the database with fake data at application's startup.
 */
@Profile("dev")
@Component
public class DatabasePopulator {

    @Autowired
    private TodoService todoService;

    @PostConstruct
    public void populateDatabase() {

        Todo todo = new Todo();
        todo.setId(1);
        todo.setUserId(1);
        todo.setTitle("Milk");
        todo.setDescription("Remember the milk!");
        todo.setStatus(false);
        todoService.create(todo);

    }

}

@@ -81,16 +81,60 @@
 l.Todo;%0A
+import io.github.javageeks.mase.model.User;%0A
 import i
@@ -219,16 +219,69 @@
 truct;%0A%0A
+import io.github.javageeks.mase.service.UserService;%0A
 import o
@@ -649,16 +649,69 @@
 rvice;%0A%0A
+    @Autowired%0A    private UserService userService;%0A%0A
     @Pos
@@ -771,40 +771,229 @@
     
-Todo todo = new Todo(
+User user = new User();%0A        user.setFirstName(%22Foo%22);%0A        user.setLastName(%22Bar%22);%0A        user.setEmail(%22foo@bar.org%22);%0A        user.setPassword(%22foobar%22);%0A        user = userService.saveOrUpdate(user
 );%0A
+%0A
         
 todo
@@ -992,20 +992,29 @@
     
-todo.setId(1
+Todo todo = new Todo(
 );%0A 
@@ -1039,9 +1039,20 @@
 rId(
-1
+user.getId()
 );%0A 
@@ -1187,11 +1187,17 @@
 ice.
-cre
+saveOrUpd
 ate(

add fake user to database populator