package act.fsa.todo;

import act.boot.app.RunApp;
import org.bson.types.ObjectId;
import org.osgl.mvc.annotation.DeleteAction;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.mvc.annotation.PutAction;
import org.osgl.mvc.result.Result;
import org.osgl.util.C;

import javax.inject.Inject;
import java.util.List;

import static act.controller.Controller.Util.ok;
import static act.controller.Controller.Util.render;

/**
 * Demonstrate Job annotations
 */
public class TodoApp {

    @Inject
    public TodoItemDao dao;

    public TodoApp() {
        //logger.info(new RuntimeException(), "JobApp initialized");
    }

    @GetAction("/")
    public Result home() {
        return render();
    }

    @GetAction("/list")
    public Result list() {
        List<TodoItem> list = C.list(dao.findAll());
        return render(list);
    }

    @PostAction("/list")
    public Result add(String desc) {
        TodoItem item = new TodoItem(desc);
        dao.save(item);
        return ok();
    }

    @DeleteAction("/list/{id}")
    public Result delete(String id) {
        TodoItem item = dao.findById(new ObjectId(id));
        dao.delete(item);
        return ok();
    }

    @PutAction("/list/{id}")
    public Result update(String id, String desc) {
        TodoItem item = dao.findById(new ObjectId(id));
        item.setDesc(desc);
        dao.save(item);
        return ok();
    }

    public static void main(String[] args) throws Exception {
        RunApp.start(TodoApp.class);
    }

}

@@ -539,29 +539,30 @@
 Inject%0A    p
-ublic
+rivate
  TodoItemDao
@@ -572,107 +572,8 @@
 o;%0A%0A
-    public TodoApp() %7B%0A        //logger.info(new RuntimeException(), %22JobApp initialized%22);%0A    %7D%0A%0A
     

make dao injection be private