commit d2757f192a25fb8ac0dca540d3c85b5bcea3c12e
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Fri Aug 24 00:15:48 2018 +0700

    FIX auth controller

diff --git a/src/main/java/com/wanichnun/todoapp/controller/AuthController.java b/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
new file mode 100644
index 0000000..723e004
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
@@ -0,0 +1,27 @@
+package com.wanichnun.todoapp.controller;
+
+import com.wanichnun.todoapp.model.AuthRequest;
+import com.wanichnun.todoapp.model.Response;
+import com.wanichnun.todoapp.model.ResponseModel;
+import com.wanichnun.todoapp.service.AuthService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(path = "/api/v1/auth")
+public class AuthController {
+    @Autowired
+    private AuthService authService;
+
+    @PostMapping()
+    public HttpEntity<ResponseModel> update(
+            @RequestBody AuthRequest request
+            ) {
+        return new ResponseModel(Response.SUCCESS.getContent(), authService.getAccessToken(request)).build(HttpStatus.OK);
+    }
+}
\ No newline at end of file

commit 01c09050397f0f7e9abcf5d830d0740c995bdea9
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Fri Aug 24 00:09:30 2018 +0700

    REFACTOR

diff --git a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
index 28532bf..99a884e 100644
--- a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
@@ -19,37 +19,37 @@ import static org.valid4j.Assertive.require;
 @LineMessageHandler
 @Slf4j
 public class MessageHandler {
 
     @Autowired
     private TodoService todoService;
 
     private static final String EDIT = "edit";
     private static final String WRONG_FORMAT = "Wrong format";
 
     @Value("${web.url}")
     private String webUrl;
 
     @EventMapping
     public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
         log.info("Got message this bot: {}", event);
         try {
-            if (EDIT.equals(event.getMessage().getText())) {
+            if (EDIT.equalsIgnoreCase(event.getMessage().getText())) {
                 return new TextMessage(webUrl);
             }
             else {
                 String userId = event.getSource().getUserId();
                 String messageContent = event.getMessage().getText();
                 return todoService.handleTodoCreateRequest(userId, messageContent);
             }
         }
         catch (RequireViolation re) {
             return new TextMessage(re.getMessage());
         }
         catch (Exception e) {
             e.printStackTrace();
             log.error("Error " + e);
             return new TextMessage(WRONG_FORMAT);
         }
 
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 7219b19..e586d03 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -20,114 +20,116 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private static final String TODAY = "today";
     private static final String TOMORROW = "tomorrow";
     private static final String INVALID_TEXT_FORMAT = "Invalid text format";
     private static final String INVALID_DATE_FORMAT = "Invalid date format";
     private static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
+    private static final String DEFAULT_TIME = "12:00";
+    private static final String MESSAGE_SPLITTER = " : ";
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     @LogExecutionTime
     public TextMessage handleTodoCreateRequest(String userId, String message) {
         Boolean isPinned = false;
         Boolean isDone = false;
 
 
-        String[] splittedMessage = message.split(" : ");
+        String[] splittedMessage = message.split(MESSAGE_SPLITTER);
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, INVALID_TEXT_FORMAT);
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
-        String timeText = "12:00";
+        String timeText = DEFAULT_TIME;
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
 
         if (dateText.equalsIgnoreCase(TODAY)) {
             dateText = convertDate(TODAY);
         }
         if (dateText.equalsIgnoreCase(TOMORROW)) {
             dateText = convertDate(TOMORROW);
         }
 
         Date date;
         try {
             date = format.parse(dateText + " " + timeText);
         } catch (ParseException pe) {
             pe.printStackTrace();
             return new TextMessage(INVALID_DATE_FORMAT);
         }
 
         this.create(userId, taskName, isPinned, isDone, date);
         return new TextMessage(Response.SUCCESS.getContent());
     }
 
     private String convertDate(String date) {
         StringBuilder sb = new StringBuilder();
         Calendar calendar = Calendar.getInstance();
 
         if (date.equalsIgnoreCase(TOMORROW)) {
             calendar.add(Calendar.DATE, 1);
         }
 
         sb.append(calendar.get(Calendar.DAY_OF_MONTH)).append("/");
         sb.append(calendar.get(Calendar.MONTH)).append("/");
         sb.append(calendar.get(Calendar.YEAR));
 
         return sb.toString();
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     private Long calculateOrder(String userId) {
         return (long) (todoRepository.findByUserId(userId).size() + 1);
     }
 
     public List<Todo> listTodos(String userId) {
         List<Todo> todoList = todoRepository.findByUserIdOrderByOrderAsc(userId);
         List<Todo> pinnedTodoList = new ArrayList<>();
         List<Todo> sortedTodoList = new ArrayList<>();
         todoList.forEach((todo -> {
             if (todo.getIsPinned()) {
                 pinnedTodoList.add(todo);
             }
         }));
 
         todoList.removeAll(pinnedTodoList);
         sortedTodoList.addAll(pinnedTodoList);
         sortedTodoList.addAll(todoList);
 
         return sortedTodoList;
     }
 
     public List<Todo> updateOrder(String userId, List<Todo> todoList) {
         require(todoRepository.findByUserId(userId).size() > 0);
         for (int i = 0; i < todoList.size(); i++) {
             todoList.get(i).setOrder((long) i+1);
         }
         return todoRepository.saveAll(todoList);
     }
 }

commit bc0804d2361b8826cede17adc248e69a72ffd6e6
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 23:54:46 2018 +0700

    FIX line hook not working

diff --git a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
index 84ca8ff..28532bf 100644
--- a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
@@ -19,38 +19,37 @@ import static org.valid4j.Assertive.require;
 @LineMessageHandler
 @Slf4j
 public class MessageHandler {
 
     @Autowired
     private TodoService todoService;
 
     private static final String EDIT = "edit";
     private static final String WRONG_FORMAT = "Wrong format";
 
     @Value("${web.url}")
     private String webUrl;
 
-    @LogExecutionTime
     @EventMapping
     public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
         log.info("Got message this bot: {}", event);
         try {
             if (EDIT.equals(event.getMessage().getText())) {
                 return new TextMessage(webUrl);
             }
             else {
                 String userId = event.getSource().getUserId();
                 String messageContent = event.getMessage().getText();
                 return todoService.handleTodoCreateRequest(userId, messageContent);
             }
         }
         catch (RequireViolation re) {
             return new TextMessage(re.getMessage());
         }
         catch (Exception e) {
             e.printStackTrace();
             log.error("Error " + e);
             return new TextMessage(WRONG_FORMAT);
         }
 
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 0bce604..7219b19 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -3,2 +3,3 @@ package com.wanichnun.todoapp.service;
 import com.linecorp.bot.model.message.TextMessage;
+import com.wanichnun.todoapp.annotation.LogExecutionTime;
 import com.wanichnun.todoapp.document.Todo;
@@ -6,2 +7,3 @@ import com.wanichnun.todoapp.model.Response;
 import com.wanichnun.todoapp.repository.TodoRepository;
+import lombok.extern.java.Log;
 import lombok.extern.slf4j.Slf4j;
@@ -18,113 +20,114 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private static final String TODAY = "today";
     private static final String TOMORROW = "tomorrow";
     private static final String INVALID_TEXT_FORMAT = "Invalid text format";
     private static final String INVALID_DATE_FORMAT = "Invalid date format";
     private static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
+    @LogExecutionTime
     public TextMessage handleTodoCreateRequest(String userId, String message) {
         Boolean isPinned = false;
         Boolean isDone = false;
 
 
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, INVALID_TEXT_FORMAT);
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
 
         if (dateText.equalsIgnoreCase(TODAY)) {
             dateText = convertDate(TODAY);
         }
         if (dateText.equalsIgnoreCase(TOMORROW)) {
             dateText = convertDate(TOMORROW);
         }
 
         Date date;
         try {
             date = format.parse(dateText + " " + timeText);
         } catch (ParseException pe) {
             pe.printStackTrace();
             return new TextMessage(INVALID_DATE_FORMAT);
         }
 
         this.create(userId, taskName, isPinned, isDone, date);
         return new TextMessage(Response.SUCCESS.getContent());
     }
 
     private String convertDate(String date) {
         StringBuilder sb = new StringBuilder();
         Calendar calendar = Calendar.getInstance();
 
         if (date.equalsIgnoreCase(TOMORROW)) {
             calendar.add(Calendar.DATE, 1);
         }
 
         sb.append(calendar.get(Calendar.DAY_OF_MONTH)).append("/");
         sb.append(calendar.get(Calendar.MONTH)).append("/");
         sb.append(calendar.get(Calendar.YEAR));
 
         return sb.toString();
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     private Long calculateOrder(String userId) {
         return (long) (todoRepository.findByUserId(userId).size() + 1);
     }
 
     public List<Todo> listTodos(String userId) {
         List<Todo> todoList = todoRepository.findByUserIdOrderByOrderAsc(userId);
         List<Todo> pinnedTodoList = new ArrayList<>();
         List<Todo> sortedTodoList = new ArrayList<>();
         todoList.forEach((todo -> {
             if (todo.getIsPinned()) {
                 pinnedTodoList.add(todo);
             }
         }));
 
         todoList.removeAll(pinnedTodoList);
         sortedTodoList.addAll(pinnedTodoList);
         sortedTodoList.addAll(todoList);
 
         return sortedTodoList;
     }
 
     public List<Todo> updateOrder(String userId, List<Todo> todoList) {
         require(todoRepository.findByUserId(userId).size() > 0);
         for (int i = 0; i < todoList.size(); i++) {
             todoList.get(i).setOrder((long) i+1);
         }
         return todoRepository.saveAll(todoList);
     }
 }

commit d01fa31e32ef42cfbe5196b9c16993c723dc1933
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 23:51:15 2018 +0700

    REFACTOR

diff --git a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
index c69a9de..84ca8ff 100644
--- a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
@@ -7,2 +7,3 @@ import com.linecorp.bot.spring.boot.annotation.EventMapping;
 import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;
+import com.wanichnun.todoapp.annotation.LogExecutionTime;
 import com.wanichnun.todoapp.service.TodoService;
@@ -10,2 +11,3 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.valid4j.errors.RequireViolation;
@@ -17,32 +19,38 @@ import static org.valid4j.Assertive.require;
 @LineMessageHandler
 @Slf4j
 public class MessageHandler {
-    String edit = "edit";
 
     @Autowired
     private TodoService todoService;
 
+    private static final String EDIT = "edit";
+    private static final String WRONG_FORMAT = "Wrong format";
+
+    @Value("${web.url}")
+    private String webUrl;
+
+    @LogExecutionTime
     @EventMapping
-    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws ParseException {
+    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
         log.info("Got message this bot: {}", event);
         try {
-            if (edit.equals(event.getMessage().getText())) {
-                return new TextMessage("https://google.com");
+            if (EDIT.equals(event.getMessage().getText())) {
+                return new TextMessage(webUrl);
             }
             else {
                 String userId = event.getSource().getUserId();
                 String messageContent = event.getMessage().getText();
                 return todoService.handleTodoCreateRequest(userId, messageContent);
             }
         }
         catch (RequireViolation re) {
             return new TextMessage(re.getMessage());
         }
         catch (Exception e) {
             e.printStackTrace();
             log.error("Error " + e);
-            return new TextMessage("Wrong format");
+            return new TextMessage(WRONG_FORMAT);
         }
 
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 0156723..0bce604 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -18,112 +18,113 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private static final String TODAY = "today";
     private static final String TOMORROW = "tomorrow";
     private static final String INVALID_TEXT_FORMAT = "Invalid text format";
     private static final String INVALID_DATE_FORMAT = "Invalid date format";
+    private static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     public TextMessage handleTodoCreateRequest(String userId, String message) {
         Boolean isPinned = false;
         Boolean isDone = false;
 
 
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, INVALID_TEXT_FORMAT);
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
-        DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
+        DateFormat format = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
 
         if (dateText.equalsIgnoreCase(TODAY)) {
             dateText = convertDate(TODAY);
         }
         if (dateText.equalsIgnoreCase(TOMORROW)) {
             dateText = convertDate(TOMORROW);
         }
 
         Date date;
         try {
             date = format.parse(dateText + " " + timeText);
         } catch (ParseException pe) {
             pe.printStackTrace();
             return new TextMessage(INVALID_DATE_FORMAT);
         }
 
         this.create(userId, taskName, isPinned, isDone, date);
         return new TextMessage(Response.SUCCESS.getContent());
     }
 
     private String convertDate(String date) {
         StringBuilder sb = new StringBuilder();
         Calendar calendar = Calendar.getInstance();
 
         if (date.equalsIgnoreCase(TOMORROW)) {
             calendar.add(Calendar.DATE, 1);
         }
 
         sb.append(calendar.get(Calendar.DAY_OF_MONTH)).append("/");
         sb.append(calendar.get(Calendar.MONTH)).append("/");
         sb.append(calendar.get(Calendar.YEAR));
 
         return sb.toString();
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     private Long calculateOrder(String userId) {
         return (long) (todoRepository.findByUserId(userId).size() + 1);
     }
 
     public List<Todo> listTodos(String userId) {
         List<Todo> todoList = todoRepository.findByUserIdOrderByOrderAsc(userId);
         List<Todo> pinnedTodoList = new ArrayList<>();
         List<Todo> sortedTodoList = new ArrayList<>();
         todoList.forEach((todo -> {
             if (todo.getIsPinned()) {
                 pinnedTodoList.add(todo);
             }
         }));
 
         todoList.removeAll(pinnedTodoList);
         sortedTodoList.addAll(pinnedTodoList);
         sortedTodoList.addAll(todoList);
 
         return sortedTodoList;
     }
 
     public List<Todo> updateOrder(String userId, List<Todo> todoList) {
         require(todoRepository.findByUserId(userId).size() > 0);
         for (int i = 0; i < todoList.size(); i++) {
             todoList.get(i).setOrder((long) i+1);
         }
         return todoRepository.saveAll(todoList);
     }
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index f27ea4f..abdd416 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -13,9 +13,11 @@ line:
   bot:
     channelToken: ${LINE_CHANNEL_TOKEN}
     channelSecret: ${LINE_CHANNEL_SECRET}
   getAccessTokenUrl: ${LINE_GET_ACCESS_TOKEN_URL}
   clientId: ${LINE_CLIENT_ID}
   clientSecret: ${LINE_CLIENT_SECRET}
   grantType: ${LINE_GRANT_TYPE}
   redirectUri: ${LINE_REDIRECT_URI}
+web:
+  url: ${WEB_URL}
 server:
diff --git a/src/main/resources/application.yml.bak b/src/main/resources/application.yml.bak
deleted file mode 100644
index e1ac318..0000000
--- a/src/main/resources/application.yml.bak
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
----
-spring:
-  profiles: dev
-  devtools:
-    restart:
-      enabled: true
-      additional-paths: src
-  data:
-      mongodb:
-        host: localhost
-        database: todo
-line:
-  bot:
-#    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
-#    channelSecret: 52f1f89f193bd08fa092371e9865afc8
-    channelToken: UZO234Na089EcMp/2SeFDVlKesy9nK0SUzyZ6QhSOokOO0iNbbde1sjU2Gb9e5oQZPSs9oHGNWwLQ049qWcxv61QkiAhT40z9Y9pZhIxnAqnDG7DIkW0g8lPZ44ppXNcdRqJMQDjrcGCG/QVbU+XHQdB04t89/1O/w1cDnyilFU=
-    channelSecret: 68250ab330c896817551e82523f37be3
-server:
-  port: 8082
----
-spring:
-  profiles: default
-  devtools:
-    restart:
-      enabled: true
-      additional-paths: src
-  data:
-      mongodb:
-        host: ds125352.mlab.com:25352
-        database: todoexam
-        username: todo_app
-        password: ToDo@pp1
-
-line:
-  bot:
-    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
-    channelSecret: 52f1f89f193bd08fa092371e9865afc8
\ No newline at end of file

commit 1e6aa09719e604fff3110ff91cd2580ee6d5d0eb
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 23:42:56 2018 +0700

    REFACTOR

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..23c136a
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,6 @@
+FROM openjdk:8-jdk-alpine
+
+COPY . /
+RUN ./gradlew build
+
+ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","build/libs/app.jar"]
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index a3211dd..863047c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,15 +27,16 @@ repositories {
 dependencies {
     compile("org.springframework.boot:spring-boot-starter-web")
     compile("org.springframework.boot:spring-boot-devtools")
     compile("org.springframework.boot:spring-boot-starter-actuator")
+    compile("org.springframework.boot:spring-boot-starter-aop")
     compile("org.springframework.boot:spring-boot-starter-data-mongodb")
     compile('org.valid4j:valid4j:0.5.0')
     compile('joda-time:joda-time:2.9.9')
     compile 'com.linecorp.bot:line-bot-spring-boot:2.0.0'
     compile("org.projectlombok:lombok:1.18.2")
     compile("com.mashape.unirest:unirest-java:1.4.9")
 
     testCompile("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.0")
     testCompile("org.springframework.boot:spring-boot-starter-test")
     testCompile group: 'junit', name: 'junit', version: '4.12'
 }
diff --git a/src/main/java/com/wanichnun/todoapp/annotation/LogExecutionTime.java b/src/main/java/com/wanichnun/todoapp/annotation/LogExecutionTime.java
new file mode 100644
index 0000000..b86247d
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/annotation/LogExecutionTime.java
@@ -0,0 +1,11 @@
+package com.wanichnun.todoapp.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface LogExecutionTime {
+}
\ No newline at end of file
diff --git a/src/main/java/com/wanichnun/todoapp/aspect/LogAspect.java b/src/main/java/com/wanichnun/todoapp/aspect/LogAspect.java
new file mode 100644
index 0000000..76ec300
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/aspect/LogAspect.java
@@ -0,0 +1,22 @@
+package com.wanichnun.todoapp.aspect;
+
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+@Slf4j
+public class LogAspect {
+    @Around("@annotation(com.wanichnun.todoapp.annotation.LogExecutionTime)")
+    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
+        final long start = System.currentTimeMillis();
+        final Object proceed = joinPoint.proceed();
+        final long executionTime = System.currentTimeMillis() - start;
+        log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms");
+
+        return proceed;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/wanichnun/todoapp/controller/AuthController.java b/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
deleted file mode 100644
index caad3c2..0000000
--- a/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.wanichnun.todoapp.controller;
-
-import com.mashape.unirest.http.exceptions.UnirestException;
-import com.wanichnun.todoapp.model.AuthRequest;
-import com.wanichnun.todoapp.model.Response;
-import com.wanichnun.todoapp.model.ResponseModel;
-import com.wanichnun.todoapp.service.AuthService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.*;
-
-@RestController
-@RequestMapping(path = "/api/v1/auth")
-public class AuthController {
-    @Autowired
-    private AuthService authService;
-
-    @PostMapping()
-    public HttpEntity<ResponseModel> update(
-            @RequestBody AuthRequest request
-            ) throws UnirestException {
-        return new ResponseModel(Response.SUCCESS.getContent(), authService.getAccessToken(request)).build(HttpStatus.OK);
-    }
-}
diff --git a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
index 44f6790..b7316ca 100644
--- a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
@@ -2,2 +2,3 @@ package com.wanichnun.todoapp.controller;
 
+import com.wanichnun.todoapp.annotation.LogExecutionTime;
 import com.wanichnun.todoapp.document.Todo;
@@ -15,36 +16,24 @@ import java.util.List;
 @RestController
 @RequestMapping(path = "/api/v1/users")
 public class TodoController {
     @Autowired
     private TodoService todoService;
 
+    @LogExecutionTime
     @GetMapping(path = "{userId}/todos")
     public HttpEntity<ResponseModel> getAll(
             @PathVariable(name = "userId") String userId) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.listTodos(userId)).build(HttpStatus.OK);
     }
 
-//    @PutMapping(path = "{userId}/todos/{todoId}")
-//    public HttpEntity<ResponseModel> update(
-//            @PathVariable(name = "userId") String userId,
-//            @PathVariable(name = "todoId") String todoId,
-//            @RequestBody TodoUpdateRequest request
-//    ) {
-//        return new ResponseModel(Response.SUCCESS.getContent(), todoService.update(
-//                todoId,
-//                userId,
-//                request.getIsPinned(),
-//                request.getIsDone(),
-//                request.getOrder())).build(HttpStatus.OK);
-//    }
-
+    @LogExecutionTime
     @PutMapping(path = "{userId}/todos")
     public HttpEntity<ResponseModel> update(
             @PathVariable(name = "userId") String userId,
             @RequestBody List<Todo> todoList
     ) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.updateOrder(
                 userId,
                 todoList)).build(HttpStatus.OK);
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
index dbb67b8..7f10728 100644
--- a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
@@ -9,9 +9,5 @@ import java.util.Optional;
 public interface TodoRepository extends MongoRepository<Todo, String> {
-    Optional<Todo> findByIdAndUserId(String id, String userId);
 
     List<Todo> findByUserId(String userId);
-
-    List<Todo> findByUserIdOrderByDateAsc(String userId);
-
     List<Todo> findByUserIdOrderByOrderAsc(String userId);
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 2d134fe..0156723 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -4,2 +4,3 @@ import com.linecorp.bot.model.message.TextMessage;
 import com.wanichnun.todoapp.document.Todo;
+import com.wanichnun.todoapp.model.Response;
 import com.wanichnun.todoapp.repository.TodoRepository;
@@ -17,111 +18,112 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private static final String TODAY = "today";
     private static final String TOMORROW = "tomorrow";
-    private static final String DATE_TIME_FORMAT = "dd/MM/yyyy HH:mm";
+    private static final String INVALID_TEXT_FORMAT = "Invalid text format";
+    private static final String INVALID_DATE_FORMAT = "Invalid date format";
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     public TextMessage handleTodoCreateRequest(String userId, String message) {
         Boolean isPinned = false;
         Boolean isDone = false;
 
 
         String[] splittedMessage = message.split(" : ");
-        require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
+        require(splittedMessage.length >= 2 && splittedMessage.length <= 3, INVALID_TEXT_FORMAT);
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
 
         if (dateText.equalsIgnoreCase(TODAY)) {
             dateText = convertDate(TODAY);
         }
         if (dateText.equalsIgnoreCase(TOMORROW)) {
             dateText = convertDate(TOMORROW);
         }
 
         Date date;
         try {
             date = format.parse(dateText + " " + timeText);
         } catch (ParseException pe) {
             pe.printStackTrace();
-            return new TextMessage("Invalid date format");
+            return new TextMessage(INVALID_DATE_FORMAT);
         }
 
         this.create(userId, taskName, isPinned, isDone, date);
-        return new TextMessage("success");
+        return new TextMessage(Response.SUCCESS.getContent());
     }
 
     private String convertDate(String date) {
         StringBuilder sb = new StringBuilder();
         Calendar calendar = Calendar.getInstance();
 
         if (date.equalsIgnoreCase(TOMORROW)) {
             calendar.add(Calendar.DATE, 1);
         }
 
         sb.append(calendar.get(Calendar.DAY_OF_MONTH)).append("/");
         sb.append(calendar.get(Calendar.MONTH)).append("/");
         sb.append(calendar.get(Calendar.YEAR));
 
         return sb.toString();
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     private Long calculateOrder(String userId) {
         return (long) (todoRepository.findByUserId(userId).size() + 1);
     }
 
     public List<Todo> listTodos(String userId) {
         List<Todo> todoList = todoRepository.findByUserIdOrderByOrderAsc(userId);
         List<Todo> pinnedTodoList = new ArrayList<>();
         List<Todo> sortedTodoList = new ArrayList<>();
         todoList.forEach((todo -> {
             if (todo.getIsPinned()) {
                 pinnedTodoList.add(todo);
             }
         }));
 
         todoList.removeAll(pinnedTodoList);
         sortedTodoList.addAll(pinnedTodoList);
         sortedTodoList.addAll(todoList);
 
         return sortedTodoList;
     }
 
     public List<Todo> updateOrder(String userId, List<Todo> todoList) {
         require(todoRepository.findByUserId(userId).size() > 0);
         for (int i = 0; i < todoList.size(); i++) {
             todoList.get(i).setOrder((long) i+1);
         }
         return todoRepository.saveAll(todoList);
     }
 }
diff --git a/src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java b/src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java
deleted file mode 100644
index 9f80a4b..0000000
--- a/src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.wanichnun.todoapp.handler;
-
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-public class MessageHandlerTest {
-    @Autowired
-    MessageHandler messageHandler;
-
-//    @Test
-//    public void testHandleTextMessageEvent() {
-//        TextMessageContent textMessageContent = new TextMessageContent("123", "edit");
-//    }
-}

commit 289241f55d97a9fb754479c906efb3999c7b28d4
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 22:50:38 2018 +0700

    REFACTOR

diff --git a/src/main/java/com/wanichnun/todoapp/service/AuthService.java b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
index 2f0ede7..4698ccf 100644
--- a/src/main/java/com/wanichnun/todoapp/service/AuthService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
@@ -19,60 +19,50 @@ import org.springframework.web.client.RestTemplate;
 @Slf4j
 @Service
 public class AuthService {
 
     @Value("${line.getAccessTokenUrl}")
     private String getAccessTokenUrl;
 
     @Value("${line.clientId}")
     private String clientId;
 
     @Value("${line.clientSecret}")
     private String clientSecret;
 
     @Value("${line.grantType}")
     private String grantType;
 
     @Value("${line.redirectUri}")
     private String redirectUri;
 
     private RestTemplate restTemplate;
 
-    private Environment environment;
-
     @Autowired
-    public AuthService(RestTemplate restTemplate, Environment environment) {
+    public AuthService(RestTemplate restTemplate) {
         this.restTemplate = restTemplate;
-        this.environment = environment;
     }
 
     public AuthResponse getAccessToken(AuthRequest request) {
-        String getAccessTokenUrl = "https://api.line.me/v2/oauth/accessToken";
-
-        String clientId = "1601887173";
-        String clientSecret = "9df37fe9ad6c3c6ba0d6146be02489d5";
-        String grantType = "authorization_code";
-        String redirectUri = "https://todo-d976c.firebaseapp.com/callback";
-
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
 
         MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
         map.add("code", request.getCode());
         map.add("client_id", clientId);
         map.add("client_secret", clientSecret);
         map.add("grant_type", grantType);
         map.add("redirect_uri", redirectUri);
 
         HttpEntity<MultiValueMap<String, String>> requestForm = new HttpEntity<>(map, headers);
 
         ResponseEntity<AuthResponse> response = null;
         try {
             response = restTemplate.postForEntity(getAccessTokenUrl, requestForm , AuthResponse.class);
         } catch (HttpClientErrorException e) {
             e.printStackTrace();
             log.error(e.getMessage());
         }
 
         return response.getBody();
     }
 }
diff --git a/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java b/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java
index d385510..6543b32 100644
--- a/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java
+++ b/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java
@@ -11,21 +11,18 @@ import org.springframework.web.client.RestTemplate;
 @TestPropertySource(locations = {"/application.yml"})
 public class AuthServiceTest {
     private AuthService authService;
 
     @Mock
     private RestTemplate restTemplate;
 
-    @Mock
-    private Environment environment;
-
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        authService = new AuthService(restTemplate, environment);
+        authService = new AuthService(restTemplate);
     }
 
     @Test
     public void test() {
         System.out.println(123);
     }
 }
diff --git a/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
index 27449da..71a288a 100644
--- a/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
+++ b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
@@ -23,218 +23,209 @@ import static org.mockito.Mockito.when;
 public class TodoServiceTest {
     private TodoService todoService;
 
     @Mock
     private TodoRepository todoRepository;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         todoService = new TodoService(todoRepository);
     }
 
     @Test
     public void testCreateTodo() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockDate);
 
         verify(todoRepository, times(1)).save(any());
 
         Assert.assertEquals(mockTaskName, actual.getTaskName());
         Assert.assertEquals(mockUserId, actual.getUserId());
         Assert.assertEquals(mockOrder, actual.getOrder());
         Assert.assertEquals(mockIsDone, actual.getIsDone());
         Assert.assertEquals(mockIsPinned, actual.getIsPinned());
         Assert.assertEquals(mockDate, actual.getDate());
     }
 
     @Test
     public void testUpdateSuccess() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
 
         when(todoRepository.findByUserId(any())).thenReturn(Arrays.asList(mockTodo));
         when(todoRepository.saveAll(any())).thenReturn(Arrays.asList(mockTodo));
 
         List<Todo> actual = todoService.updateOrder(mockUserId, Arrays.asList(mockTodo));
 
         verify(todoRepository, times(1)).findByUserId(any());
         verify(todoRepository, times(1)).saveAll(any());
 
         Assert.assertEquals(1, actual.size());
     }
 
     @Test
     public void testListTodosSuccess() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsDone = false;
         Date mockDate = new Date();
 
         Todo mockTodo1 = new Todo();
         mockTodo1.setId("1");
         mockTodo1.setUserId(mockUserId);
         mockTodo1.setTaskName(mockTaskName);
         mockTodo1.setOrder(1L);
         mockTodo1.setIsPinned(false);
         mockTodo1.setIsDone(mockIsDone);
         mockTodo1.setDate(mockDate);
 
         Todo mockTodo2 = new Todo();
         mockTodo2.setId("2");
         mockTodo2.setUserId(mockUserId);
         mockTodo2.setTaskName(mockTaskName);
         mockTodo2.setOrder(2L);
         mockTodo2.setIsPinned(true);
         mockTodo2.setIsDone(mockIsDone);
         mockTodo2.setDate(mockDate);
 
         List<Todo> mockTodoList = new ArrayList<>();
         mockTodoList.add(mockTodo1);
         mockTodoList.add(mockTodo2);
 
         when(todoRepository.findByUserIdOrderByOrderAsc(any())).thenReturn(mockTodoList);
 
         List<Todo> actual = todoService.listTodos("U1");
 
         verify(todoRepository, times(1)).findByUserIdOrderByOrderAsc(any());
 
         Assert.assertEquals(2, actual.size());
         Assert.assertEquals("2", actual.get(0).getId());
 
     }
 
     @Test(expected = RequireViolation.class)
     public void testHandleTodoCreateRequestFailedWhenMessageInvalidFormat() throws ParseException {
         String mockUserId = "U1";
         String mockMessage = "Wrong format";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         todoService.handleTodoCreateRequest(mockUserId, mockMessage);
     }
 
     @Test
     public void testHandleTodoCreateRequestSuccessWhenSpecifyTime() throws ParseException {
         String mockUserId = "U1";
         String mockMessage = "Meeting with James : 20/12/2018 : 22:00";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         todoService.handleTodoCreateRequest(mockUserId, mockMessage);
 
         verify(todoRepository, times(1)).save(any());
     }
 
     @Test
     public void testHandleTodoCreateRequestSuccessWhenNotSpecifyTime() throws ParseException {
         String mockUserId = "U1";
         String mockMessage = "Meeting with James : 20/12/2018";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         todoService.handleTodoCreateRequest(mockUserId, mockMessage);
 
         verify(todoRepository, times(1)).save(any());
     }
 
     @Test
     public void testHandleTodoCreateRequestSuccessWhenSpecifyDateAndTimeToday() {
         String mockUserId = "U1";
         String mockMessage = "Meeting with James : today : 22:00";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         todoService.handleTodoCreateRequest(mockUserId, mockMessage);
 
         verify(todoRepository, times(1)).save(any());
     }
 
     @Test
     public void testHandleTodoCreateRequestSuccessWhenSpecifyDateTomorrow() {
         String mockUserId = "U1";
         String mockMessage = "Meeting with James : tomorrow";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         todoService.handleTodoCreateRequest(mockUserId, mockMessage);
 
         verify(todoRepository, times(1)).save(any());
     }
 
     @Test
     public void testHandleTodoCreateRequestFailedWhenWrongDate() {
         String mockUserId = "U1";
         String mockMessage = "Meeting with James : wrong";
 
         Todo mockTodo = new Todo();
         mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
         mockTodo.setIsPinned(false);
 
         TextMessage textMessage = todoService.handleTodoCreateRequest(mockUserId, mockMessage);
 
         Assert.assertEquals("Invalid date format", textMessage.getText());
     }
-
-
-    @Test
-    public void test() throws ParseException {
-        String test = "2/1/2018 12:00";
-        DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
-        Date date = format.parse(test);
-        System.out.println(date);
-    }
 }

commit 9f8b726db2689ea4806c7eedd8262800178893ea
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 22:46:02 2018 +0700

    ADD README

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5d20977
--- /dev/null
+++ b/README.md
@@ -0,0 +1,35 @@
+# todo-ui
+
+Simple To-Do application API build with LINE messaging API. This must be used with my todo-app-ui.
+
+## Environment variables
+| Name                          | Value                                                             |
+| ----------------------------- |-------------------------------------------------------------------|
+| DEV_TOOL_ENABLED              | true/false disabled on production                                 |
+| MONGO_HOST                    | mongo host url                                                    |
+| MONGO_DB_NAME                 | mongo database name                                               |
+| MONGO_USER                    | mongo database user                                               |
+| MONGO_PASSWORD                | mongo database password                                           |
+| LINE_CHANNEL_TOKEN            | token of LINE bot channel                                         |
+| LINE_CHANNEL_SECRET           | secret of LINE bot channel                                        |
+| LINE_GET_ACCESS_TOKEN_URL     | https://api.line.me/v2/oauth/accessToken                          |
+| LINE_CLIENT_ID                | client ID of LINE web login                                       |
+| LINE_CLIENT_SECRET            | secret of LINE web login                                          |
+| LINE_GRANT_TYPE               | grant type of LINE web login (authorization_code)                 |
+| LINE_REDIRECT_URI             | url for web frontend to receive callback after user logged in     |
+| PORT                          | your preferred port                                               |
+
+## Test
+```
+gradlew test
+```
+
+## Project build
+```
+gradlew build
+```
+
+### Run
+```
+gradlew bootRun
+```

commit 374b252f05d96fb51027510782e6dbd515bcf3ca
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 21:59:39 2018 +0700

    UPDATE procfile

diff --git a/Procfile b/Procfile
index 9f730d3..9fd2355 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: java $JAVA_OPTS -jar target/*.jar --server.port=$PORT
+web java $JAVA_OPTS -jar build/libs/*.jar --server.port=$PORT
\ No newline at end of file

commit b59ed4455c5c357abdda035f8814df8e9159d963
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 21:49:38 2018 +0700

    REFACTOR config

diff --git a/src/main/java/com/wanichnun/todoapp/service/AuthService.java b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
index f93775c..2f0ede7 100644
--- a/src/main/java/com/wanichnun/todoapp/service/AuthService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
@@ -6,2 +6,4 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
 import org.springframework.http.HttpEntity;
@@ -17,37 +19,60 @@ import org.springframework.web.client.RestTemplate;
 @Slf4j
 @Service
 public class AuthService {
-    @Autowired
+
+    @Value("${line.getAccessTokenUrl}")
+    private String getAccessTokenUrl;
+
+    @Value("${line.clientId}")
+    private String clientId;
+
+    @Value("${line.clientSecret}")
+    private String clientSecret;
+
+    @Value("${line.grantType}")
+    private String grantType;
+
+    @Value("${line.redirectUri}")
+    private String redirectUri;
+
     private RestTemplate restTemplate;
 
+    private Environment environment;
+
+    @Autowired
+    public AuthService(RestTemplate restTemplate, Environment environment) {
+        this.restTemplate = restTemplate;
+        this.environment = environment;
+    }
+
     public AuthResponse getAccessToken(AuthRequest request) {
         String getAccessTokenUrl = "https://api.line.me/v2/oauth/accessToken";
 
         String clientId = "1601887173";
         String clientSecret = "9df37fe9ad6c3c6ba0d6146be02489d5";
         String grantType = "authorization_code";
         String redirectUri = "https://todo-d976c.firebaseapp.com/callback";
 
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
 
         MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
         map.add("code", request.getCode());
         map.add("client_id", clientId);
         map.add("client_secret", clientSecret);
         map.add("grant_type", grantType);
         map.add("redirect_uri", redirectUri);
 
         HttpEntity<MultiValueMap<String, String>> requestForm = new HttpEntity<>(map, headers);
 
         ResponseEntity<AuthResponse> response = null;
         try {
             response = restTemplate.postForEntity(getAccessTokenUrl, requestForm , AuthResponse.class);
         } catch (HttpClientErrorException e) {
             e.printStackTrace();
             log.error(e.getMessage());
         }
 
         return response.getBody();
     }
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index e1ac318..f27ea4f 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,39 +1,22 @@
-
-
----
 spring:
-  profiles: dev
   devtools:
     restart:
-      enabled: true
+      enabled: ${DEV_TOOL_ENABLED}
       additional-paths: src
   data:
       mongodb:
-        host: localhost
-        database: todo
+        host: ${MONGO_HOST}
+        database: ${MONGO_DB_NAME}
+        username: ${MONGO_USER}
+        password: ${MONGO_PASSWORD}
 line:
   bot:
-#    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
-#    channelSecret: 52f1f89f193bd08fa092371e9865afc8
-    channelToken: UZO234Na089EcMp/2SeFDVlKesy9nK0SUzyZ6QhSOokOO0iNbbde1sjU2Gb9e5oQZPSs9oHGNWwLQ049qWcxv61QkiAhT40z9Y9pZhIxnAqnDG7DIkW0g8lPZ44ppXNcdRqJMQDjrcGCG/QVbU+XHQdB04t89/1O/w1cDnyilFU=
-    channelSecret: 68250ab330c896817551e82523f37be3
+    channelToken: ${LINE_CHANNEL_TOKEN}
+    channelSecret: ${LINE_CHANNEL_SECRET}
+  getAccessTokenUrl: ${LINE_GET_ACCESS_TOKEN_URL}
+  clientId: ${LINE_CLIENT_ID}
+  clientSecret: ${LINE_CLIENT_SECRET}
+  grantType: ${LINE_GRANT_TYPE}
+  redirectUri: ${LINE_REDIRECT_URI}
 server:
-  port: 8082
----
-spring:
-  profiles: default
-  devtools:
-    restart:
-      enabled: true
-      additional-paths: src
-  data:
-      mongodb:
-        host: ds125352.mlab.com:25352
-        database: todoexam
-        username: todo_app
-        password: ToDo@pp1
-
-line:
-  bot:
-    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
-    channelSecret: 52f1f89f193bd08fa092371e9865afc8
\ No newline at end of file
+  port: ${PORT}
\ No newline at end of file
diff --git a/src/main/resources/application.yml.bak b/src/main/resources/application.yml.bak
new file mode 100644
index 0000000..e1ac318
--- /dev/null
+++ b/src/main/resources/application.yml.bak
@@ -0,0 +1,39 @@
+
+
+---
+spring:
+  profiles: dev
+  devtools:
+    restart:
+      enabled: true
+      additional-paths: src
+  data:
+      mongodb:
+        host: localhost
+        database: todo
+line:
+  bot:
+#    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
+#    channelSecret: 52f1f89f193bd08fa092371e9865afc8
+    channelToken: UZO234Na089EcMp/2SeFDVlKesy9nK0SUzyZ6QhSOokOO0iNbbde1sjU2Gb9e5oQZPSs9oHGNWwLQ049qWcxv61QkiAhT40z9Y9pZhIxnAqnDG7DIkW0g8lPZ44ppXNcdRqJMQDjrcGCG/QVbU+XHQdB04t89/1O/w1cDnyilFU=
+    channelSecret: 68250ab330c896817551e82523f37be3
+server:
+  port: 8082
+---
+spring:
+  profiles: default
+  devtools:
+    restart:
+      enabled: true
+      additional-paths: src
+  data:
+      mongodb:
+        host: ds125352.mlab.com:25352
+        database: todoexam
+        username: todo_app
+        password: ToDo@pp1
+
+line:
+  bot:
+    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
+    channelSecret: 52f1f89f193bd08fa092371e9865afc8
\ No newline at end of file
diff --git a/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java b/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java
new file mode 100644
index 0000000..d385510
--- /dev/null
+++ b/src/test/java/com/wanichnun/todoapp/service/AuthServiceTest.java
@@ -0,0 +1,31 @@
+package com.wanichnun.todoapp.service;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.web.client.RestTemplate;
+
+@TestPropertySource(locations = {"/application.yml"})
+public class AuthServiceTest {
+    private AuthService authService;
+
+    @Mock
+    private RestTemplate restTemplate;
+
+    @Mock
+    private Environment environment;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        authService = new AuthService(restTemplate, environment);
+    }
+
+    @Test
+    public void test() {
+        System.out.println(123);
+    }
+}

commit 7d6257af283ddfa3501687a4e87f61c2a8389b37
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Thu Aug 23 18:59:02 2018 +0700

    UPDATE date check

diff --git a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
index 7c08dc0..44f6790 100644
--- a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
@@ -2,2 +2,3 @@ package com.wanichnun.todoapp.controller;
 
+import com.wanichnun.todoapp.document.Todo;
 import com.wanichnun.todoapp.model.Response;
@@ -10,28 +11,40 @@ import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 @RestController
 @RequestMapping(path = "/api/v1/users")
 public class TodoController {
     @Autowired
     private TodoService todoService;
 
     @GetMapping(path = "{userId}/todos")
     public HttpEntity<ResponseModel> getAll(
             @PathVariable(name = "userId") String userId) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.listTodos(userId)).build(HttpStatus.OK);
     }
 
-    @PutMapping(path = "{userId}/todos/{todoId}")
+//    @PutMapping(path = "{userId}/todos/{todoId}")
+//    public HttpEntity<ResponseModel> update(
+//            @PathVariable(name = "userId") String userId,
+//            @PathVariable(name = "todoId") String todoId,
+//            @RequestBody TodoUpdateRequest request
+//    ) {
+//        return new ResponseModel(Response.SUCCESS.getContent(), todoService.update(
+//                todoId,
+//                userId,
+//                request.getIsPinned(),
+//                request.getIsDone(),
+//                request.getOrder())).build(HttpStatus.OK);
+//    }
+
+    @PutMapping(path = "{userId}/todos")
     public HttpEntity<ResponseModel> update(
             @PathVariable(name = "userId") String userId,
-            @PathVariable(name = "todoId") String todoId,
-            @RequestBody TodoUpdateRequest request
+            @RequestBody List<Todo> todoList
     ) {
-        return new ResponseModel(Response.SUCCESS.getContent(), todoService.update(
-                todoId,
+        return new ResponseModel(Response.SUCCESS.getContent(), todoService.updateOrder(
                 userId,
-                request.getIsPinned(),
-                request.getIsDone(),
-                request.getOrder())).build(HttpStatus.OK);
+                todoList)).build(HttpStatus.OK);
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
index 5882470..c69a9de 100644
--- a/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
@@ -17,31 +17,32 @@ import static org.valid4j.Assertive.require;
 @LineMessageHandler
 @Slf4j
 public class MessageHandler {
     String edit = "edit";
 
     @Autowired
     private TodoService todoService;
 
     @EventMapping
     public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws ParseException {
         log.info("Got message this bot: {}", event);
         try {
             if (edit.equals(event.getMessage().getText())) {
                 return new TextMessage("https://google.com");
             }
             else {
                 String userId = event.getSource().getUserId();
                 String messageContent = event.getMessage().getText();
                 return todoService.handleTodoCreateRequest(userId, messageContent);
             }
         }
         catch (RequireViolation re) {
             return new TextMessage(re.getMessage());
         }
         catch (Exception e) {
+            e.printStackTrace();
             log.error("Error " + e);
             return new TextMessage("Wrong format");
         }
 
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
index b791e37..dbb67b8 100644
--- a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
@@ -9,7 +9,9 @@ import java.util.Optional;
 public interface TodoRepository extends MongoRepository<Todo, String> {
     Optional<Todo> findByIdAndUserId(String id, String userId);
 
     List<Todo> findByUserId(String userId);
 
     List<Todo> findByUserIdOrderByDateAsc(String userId);
+
+    List<Todo> findByUserIdOrderByOrderAsc(String userId);
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 09d05fa..2d134fe 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -17,82 +17,111 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
+    private static final String TODAY = "today";
+    private static final String TOMORROW = "tomorrow";
+    private static final String DATE_TIME_FORMAT = "dd/MM/yyyy HH:mm";
+
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
-    public TextMessage handleTodoCreateRequest(String userId, String message) throws ParseException {
+    public TextMessage handleTodoCreateRequest(String userId, String message) {
         Boolean isPinned = false;
         Boolean isDone = false;
 
+
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
-        Date date = format.parse(dateText + " " + timeText);
+
+        if (dateText.equalsIgnoreCase(TODAY)) {
+            dateText = convertDate(TODAY);
+        }
+        if (dateText.equalsIgnoreCase(TOMORROW)) {
+            dateText = convertDate(TOMORROW);
+        }
+
+        Date date;
+        try {
+            date = format.parse(dateText + " " + timeText);
+        } catch (ParseException pe) {
+            pe.printStackTrace();
+            return new TextMessage("Invalid date format");
+        }
+
         this.create(userId, taskName, isPinned, isDone, date);
         return new TextMessage("success");
     }
 
+    private String convertDate(String date) {
+        StringBuilder sb = new StringBuilder();
+        Calendar calendar = Calendar.getInstance();
+
+        if (date.equalsIgnoreCase(TOMORROW)) {
+            calendar.add(Calendar.DATE, 1);
+        }
+
+        sb.append(calendar.get(Calendar.DAY_OF_MONTH)).append("/");
+        sb.append(calendar.get(Calendar.MONTH)).append("/");
+        sb.append(calendar.get(Calendar.YEAR));
+
+        return sb.toString();
+    }
+
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     private Long calculateOrder(String userId) {
         return (long) (todoRepository.findByUserId(userId).size() + 1);
     }
 
-    public Todo update(String id, String userId, Boolean isPinned, Boolean isDone, Long order) {
-        Optional<Todo> result = todoRepository.findByIdAndUserId(id, userId);
-        require(result.isPresent(), "Resource not found");
-        Todo todo = result.get();
-        todo.setIsPinned(isPinned);
-        todo.setIsDone(isDone);
-        todo.setOrder(order);
-
-        Todo updatedTodo = todoRepository.save(todo);
-        log.info("Updated todo {}", updatedTodo);
-        return updatedTodo;
-    }
-
     public List<Todo> listTodos(String userId) {
-        List<Todo> todoList = todoRepository.findByUserIdOrderByDateAsc(userId);
+        List<Todo> todoList = todoRepository.findByUserIdOrderByOrderAsc(userId);
         List<Todo> pinnedTodoList = new ArrayList<>();
         List<Todo> sortedTodoList = new ArrayList<>();
-
         todoList.forEach((todo -> {
             if (todo.getIsPinned()) {
                 pinnedTodoList.add(todo);
             }
         }));
 
         todoList.removeAll(pinnedTodoList);
         sortedTodoList.addAll(pinnedTodoList);
         sortedTodoList.addAll(todoList);
 
         return sortedTodoList;
     }
+
+    public List<Todo> updateOrder(String userId, List<Todo> todoList) {
+        require(todoRepository.findByUserId(userId).size() > 0);
+        for (int i = 0; i < todoList.size(); i++) {
+            todoList.get(i).setOrder((long) i+1);
+        }
+        return todoRepository.saveAll(todoList);
+    }
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ea15ae9..e1ac318 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1 +1,4 @@
+
+
+---
 spring:
diff --git a/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
index 60c7777..27449da 100644
--- a/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
+++ b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
@@ -2,2 +2,3 @@ package com.wanichnun.todoapp.service;
 
+import com.linecorp.bot.model.message.TextMessage;
 import com.wanichnun.todoapp.document.Todo;
@@ -9,2 +10,3 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.valid4j.errors.RequireViolation;
 
@@ -21,120 +23,218 @@ import static org.mockito.Mockito.when;
 public class TodoServiceTest {
     private TodoService todoService;
 
     @Mock
     private TodoRepository todoRepository;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         todoService = new TodoService(todoRepository);
     }
 
     @Test
     public void testCreateTodo() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
-        Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockOrder, mockDate);
+        Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockDate);
 
         verify(todoRepository, times(1)).save(any());
 
         Assert.assertEquals(mockTaskName, actual.getTaskName());
         Assert.assertEquals(mockUserId, actual.getUserId());
         Assert.assertEquals(mockOrder, actual.getOrder());
         Assert.assertEquals(mockIsDone, actual.getIsDone());
         Assert.assertEquals(mockIsPinned, actual.getIsPinned());
         Assert.assertEquals(mockDate, actual.getDate());
     }
 
     @Test
     public void testUpdateSuccess() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
-        Optional<Todo> mockTodoOpt = Optional.of(mockTodo);
 
-        when(todoRepository.findByIdAndUserId(any(), any())).thenReturn(mockTodoOpt);
-        when(todoRepository.save(any())).thenReturn(mockTodoOpt.get());
+        when(todoRepository.findByUserId(any())).thenReturn(Arrays.asList(mockTodo));
+        when(todoRepository.saveAll(any())).thenReturn(Arrays.asList(mockTodo));
 
-        Todo actual = todoService.update("AAA", "USERID", false, false, 0L);
+        List<Todo> actual = todoService.updateOrder(mockUserId, Arrays.asList(mockTodo));
 
-        verify(todoRepository, times(1)).findByIdAndUserId(any(), any());
-        verify(todoRepository, times(1)).save(any());
+        verify(todoRepository, times(1)).findByUserId(any());
+        verify(todoRepository, times(1)).saveAll(any());
 
-        Assert.assertEquals(mockUserId, actual.getUserId());
-        Assert.assertEquals(mockTaskName, actual.getTaskName());
-        Assert.assertEquals(mockOrder, actual.getOrder());
-        Assert.assertEquals(mockIsDone, actual.getIsDone());
-        Assert.assertEquals(mockIsPinned, actual.getIsPinned());
-        Assert.assertEquals(mockDate, actual.getDate());
+        Assert.assertEquals(1, actual.size());
     }
 
     @Test
     public void testListTodosSuccess() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
-        Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
-        Long mockOrder = 0L;
         Date mockDate = new Date();
 
+        Todo mockTodo1 = new Todo();
+        mockTodo1.setId("1");
+        mockTodo1.setUserId(mockUserId);
+        mockTodo1.setTaskName(mockTaskName);
+        mockTodo1.setOrder(1L);
+        mockTodo1.setIsPinned(false);
+        mockTodo1.setIsDone(mockIsDone);
+        mockTodo1.setDate(mockDate);
+
+        Todo mockTodo2 = new Todo();
+        mockTodo2.setId("2");
+        mockTodo2.setUserId(mockUserId);
+        mockTodo2.setTaskName(mockTaskName);
+        mockTodo2.setOrder(2L);
+        mockTodo2.setIsPinned(true);
+        mockTodo2.setIsDone(mockIsDone);
+        mockTodo2.setDate(mockDate);
+
+        List<Todo> mockTodoList = new ArrayList<>();
+        mockTodoList.add(mockTodo1);
+        mockTodoList.add(mockTodo2);
+
+        when(todoRepository.findByUserIdOrderByOrderAsc(any())).thenReturn(mockTodoList);
+
+        List<Todo> actual = todoService.listTodos("U1");
+
+        verify(todoRepository, times(1)).findByUserIdOrderByOrderAsc(any());
+
+        Assert.assertEquals(2, actual.size());
+        Assert.assertEquals("2", actual.get(0).getId());
+
+    }
+
+    @Test(expected = RequireViolation.class)
+    public void testHandleTodoCreateRequestFailedWhenMessageInvalidFormat() throws ParseException {
+        String mockUserId = "U1";
+        String mockMessage = "Wrong format";
+
         Todo mockTodo = new Todo();
+        mockTodo.setId("1");
         mockTodo.setUserId(mockUserId);
-        mockTodo.setTaskName(mockTaskName);
-        mockTodo.setOrder(mockOrder);
-        mockTodo.setIsPinned(mockIsPinned);
-        mockTodo.setIsDone(mockIsDone);
-        mockTodo.setDate(mockDate);
+        mockTodo.setIsPinned(false);
 
-        when(todoRepository.findByUserId(any())).thenReturn(Arrays.asList(mockTodo));;
+        todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+    }
 
-        List<Todo> actual = todoService.listTodos("AAA");
+    @Test
+    public void testHandleTodoCreateRequestSuccessWhenSpecifyTime() throws ParseException {
+        String mockUserId = "U1";
+        String mockMessage = "Meeting with James : 20/12/2018 : 22:00";
 
-        verify(todoRepository, times(1)).findByUserId(any());
+        Todo mockTodo = new Todo();
+        mockTodo.setId("1");
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setIsPinned(false);
 
-        Assert.assertEquals(1, actual.size());
+        when(todoRepository.save(any())).thenReturn(mockTodo);
 
-        Assert.assertEquals(mockUserId, actual.get(0).getUserId());
-        Assert.assertEquals(mockTaskName, actual.get(0).getTaskName());
-        Assert.assertEquals(mockOrder, actual.get(0).getOrder());
-        Assert.assertEquals(mockIsDone, actual.get(0).getIsDone());
-        Assert.assertEquals(mockIsPinned, actual.get(0).getIsPinned());
-        Assert.assertEquals(mockDate, actual.get(0).getDate());
+        todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+
+        verify(todoRepository, times(1)).save(any());
     }
 
+    @Test
+    public void testHandleTodoCreateRequestSuccessWhenNotSpecifyTime() throws ParseException {
+        String mockUserId = "U1";
+        String mockMessage = "Meeting with James : 20/12/2018";
+
+        Todo mockTodo = new Todo();
+        mockTodo.setId("1");
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setIsPinned(false);
+
+        when(todoRepository.save(any())).thenReturn(mockTodo);
+
+        todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+
+        verify(todoRepository, times(1)).save(any());
+    }
+
+    @Test
+    public void testHandleTodoCreateRequestSuccessWhenSpecifyDateAndTimeToday() {
+        String mockUserId = "U1";
+        String mockMessage = "Meeting with James : today : 22:00";
+
+        Todo mockTodo = new Todo();
+        mockTodo.setId("1");
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setIsPinned(false);
+
+        when(todoRepository.save(any())).thenReturn(mockTodo);
+
+        todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+
+        verify(todoRepository, times(1)).save(any());
+    }
+
+    @Test
+    public void testHandleTodoCreateRequestSuccessWhenSpecifyDateTomorrow() {
+        String mockUserId = "U1";
+        String mockMessage = "Meeting with James : tomorrow";
+
+        Todo mockTodo = new Todo();
+        mockTodo.setId("1");
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setIsPinned(false);
+
+        when(todoRepository.save(any())).thenReturn(mockTodo);
+
+        todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+
+        verify(todoRepository, times(1)).save(any());
+    }
+
+    @Test
+    public void testHandleTodoCreateRequestFailedWhenWrongDate() {
+        String mockUserId = "U1";
+        String mockMessage = "Meeting with James : wrong";
+
+        Todo mockTodo = new Todo();
+        mockTodo.setId("1");
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setIsPinned(false);
+
+        TextMessage textMessage = todoService.handleTodoCreateRequest(mockUserId, mockMessage);
+
+        Assert.assertEquals("Invalid date format", textMessage.getText());
+    }
+
+
     @Test
     public void test() throws ParseException {
         String test = "2/1/2018 12:00";
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(test);
         System.out.println(date);
     }
 }

commit d227fe17a492a7f5f4107de811ec9a34cee8a341
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Wed Aug 22 21:54:04 2018 +0700

    UPDATE api list todo

diff --git a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
index 988a5e4..7c08dc0 100644
--- a/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
@@ -10,28 +10,28 @@ import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
 @RestController
-@RequestMapping(path = "/api/v1/users/{userId}/todos")
+@RequestMapping(path = "/api/v1/users")
 public class TodoController {
     @Autowired
     private TodoService todoService;
 
-    @GetMapping
+    @GetMapping(path = "{userId}/todos")
     public HttpEntity<ResponseModel> getAll(
             @PathVariable(name = "userId") String userId) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.listTodos(userId)).build(HttpStatus.OK);
     }
 
-    @PutMapping(path = "{todoId}")
+    @PutMapping(path = "{userId}/todos/{todoId}")
     public HttpEntity<ResponseModel> update(
             @PathVariable(name = "userId") String userId,
             @PathVariable(name = "todoId") String todoId,
             @RequestBody TodoUpdateRequest request
     ) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.update(
                 todoId,
                 userId,
                 request.getIsPinned(),
                 request.getIsDone(),
                 request.getOrder())).build(HttpStatus.OK);
     }
 }
diff --git a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
index 23d092b..b791e37 100644
--- a/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
@@ -9,5 +9,7 @@ import java.util.Optional;
 public interface TodoRepository extends MongoRepository<Todo, String> {
     Optional<Todo> findByIdAndUserId(String id, String userId);
 
     List<Todo> findByUserId(String userId);
+
+    List<Todo> findByUserIdOrderByDateAsc(String userId);
 }
diff --git a/src/main/java/com/wanichnun/todoapp/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
index e314712..09d05fa 100644
--- a/src/main/java/com/wanichnun/todoapp/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -17,67 +17,82 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     public TextMessage handleTodoCreateRequest(String userId, String message) throws ParseException {
         Boolean isPinned = false;
         Boolean isDone = false;
-        Long order = 0L;
 
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(dateText + " " + timeText);
-        this.create(userId, taskName, isPinned, isDone, order, date);
+        this.create(userId, taskName, isPinned, isDone, date);
         return new TextMessage("success");
     }
 
-    public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Long order, Date date) {
+    public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
-        todo.setOrder(order);
+        todo.setOrder(calculateOrder(userId));
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
+    private Long calculateOrder(String userId) {
+        return (long) (todoRepository.findByUserId(userId).size() + 1);
+    }
+
     public Todo update(String id, String userId, Boolean isPinned, Boolean isDone, Long order) {
         Optional<Todo> result = todoRepository.findByIdAndUserId(id, userId);
         require(result.isPresent(), "Resource not found");
-        System.out.println("result " + result);
         Todo todo = result.get();
         todo.setIsPinned(isPinned);
         todo.setIsDone(isDone);
         todo.setOrder(order);
 
         Todo updatedTodo = todoRepository.save(todo);
         log.info("Updated todo {}", updatedTodo);
         return updatedTodo;
     }
 
     public List<Todo> listTodos(String userId) {
-        List<Todo> todoList = todoRepository.findByUserId(userId);
-        return todoList;
+        List<Todo> todoList = todoRepository.findByUserIdOrderByDateAsc(userId);
+        List<Todo> pinnedTodoList = new ArrayList<>();
+        List<Todo> sortedTodoList = new ArrayList<>();
+
+        todoList.forEach((todo -> {
+            if (todo.getIsPinned()) {
+                pinnedTodoList.add(todo);
+            }
+        }));
+
+        todoList.removeAll(pinnedTodoList);
+        sortedTodoList.addAll(pinnedTodoList);
+        sortedTodoList.addAll(todoList);
+
+        return sortedTodoList;
     }
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ffc713e..ea15ae9 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,16 +1,19 @@
 spring:
   profiles: dev
   devtools:
     restart:
       enabled: true
       additional-paths: src
   data:
       mongodb:
         host: localhost
         database: todo
-
 line:
   bot:
-    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
-    channelSecret: 52f1f89f193bd08fa092371e9865afc8
+#    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
+#    channelSecret: 52f1f89f193bd08fa092371e9865afc8
+    channelToken: UZO234Na089EcMp/2SeFDVlKesy9nK0SUzyZ6QhSOokOO0iNbbde1sjU2Gb9e5oQZPSs9oHGNWwLQ049qWcxv61QkiAhT40z9Y9pZhIxnAqnDG7DIkW0g8lPZ44ppXNcdRqJMQDjrcGCG/QVbU+XHQdB04t89/1O/w1cDnyilFU=
+    channelSecret: 68250ab330c896817551e82523f37be3
+server:
+  port: 8082
 ---

commit 7da8ae5a684755b31b20575ce16406a7ac7e8bac
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 18:52:19 2018 +0700

    ADD auth

diff --git a/src/main/java/com/wanichnun/todoapp/filter/CORSFilter.java b/src/main/java/com/wanichnun/todoapp/filter/CORSFilter.java
new file mode 100644
index 0000000..505c66f
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/filter/CORSFilter.java
@@ -0,0 +1,35 @@
+package com.wanichnun.todoapp.filter;
+
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+@Order(Ordered.HIGHEST_PRECEDENCE)
+public class CORSFilter implements Filter {
+
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+            throws IOException, ServletException {
+        HttpServletResponse response = (HttpServletResponse) res;
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PATCH, PUT");
+        response.setHeader("Access-Control-Max-Age", "3600");
+        response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, "
+                + "Origin, Cache-Control, Authorization, "
+                + "sid"
+        );
+        response.setHeader("Access-Control-Expose-Headers", "sid");
+
+        chain.doFilter(req, res);
+    }
+
+    public void init(FilterConfig filterConfig) {
+    }
+
+    public void destroy() {
+    }
+}
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 0ef90b1..ffc713e 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -13,16 +13,16 @@ line:
   bot:
     channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
     channelSecret: 52f1f89f193bd08fa092371e9865afc8
 ---
 spring:
-  profiles: prod
+  profiles: default
   devtools:
     restart:
       enabled: true
       additional-paths: src
   data:
       mongodb:
         host: ds125352.mlab.com:25352
         database: todoexam
         username: todo_app
         password: ToDo@pp1

commit a2983552bdf355f1d4c31a5eaa801f0fcab82359
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 15:07:49 2018 +0700

    UPDATE Proc

diff --git a/Procfile b/Procfile
index eb75169..9f730d3 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: ./gradlew bootRun -Dserver.port=$PORT
+web: java $JAVA_OPTS -jar target/*.jar --server.port=$PORT
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ffc713e..0ef90b1 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -13,16 +13,16 @@ line:
   bot:
     channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
     channelSecret: 52f1f89f193bd08fa092371e9865afc8
 ---
 spring:
-  profiles: default
+  profiles: prod
   devtools:
     restart:
       enabled: true
       additional-paths: src
   data:
       mongodb:
         host: ds125352.mlab.com:25352
         database: todoexam
         username: todo_app
         password: ToDo@pp1

commit 0066b302b16f6610a39db6a14b7665c2efed825d
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 14:53:34 2018 +0700

    UPDATE Proc

diff --git a/Procfile b/Procfile
index c0b806a..eb75169 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: ./gradlew bootRun --server.port=$PORT --spring.profiles.active=prod
+web: ./gradlew bootRun -Dserver.port=$PORT

commit 96f52bd664fcdc8b29f77d5587b867762b63134a
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 14:31:20 2018 +0700

    UPDATE Proc

diff --git a/Procfile b/Procfile
index 5d8e02b..c0b806a 100644
--- a/Procfile
+++ b/Procfile
@@ -1 +1 @@
-web: java $JAVA_OPTS -jar target/*.jar --server.port=$PORT --spring.profiles.active=prod
\ No newline at end of file
+web: ./gradlew bootRun --server.port=$PORT --spring.profiles.active=prod

commit 4c653db2a3e97c9e53ca898c3ba4a724eedc8d88
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 14:19:37 2018 +0700

    UPDATE config for heroku

diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 0ef90b1..ffc713e 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -13,16 +13,16 @@ line:
   bot:
     channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
     channelSecret: 52f1f89f193bd08fa092371e9865afc8
 ---
 spring:
-  profiles: prod
+  profiles: default
   devtools:
     restart:
       enabled: true
       additional-paths: src
   data:
       mongodb:
         host: ds125352.mlab.com:25352
         database: todoexam
         username: todo_app
         password: ToDo@pp1

commit 2d35049c07e2b61b1d84b4726c8d1e3c66e4e3b3
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 14:15:53 2018 +0700

    ADD Procfile

diff --git a/Procfile b/Procfile
new file mode 100644
index 0000000..5d8e02b
--- /dev/null
+++ b/Procfile
@@ -0,0 +1 @@
+web: java $JAVA_OPTS -jar target/*.jar --server.port=$PORT --spring.profiles.active=prod
\ No newline at end of file

commit 41b5bc70ca224988fbfdc179f878b42ec7f73237
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Tue Aug 21 13:44:37 2018 +0700

    ADD line auth and config prod

diff --git a/build.gradle b/build.gradle
index 19a25b8..a3211dd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,2 +19,3 @@ apply plugin: 'io.spring.dependency-management'
 sourceCompatibility = 1.8
+bootRun.systemProperties = System.properties
 
@@ -26,14 +27,15 @@ repositories {
 dependencies {
     compile("org.springframework.boot:spring-boot-starter-web")
     compile("org.springframework.boot:spring-boot-devtools")
     compile("org.springframework.boot:spring-boot-starter-actuator")
     compile("org.springframework.boot:spring-boot-starter-data-mongodb")
     compile('org.valid4j:valid4j:0.5.0')
     compile('joda-time:joda-time:2.9.9')
     compile 'com.linecorp.bot:line-bot-spring-boot:2.0.0'
     compile("org.projectlombok:lombok:1.18.2")
+    compile("com.mashape.unirest:unirest-java:1.4.9")
 
     testCompile("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.0")
     testCompile("org.springframework.boot:spring-boot-starter-test")
     testCompile group: 'junit', name: 'junit', version: '4.12'
 }
diff --git a/settings.gradle b/settings.gradle
index 381292b..b41c0d1 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1,2 @@
-rootProject.name = 'line-exam'
+rootProject.name = 'todoapp'
 
diff --git a/src/main/java/com/wanichnun/lineexam/Application.java b/src/main/java/com/wanichnun/todoapp/Application.java
similarity index 92%
rename from src/main/java/com/wanichnun/lineexam/Application.java
rename to src/main/java/com/wanichnun/todoapp/Application.java
index b9f1ac0..42ee9a8 100644
--- a/src/main/java/com/wanichnun/lineexam/Application.java
+++ b/src/main/java/com/wanichnun/todoapp/Application.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam;
+package com.wanichnun.todoapp;
 
diff --git a/src/main/java/com/wanichnun/todoapp/config/RestTemplateConfig.java b/src/main/java/com/wanichnun/todoapp/config/RestTemplateConfig.java
new file mode 100644
index 0000000..5766f95
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/config/RestTemplateConfig.java
@@ -0,0 +1,13 @@
+package com.wanichnun.todoapp.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class RestTemplateConfig {
+	@Bean
+	public RestTemplate restTemplate() {
+		return new RestTemplate();
+	}
+}
diff --git a/src/main/java/com/wanichnun/todoapp/controller/AuthController.java b/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
new file mode 100644
index 0000000..caad3c2
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/controller/AuthController.java
@@ -0,0 +1,25 @@
+package com.wanichnun.todoapp.controller;
+
+import com.mashape.unirest.http.exceptions.UnirestException;
+import com.wanichnun.todoapp.model.AuthRequest;
+import com.wanichnun.todoapp.model.Response;
+import com.wanichnun.todoapp.model.ResponseModel;
+import com.wanichnun.todoapp.service.AuthService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping(path = "/api/v1/auth")
+public class AuthController {
+    @Autowired
+    private AuthService authService;
+
+    @PostMapping()
+    public HttpEntity<ResponseModel> update(
+            @RequestBody AuthRequest request
+            ) throws UnirestException {
+        return new ResponseModel(Response.SUCCESS.getContent(), authService.getAccessToken(request)).build(HttpStatus.OK);
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
similarity index 82%
rename from src/main/java/com/wanichnun/lineexam/controller/TodoController.java
rename to src/main/java/com/wanichnun/todoapp/controller/TodoController.java
index 9f4a26f..988a5e4 100644
--- a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/todoapp/controller/TodoController.java
@@ -1,7 +1,7 @@
-package com.wanichnun.lineexam.controller;
+package com.wanichnun.todoapp.controller;
 
-import com.wanichnun.lineexam.model.Response;
-import com.wanichnun.lineexam.model.ResponseModel;
-import com.wanichnun.lineexam.model.TodoUpdateRequest;
-import com.wanichnun.lineexam.service.TodoService;
+import com.wanichnun.todoapp.model.Response;
+import com.wanichnun.todoapp.model.ResponseModel;
+import com.wanichnun.todoapp.model.TodoUpdateRequest;
+import com.wanichnun.todoapp.service.TodoService;
 import org.springframework.beans.factory.annotation.Autowired;
diff --git a/src/main/java/com/wanichnun/lineexam/document/Todo.java b/src/main/java/com/wanichnun/todoapp/document/Todo.java
similarity index 90%
rename from src/main/java/com/wanichnun/lineexam/document/Todo.java
rename to src/main/java/com/wanichnun/todoapp/document/Todo.java
index 0249863..9a5df1b 100644
--- a/src/main/java/com/wanichnun/lineexam/document/Todo.java
+++ b/src/main/java/com/wanichnun/todoapp/document/Todo.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam.document;
+package com.wanichnun.todoapp.document;
 
diff --git a/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
similarity index 82%
rename from src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
rename to src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
index 5ae46ba..5882470 100644
--- a/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/todoapp/handler/MessageHandler.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam.handler;
+package com.wanichnun.todoapp.handler;
 
@@ -7,5 +7,3 @@ import com.linecorp.bot.spring.boot.annotation.EventMapping;
 import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;
-import com.sun.org.apache.xpath.internal.operations.Bool;
-import com.wanichnun.lineexam.document.Todo;
-import com.wanichnun.lineexam.service.TodoService;
+import com.wanichnun.todoapp.service.TodoService;
 import lombok.extern.slf4j.Slf4j;
@@ -14,7 +12,3 @@ import org.valid4j.errors.RequireViolation;
 
-import java.text.DateFormat;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
 
diff --git a/src/main/java/com/wanichnun/todoapp/model/AuthRequest.java b/src/main/java/com/wanichnun/todoapp/model/AuthRequest.java
new file mode 100644
index 0000000..fb8d4f1
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/model/AuthRequest.java
@@ -0,0 +1,8 @@
+package com.wanichnun.todoapp.model;
+
+import lombok.Data;
+
+@Data
+public class AuthRequest {
+    private String code;
+}
diff --git a/src/main/java/com/wanichnun/todoapp/model/AuthResponse.java b/src/main/java/com/wanichnun/todoapp/model/AuthResponse.java
new file mode 100644
index 0000000..61c780d
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/model/AuthResponse.java
@@ -0,0 +1,21 @@
+package com.wanichnun.todoapp.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class AuthResponse {
+    private String scope;
+
+    @JsonProperty(value = "access_token")
+    private String accessToken;
+
+    @JsonProperty(value = "token_type")
+    private String tokenType;
+
+    @JsonProperty(value = "expires_in")
+    private Integer expiresIn;
+
+    @JsonProperty(value = "refresh_token")
+    private String refreshToken;
+}
diff --git a/src/main/java/com/wanichnun/lineexam/model/Response.java b/src/main/java/com/wanichnun/todoapp/model/Response.java
similarity index 84%
rename from src/main/java/com/wanichnun/lineexam/model/Response.java
rename to src/main/java/com/wanichnun/todoapp/model/Response.java
index 339c0d4..ac10477 100644
--- a/src/main/java/com/wanichnun/lineexam/model/Response.java
+++ b/src/main/java/com/wanichnun/todoapp/model/Response.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam.model;
+package com.wanichnun.todoapp.model;
 
diff --git a/src/main/java/com/wanichnun/lineexam/model/ResponseModel.java b/src/main/java/com/wanichnun/todoapp/model/ResponseModel.java
similarity index 94%
rename from src/main/java/com/wanichnun/lineexam/model/ResponseModel.java
rename to src/main/java/com/wanichnun/todoapp/model/ResponseModel.java
index 67ca7f2..fbfff7a 100644
--- a/src/main/java/com/wanichnun/lineexam/model/ResponseModel.java
+++ b/src/main/java/com/wanichnun/todoapp/model/ResponseModel.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam.model;
+package com.wanichnun.todoapp.model;
 
diff --git a/src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java b/src/main/java/com/wanichnun/todoapp/model/TodoUpdateRequest.java
similarity index 79%
rename from src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java
rename to src/main/java/com/wanichnun/todoapp/model/TodoUpdateRequest.java
index cdfd740..889e4b5 100644
--- a/src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java
+++ b/src/main/java/com/wanichnun/todoapp/model/TodoUpdateRequest.java
@@ -1,2 +1,2 @@
-package com.wanichnun.lineexam.model;
+package com.wanichnun.todoapp.model;
 
diff --git a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
similarity index 77%
rename from src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
rename to src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
index 19f73d6..23d092b 100644
--- a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/todoapp/repository/TodoRepository.java
@@ -1,4 +1,4 @@
-package com.wanichnun.lineexam.repository;
+package com.wanichnun.todoapp.repository;
 
-import com.wanichnun.lineexam.document.Todo;
+import com.wanichnun.todoapp.document.Todo;
 import org.springframework.data.mongodb.repository.MongoRepository;
diff --git a/src/main/java/com/wanichnun/todoapp/service/AuthService.java b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
new file mode 100644
index 0000000..f93775c
--- /dev/null
+++ b/src/main/java/com/wanichnun/todoapp/service/AuthService.java
@@ -0,0 +1,53 @@
+package com.wanichnun.todoapp.service;
+
+import com.wanichnun.todoapp.model.AuthRequest;
+import com.wanichnun.todoapp.model.AuthResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
+
+@Slf4j
+@Service
+public class AuthService {
+    @Autowired
+    private RestTemplate restTemplate;
+
+    public AuthResponse getAccessToken(AuthRequest request) {
+        String getAccessTokenUrl = "https://api.line.me/v2/oauth/accessToken";
+
+        String clientId = "1601887173";
+        String clientSecret = "9df37fe9ad6c3c6ba0d6146be02489d5";
+        String grantType = "authorization_code";
+        String redirectUri = "https://todo-d976c.firebaseapp.com/callback";
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+
+        MultiValueMap<String, String> map= new LinkedMultiValueMap<>();
+        map.add("code", request.getCode());
+        map.add("client_id", clientId);
+        map.add("client_secret", clientSecret);
+        map.add("grant_type", grantType);
+        map.add("redirect_uri", redirectUri);
+
+        HttpEntity<MultiValueMap<String, String>> requestForm = new HttpEntity<>(map, headers);
+
+        ResponseEntity<AuthResponse> response = null;
+        try {
+            response = restTemplate.postForEntity(getAccessTokenUrl, requestForm , AuthResponse.class);
+        } catch (HttpClientErrorException e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+
+        return response.getBody();
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/service/TodoService.java b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
similarity index 89%
rename from src/main/java/com/wanichnun/lineexam/service/TodoService.java
rename to src/main/java/com/wanichnun/todoapp/service/TodoService.java
index 2ccd8c0..e314712 100644
--- a/src/main/java/com/wanichnun/lineexam/service/TodoService.java
+++ b/src/main/java/com/wanichnun/todoapp/service/TodoService.java
@@ -1,11 +1,8 @@
-package com.wanichnun.lineexam.service;
+package com.wanichnun.todoapp.service;
 
 import com.linecorp.bot.model.message.TextMessage;
-import com.sun.org.apache.xpath.internal.operations.Bool;
-import com.wanichnun.lineexam.document.Todo;
-import com.wanichnun.lineexam.model.ResponseModel;
-import com.wanichnun.lineexam.repository.TodoRepository;
+import com.wanichnun.todoapp.document.Todo;
+import com.wanichnun.todoapp.repository.TodoRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpEntity;
 import org.springframework.stereotype.Service;
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 95bb834..0ef90b1 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,14 +1,33 @@
+spring:
+  profiles: dev
+  devtools:
+    restart:
+      enabled: true
+      additional-paths: src
+  data:
+      mongodb:
+        host: localhost
+        database: todo
+
 line:
   bot:
     channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
     channelSecret: 52f1f89f193bd08fa092371e9865afc8
-
+---
 spring:
+  profiles: prod
   devtools:
     restart:
       enabled: true
       additional-paths: src
   data:
       mongodb:
-        host: localhost
-        database: todo
\ No newline at end of file
+        host: ds125352.mlab.com:25352
+        database: todoexam
+        username: todo_app
+        password: ToDo@pp1
+
+line:
+  bot:
+    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
+    channelSecret: 52f1f89f193bd08fa092371e9865afc8
\ No newline at end of file
diff --git a/src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java b/src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java
similarity index 77%
rename from src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java
rename to src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java
index afadfe1..9f80a4b 100644
--- a/src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java
+++ b/src/test/java/com/wanichnun/todoapp/handler/MessageHandlerTest.java
@@ -1,5 +1,3 @@
-package com.wanichnun.lineexam.handler;
+package com.wanichnun.todoapp.handler;
 
-import com.linecorp.bot.model.event.message.TextMessageContent;
-import org.junit.Test;
 import org.junit.runner.RunWith;
diff --git a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
similarity index 97%
rename from src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
rename to src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
index aa86948..60c7777 100644
--- a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
+++ b/src/test/java/com/wanichnun/todoapp/service/TodoServiceTest.java
@@ -1,5 +1,5 @@
-package com.wanichnun.lineexam.service;
+package com.wanichnun.todoapp.service;
 
-import com.wanichnun.lineexam.document.Todo;
-import com.wanichnun.lineexam.repository.TodoRepository;
+import com.wanichnun.todoapp.document.Todo;
+import com.wanichnun.todoapp.repository.TodoRepository;
 import org.junit.Assert;

commit 4b54016433be28750fceec91b8f4187eb76880bf
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Mon Aug 20 17:30:10 2018 +0700

    FIX issue document id

diff --git a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
index 85ef59a..9f4a26f 100644
--- a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
@@ -4,2 +4,3 @@ import com.wanichnun.lineexam.model.Response;
 import com.wanichnun.lineexam.model.ResponseModel;
+import com.wanichnun.lineexam.model.TodoUpdateRequest;
 import com.wanichnun.lineexam.service.TodoService;
@@ -8,19 +9,29 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
-@RequestMapping(path = "/api/v1/todos")
+@RequestMapping(path = "/api/v1/users/{userId}/todos")
 public class TodoController {
     @Autowired
     private TodoService todoService;
 
     @GetMapping
     public HttpEntity<ResponseModel> getAll(
-            @RequestParam(name = "userId") String userId) {
+            @PathVariable(name = "userId") String userId) {
         return new ResponseModel(Response.SUCCESS.getContent(), todoService.listTodos(userId)).build(HttpStatus.OK);
     }
 
+    @PutMapping(path = "{todoId}")
+    public HttpEntity<ResponseModel> update(
+            @PathVariable(name = "userId") String userId,
+            @PathVariable(name = "todoId") String todoId,
+            @RequestBody TodoUpdateRequest request
+    ) {
+        return new ResponseModel(Response.SUCCESS.getContent(), todoService.update(
+                todoId,
+                userId,
+                request.getIsPinned(),
+                request.getIsDone(),
+                request.getOrder())).build(HttpStatus.OK);
+    }
 }
diff --git a/src/main/java/com/wanichnun/lineexam/document/Todo.java b/src/main/java/com/wanichnun/lineexam/document/Todo.java
index c9ebe0b..0249863 100644
--- a/src/main/java/com/wanichnun/lineexam/document/Todo.java
+++ b/src/main/java/com/wanichnun/lineexam/document/Todo.java
@@ -3,5 +3,4 @@ package com.wanichnun.lineexam.document;
 import lombok.Data;
+import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
-import org.springframework.data.mongodb.core.mapping.Field;
-
 import java.util.Date;
@@ -9,12 +8,12 @@ import java.util.Date;
 @Data
 @Document(collection = "Todo")
 public class Todo {
-    @Field(value = "id")
+    @Id
     private String id;
     private String userId;
     private String taskName;
     private Boolean isPinned;
     private Boolean isDone;
     private Long order;
     private Date date;
 }
diff --git a/src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java b/src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java
new file mode 100644
index 0000000..cdfd740
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/model/TodoUpdateRequest.java
@@ -0,0 +1,10 @@
+package com.wanichnun.lineexam.model;
+
+import lombok.Data;
+
+@Data
+public class TodoUpdateRequest {
+    private Boolean isPinned;
+    private Boolean isDone;
+    private Long order;
+}

commit 938c552b64e2d07b100be0b4706d84bd5edbe78c
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Mon Aug 20 17:12:26 2018 +0700

    ADD api list todos

diff --git a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
index 1dc6d1d..85ef59a 100644
--- a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
+++ b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
@@ -2,3 +2,11 @@ package com.wanichnun.lineexam.controller;
 
+import com.wanichnun.lineexam.model.Response;
+import com.wanichnun.lineexam.model.ResponseModel;
+import com.wanichnun.lineexam.service.TodoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -6,5 +14,13 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping(path = "/api/v1/todos")
 public class TodoController {
+    @Autowired
+    private TodoService todoService;
+
+    @GetMapping
+    public HttpEntity<ResponseModel> getAll(
+            @RequestParam(name = "userId") String userId) {
+        return new ResponseModel(Response.SUCCESS.getContent(), todoService.listTodos(userId)).build(HttpStatus.OK);
+    }
 
 }
diff --git a/src/main/java/com/wanichnun/lineexam/model/Response.java b/src/main/java/com/wanichnun/lineexam/model/Response.java
new file mode 100644
index 0000000..339c0d4
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/model/Response.java
@@ -0,0 +1,15 @@
+package com.wanichnun.lineexam.model;
+
+import lombok.Getter;
+
+@Getter
+public enum Response {
+    SUCCESS("success"),
+    ERROR("error");
+
+    private final String content;
+
+    Response(String content) {
+        this.content = content;
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/model/ResponseModel.java b/src/main/java/com/wanichnun/lineexam/model/ResponseModel.java
new file mode 100644
index 0000000..67ca7f2
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/model/ResponseModel.java
@@ -0,0 +1,27 @@
+package com.wanichnun.lineexam.model;
+
+import lombok.Data;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+@Data
+public class ResponseModel {
+
+    final String message;
+    final Object data;
+
+    public ResponseModel(String message, Object data) {
+        this.message = message;
+        this.data = data;
+    }
+
+    public ResponseModel(String message) {
+        this.message = message;
+        this.data = "";
+    }
+
+    public HttpEntity<ResponseModel> build(HttpStatus status) {
+        return new ResponseEntity<>(new ResponseModel(this.message, this.data), status);
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
index 54dc943..19f73d6 100644
--- a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
@@ -9,3 +9,5 @@ import java.util.Optional;
 public interface TodoRepository extends MongoRepository<Todo, String> {
     Optional<Todo> findByIdAndUserId(String id, String userId);
+
+    List<Todo> findByUserId(String userId);
 }
diff --git a/src/main/java/com/wanichnun/lineexam/service/TodoService.java b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
index 5c1d7da..2ccd8c0 100644
--- a/src/main/java/com/wanichnun/lineexam/service/TodoService.java
+++ b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
@@ -5,2 +5,3 @@ import com.sun.org.apache.xpath.internal.operations.Bool;
 import com.wanichnun.lineexam.document.Todo;
+import com.wanichnun.lineexam.model.ResponseModel;
 import com.wanichnun.lineexam.repository.TodoRepository;
@@ -8,2 +9,3 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
 import org.springframework.stereotype.Service;
@@ -13,6 +15,3 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Optional;
-import java.util.UUID;
+import java.util.*;
 
@@ -21,62 +20,67 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     public TextMessage handleTodoCreateRequest(String userId, String message) throws ParseException {
         Boolean isPinned = false;
         Boolean isDone = false;
         Long order = 0L;
 
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(dateText + " " + timeText);
         this.create(userId, taskName, isPinned, isDone, order, date);
         return new TextMessage("success");
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Long order, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(order);
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     public Todo update(String id, String userId, Boolean isPinned, Boolean isDone, Long order) {
         Optional<Todo> result = todoRepository.findByIdAndUserId(id, userId);
         require(result.isPresent(), "Resource not found");
         System.out.println("result " + result);
         Todo todo = result.get();
         todo.setIsPinned(isPinned);
         todo.setIsDone(isDone);
         todo.setOrder(order);
 
         Todo updatedTodo = todoRepository.save(todo);
         log.info("Updated todo {}", updatedTodo);
         return updatedTodo;
     }
+
+    public List<Todo> listTodos(String userId) {
+        List<Todo> todoList = todoRepository.findByUserId(userId);
+        return todoList;
+    }
 }
diff --git a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
index 4dcb84c..aa86948 100644
--- a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
+++ b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
@@ -13,5 +13,3 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Optional;
+import java.util.*;
 
@@ -23,87 +21,120 @@ import static org.mockito.Mockito.when;
 public class TodoServiceTest {
     private TodoService todoService;
 
     @Mock
     private TodoRepository todoRepository;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         todoService = new TodoService(todoRepository);
     }
 
     @Test
     public void testCreateTodo() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockOrder, mockDate);
 
         verify(todoRepository, times(1)).save(any());
 
         Assert.assertEquals(mockTaskName, actual.getTaskName());
         Assert.assertEquals(mockUserId, actual.getUserId());
         Assert.assertEquals(mockOrder, actual.getOrder());
         Assert.assertEquals(mockIsDone, actual.getIsDone());
         Assert.assertEquals(mockIsPinned, actual.getIsPinned());
         Assert.assertEquals(mockDate, actual.getDate());
     }
 
     @Test
     public void testUpdateSuccess() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
         Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
         Optional<Todo> mockTodoOpt = Optional.of(mockTodo);
 
         when(todoRepository.findByIdAndUserId(any(), any())).thenReturn(mockTodoOpt);
         when(todoRepository.save(any())).thenReturn(mockTodoOpt.get());
 
         Todo actual = todoService.update("AAA", "USERID", false, false, 0L);
 
         verify(todoRepository, times(1)).findByIdAndUserId(any(), any());
         verify(todoRepository, times(1)).save(any());
 
         Assert.assertEquals(mockUserId, actual.getUserId());
         Assert.assertEquals(mockTaskName, actual.getTaskName());
         Assert.assertEquals(mockOrder, actual.getOrder());
         Assert.assertEquals(mockIsDone, actual.getIsDone());
         Assert.assertEquals(mockIsPinned, actual.getIsPinned());
         Assert.assertEquals(mockDate, actual.getDate());
     }
 
+    @Test
+    public void testListTodosSuccess() {
+        String mockUserId = "U1";
+        String mockTaskName = "mock-task";
+        Boolean mockIsPinned = false;
+        Boolean mockIsDone = false;
+        Long mockOrder = 0L;
+        Date mockDate = new Date();
+
+        Todo mockTodo = new Todo();
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setTaskName(mockTaskName);
+        mockTodo.setOrder(mockOrder);
+        mockTodo.setIsPinned(mockIsPinned);
+        mockTodo.setIsDone(mockIsDone);
+        mockTodo.setDate(mockDate);
+
+        when(todoRepository.findByUserId(any())).thenReturn(Arrays.asList(mockTodo));;
+
+        List<Todo> actual = todoService.listTodos("AAA");
+
+        verify(todoRepository, times(1)).findByUserId(any());
+
+        Assert.assertEquals(1, actual.size());
+
+        Assert.assertEquals(mockUserId, actual.get(0).getUserId());
+        Assert.assertEquals(mockTaskName, actual.get(0).getTaskName());
+        Assert.assertEquals(mockOrder, actual.get(0).getOrder());
+        Assert.assertEquals(mockIsDone, actual.get(0).getIsDone());
+        Assert.assertEquals(mockIsPinned, actual.get(0).getIsPinned());
+        Assert.assertEquals(mockDate, actual.get(0).getDate());
+    }
+
     @Test
     public void test() throws ParseException {
         String test = "2/1/2018 12:00";
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(test);
         System.out.println(date);
     }
 }

commit 7a6a2ccb5c8ee301682db76042a0ad34a85a75be
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Mon Aug 20 17:01:03 2018 +0700

    ADD unit test

diff --git a/src/main/java/com/wanichnun/lineexam/controller/TodoController.java b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
new file mode 100644
index 0000000..1dc6d1d
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/controller/TodoController.java
@@ -0,0 +1,10 @@
+package com.wanichnun.lineexam.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(path = "/api/v1/todos")
+public class TodoController {
+
+}
diff --git a/src/main/java/com/wanichnun/lineexam/service/TodoService.java b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
index b785493..5c1d7da 100644
--- a/src/main/java/com/wanichnun/lineexam/service/TodoService.java
+++ b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
@@ -21,62 +21,62 @@ import static org.valid4j.Assertive.require;
 @Slf4j
 @Service
 public class TodoService {
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
     public TextMessage handleTodoCreateRequest(String userId, String message) throws ParseException {
         Boolean isPinned = false;
         Boolean isDone = false;
         Long order = 0L;
 
         String[] splittedMessage = message.split(" : ");
         require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
 
         String taskName = splittedMessage[0];
         String dateText = splittedMessage[1];
         String timeText = "12:00";
         if (splittedMessage.length > 2) {
             timeText = splittedMessage[2];
         }
 
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(dateText + " " + timeText);
         this.create(userId, taskName, isPinned, isDone, order, date);
         return new TextMessage("success");
     }
 
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Long order, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
         todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(order);
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
 
     public Todo update(String id, String userId, Boolean isPinned, Boolean isDone, Long order) {
         Optional<Todo> result = todoRepository.findByIdAndUserId(id, userId);
         require(result.isPresent(), "Resource not found");
-
+        System.out.println("result " + result);
         Todo todo = result.get();
         todo.setIsPinned(isPinned);
         todo.setIsDone(isDone);
         todo.setOrder(order);
 
         Todo updatedTodo = todoRepository.save(todo);
         log.info("Updated todo {}", updatedTodo);
         return updatedTodo;
     }
 }
diff --git a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
index 62897f8..4dcb84c 100644
--- a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
+++ b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
@@ -15,2 +15,3 @@ import java.util.Date;
 import java.util.Locale;
+import java.util.Optional;
 
@@ -22,52 +23,87 @@ import static org.mockito.Mockito.when;
 public class TodoServiceTest {
     private TodoService todoService;
 
     @Mock
     private TodoRepository todoRepository;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         todoService = new TodoService(todoRepository);
     }
 
     @Test
     public void testCreateTodo() {
         String mockUserId = "U1";
         String mockTaskName = "mock-task";
         Boolean mockIsPinned = false;
         Boolean mockIsDone = false;
-        Long mockOrder = 1L;
+        Long mockOrder = 0L;
         Date mockDate = new Date();
 
         Todo mockTodo = new Todo();
         mockTodo.setUserId(mockUserId);
         mockTodo.setTaskName(mockTaskName);
         mockTodo.setOrder(mockOrder);
         mockTodo.setIsPinned(mockIsPinned);
         mockTodo.setIsDone(mockIsDone);
         mockTodo.setDate(mockDate);
 
 
         when(todoRepository.save(any())).thenReturn(mockTodo);
 
         Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockOrder, mockDate);
 
         verify(todoRepository, times(1)).save(any());
 
         Assert.assertEquals(mockTaskName, actual.getTaskName());
         Assert.assertEquals(mockUserId, actual.getUserId());
         Assert.assertEquals(mockOrder, actual.getOrder());
         Assert.assertEquals(mockIsDone, actual.getIsDone());
         Assert.assertEquals(mockIsPinned, actual.getIsPinned());
         Assert.assertEquals(mockDate, actual.getDate());
     }
 
+    @Test
+    public void testUpdateSuccess() {
+        String mockUserId = "U1";
+        String mockTaskName = "mock-task";
+        Boolean mockIsPinned = false;
+        Boolean mockIsDone = false;
+        Long mockOrder = 0L;
+        Date mockDate = new Date();
+
+        Todo mockTodo = new Todo();
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setTaskName(mockTaskName);
+        mockTodo.setOrder(mockOrder);
+        mockTodo.setIsPinned(mockIsPinned);
+        mockTodo.setIsDone(mockIsDone);
+        mockTodo.setDate(mockDate);
+
+        Optional<Todo> mockTodoOpt = Optional.of(mockTodo);
+
+        when(todoRepository.findByIdAndUserId(any(), any())).thenReturn(mockTodoOpt);
+        when(todoRepository.save(any())).thenReturn(mockTodoOpt.get());
+
+        Todo actual = todoService.update("AAA", "USERID", false, false, 0L);
+
+        verify(todoRepository, times(1)).findByIdAndUserId(any(), any());
+        verify(todoRepository, times(1)).save(any());
+
+        Assert.assertEquals(mockUserId, actual.getUserId());
+        Assert.assertEquals(mockTaskName, actual.getTaskName());
+        Assert.assertEquals(mockOrder, actual.getOrder());
+        Assert.assertEquals(mockIsDone, actual.getIsDone());
+        Assert.assertEquals(mockIsPinned, actual.getIsPinned());
+        Assert.assertEquals(mockDate, actual.getDate());
+    }
+
     @Test
     public void test() throws ParseException {
         String test = "2/1/2018 12:00";
         DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
         Date date = format.parse(test);
         System.out.println(date);
     }
 }

commit 486512b0d23600623b5f4266e4c6fd171df4d510
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Mon Aug 20 16:44:41 2018 +0700

    REFACTOR

diff --git a/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java b/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
index df089ad..5ae46ba 100644
--- a/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
+++ b/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
@@ -23,48 +23,31 @@ import static org.valid4j.Assertive.require;
 @LineMessageHandler
 @Slf4j
 public class MessageHandler {
     String edit = "edit";
 
     @Autowired
     private TodoService todoService;
 
     @EventMapping
     public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws ParseException {
         log.info("Got message this bot: {}", event);
         try {
             if (edit.equals(event.getMessage().getText())) {
                 return new TextMessage("https://google.com");
             }
             else {
                 String userId = event.getSource().getUserId();
-                Boolean isPinned = false;
-                Boolean isDone = false;
-                Long order = 0L;
-
-                String[] message = event.getMessage().getText().split(" : ");
-                require(message.length >= 2 && message.length <= 3, "Invalid text format");
-
-                String taskName = message[0];
-                String dateText = message[1];
-                String timeText = "12:00";
-                if (message.length > 2) {
-                    timeText = message[2];
-                }
-
-                DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
-                Date date = format.parse(dateText + " " + timeText);
-                todoService.create(userId, taskName, isPinned, isDone, order, date);
-
-                return new TextMessage("success");
+                String messageContent = event.getMessage().getText();
+                return todoService.handleTodoCreateRequest(userId, messageContent);
             }
         }
         catch (RequireViolation re) {
             return new TextMessage(re.getMessage());
         }
         catch (Exception e) {
             log.error("Error " + e);
             return new TextMessage("Wrong format");
         }
 
     }
 }
diff --git a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
index 969a421..54dc943 100644
--- a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
+++ b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
@@ -5,3 +5,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
 
+import java.util.List;
+import java.util.Optional;
+
 public interface TodoRepository extends MongoRepository<Todo, String> {
+    Optional<Todo> findByIdAndUserId(String id, String userId);
 }
diff --git a/src/main/java/com/wanichnun/lineexam/service/TodoService.java b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
index 2ec5f62..b785493 100644
--- a/src/main/java/com/wanichnun/lineexam/service/TodoService.java
+++ b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
@@ -3,2 +3,3 @@ package com.wanichnun.lineexam.service;
 import com.linecorp.bot.model.message.TextMessage;
+import com.sun.org.apache.xpath.internal.operations.Bool;
 import com.wanichnun.lineexam.document.Todo;
@@ -9,30 +10,73 @@ import org.springframework.stereotype.Service;
 
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
+import java.util.Optional;
 import java.util.UUID;
 
+import static org.valid4j.Assertive.require;
+
 @Slf4j
 @Service
 public class TodoService {
 
     private TodoRepository todoRepository;
 
     @Autowired
     public TodoService(TodoRepository todoRepository) {
         this.todoRepository = todoRepository;
     }
 
+    public TextMessage handleTodoCreateRequest(String userId, String message) throws ParseException {
+        Boolean isPinned = false;
+        Boolean isDone = false;
+        Long order = 0L;
+
+        String[] splittedMessage = message.split(" : ");
+        require(splittedMessage.length >= 2 && splittedMessage.length <= 3, "Invalid text format");
+
+        String taskName = splittedMessage[0];
+        String dateText = splittedMessage[1];
+        String timeText = "12:00";
+        if (splittedMessage.length > 2) {
+            timeText = splittedMessage[2];
+        }
+
+        DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
+        Date date = format.parse(dateText + " " + timeText);
+        this.create(userId, taskName, isPinned, isDone, order, date);
+        return new TextMessage("success");
+    }
+
     public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Long order, Date date) {
         Todo todo = new Todo();
         todo.setId(UUID.randomUUID().toString());
+        todo.setTaskName(taskName);
         todo.setUserId(userId);
         todo.setIsDone(isDone);
         todo.setIsPinned(isPinned);
         todo.setOrder(order);
         todo.setDate(date);
 
         Todo result = todoRepository.save(todo);
         log.info("Saved todo {}", result);
 
         return result;
     }
+
+    public Todo update(String id, String userId, Boolean isPinned, Boolean isDone, Long order) {
+        Optional<Todo> result = todoRepository.findByIdAndUserId(id, userId);
+        require(result.isPresent(), "Resource not found");
+
+        Todo todo = result.get();
+        todo.setIsPinned(isPinned);
+        todo.setIsDone(isDone);
+        todo.setOrder(order);
+
+        Todo updatedTodo = todoRepository.save(todo);
+        log.info("Updated todo {}", updatedTodo);
+        return updatedTodo;
+    }
 }

commit 4528935ae443852ac091954c0e00bf65e3ac6967
Author: Wanichnun Sinpitak <kitaboons@gmail.com>
Date:   Mon Aug 20 15:29:17 2018 +0700

    INIT project

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e81b55d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,121 @@
+
+# Created by https://www.gitignore.io/api/java,gradle,jetbrains+all
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+### JetBrains+all ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn.  Uncomment if using
+# auto-import.
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+### JetBrains+all Patch ###
+# Ignores the whole .idea folder and all .iml files
+# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
+
+.idea/
+
+# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
+
+*.iml
+modules.xml
+.idea/misc.xml
+*.ipr
+
+### Gradle ###
+.gradle
+/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
+
+
+# End of https://www.gitignore.io/api/java,gradle,jetbrains+all
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..19a25b8
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,39 @@
+group 'com.wanichnun'
+version '1.0-SNAPSHOT'
+
+buildscript {
+    repositories {
+        mavenCentral()
+    }
+    dependencies {
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
+    }
+}
+
+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'idea'
+apply plugin: 'org.springframework.boot'
+apply plugin: 'io.spring.dependency-management'
+
+sourceCompatibility = 1.8
+
+repositories {
+    mavenCentral()
+    jcenter()
+}
+
+dependencies {
+    compile("org.springframework.boot:spring-boot-starter-web")
+    compile("org.springframework.boot:spring-boot-devtools")
+    compile("org.springframework.boot:spring-boot-starter-actuator")
+    compile("org.springframework.boot:spring-boot-starter-data-mongodb")
+    compile('org.valid4j:valid4j:0.5.0')
+    compile('joda-time:joda-time:2.9.9')
+    compile 'com.linecorp.bot:line-bot-spring-boot:2.0.0'
+    compile("org.projectlombok:lombok:1.18.2")
+
+    testCompile("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.0")
+    testCompile("org.springframework.boot:spring-boot-starter-test")
+    testCompile group: 'junit', name: 'junit', version: '4.12'
+}
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
new file mode 100644
index 0000000..fac19a9
--- /dev/null
+++ b/docker/docker-compose.yml
@@ -0,0 +1,26 @@
+version: '3.5'
+services:
+#  web_dev:
+#    build: .
+#    ports:
+#      -  "4000:4000"
+#    volumes:
+#      -  .:/app
+#    environment:
+#      -  ENV=development
+#      -  PORT=4000
+#      -  DB=mongodb://mongodb:27017/todoDev
+  mongodb:
+    image: mongo:latest
+    container_name: "mongodb"
+    environment:
+      -  MONGO_DATA_DIR=/usr/data/db
+      -  MONGO_LOG_DIR=/dev/null
+    volumes:
+      -  ./data/db:/usr/data/db
+    ports:
+      -  27017:27017
+    command: mongod  --smallfiles  --logpath=/dev/null  #  --quiet
+networks:
+  default:
+    name: web_dev
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..01b8bf6
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..36cfab1
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Aug 20 11:24:52 ICT 2018
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+    echo "$*"
+}
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Escape application args
+save () {
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+    echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+  cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..381292b
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,2 @@
+rootProject.name = 'line-exam'
+
diff --git a/src/main/java/com/wanichnun/lineexam/Application.java b/src/main/java/com/wanichnun/lineexam/Application.java
new file mode 100644
index 0000000..b9f1ac0
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/Application.java
@@ -0,0 +1,13 @@
+package com.wanichnun.lineexam;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableAutoConfiguration
+public class Application {
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/document/Todo.java b/src/main/java/com/wanichnun/lineexam/document/Todo.java
new file mode 100644
index 0000000..c9ebe0b
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/document/Todo.java
@@ -0,0 +1,20 @@
+package com.wanichnun.lineexam.document;
+
+import lombok.Data;
+import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.Field;
+
+import java.util.Date;
+
+@Data
+@Document(collection = "Todo")
+public class Todo {
+    @Field(value = "id")
+    private String id;
+    private String userId;
+    private String taskName;
+    private Boolean isPinned;
+    private Boolean isDone;
+    private Long order;
+    private Date date;
+}
diff --git a/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java b/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
new file mode 100644
index 0000000..df089ad
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/handler/MessageHandler.java
@@ -0,0 +1,70 @@
+package com.wanichnun.lineexam.handler;
+
+import com.linecorp.bot.model.event.MessageEvent;
+import com.linecorp.bot.model.event.message.TextMessageContent;
+import com.linecorp.bot.model.message.TextMessage;
+import com.linecorp.bot.spring.boot.annotation.EventMapping;
+import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;
+import com.sun.org.apache.xpath.internal.operations.Bool;
+import com.wanichnun.lineexam.document.Todo;
+import com.wanichnun.lineexam.service.TodoService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.valid4j.errors.RequireViolation;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import static org.valid4j.Assertive.require;
+
+@LineMessageHandler
+@Slf4j
+public class MessageHandler {
+    String edit = "edit";
+
+    @Autowired
+    private TodoService todoService;
+
+    @EventMapping
+    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) throws ParseException {
+        log.info("Got message this bot: {}", event);
+        try {
+            if (edit.equals(event.getMessage().getText())) {
+                return new TextMessage("https://google.com");
+            }
+            else {
+                String userId = event.getSource().getUserId();
+                Boolean isPinned = false;
+                Boolean isDone = false;
+                Long order = 0L;
+
+                String[] message = event.getMessage().getText().split(" : ");
+                require(message.length >= 2 && message.length <= 3, "Invalid text format");
+
+                String taskName = message[0];
+                String dateText = message[1];
+                String timeText = "12:00";
+                if (message.length > 2) {
+                    timeText = message[2];
+                }
+
+                DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
+                Date date = format.parse(dateText + " " + timeText);
+                todoService.create(userId, taskName, isPinned, isDone, order, date);
+
+                return new TextMessage("success");
+            }
+        }
+        catch (RequireViolation re) {
+            return new TextMessage(re.getMessage());
+        }
+        catch (Exception e) {
+            log.error("Error " + e);
+            return new TextMessage("Wrong format");
+        }
+
+    }
+}
diff --git a/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
new file mode 100644
index 0000000..969a421
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/repository/TodoRepository.java
@@ -0,0 +1,7 @@
+package com.wanichnun.lineexam.repository;
+
+import com.wanichnun.lineexam.document.Todo;
+import org.springframework.data.mongodb.repository.MongoRepository;
+
+public interface TodoRepository extends MongoRepository<Todo, String> {
+}
diff --git a/src/main/java/com/wanichnun/lineexam/service/TodoService.java b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
new file mode 100644
index 0000000..2ec5f62
--- /dev/null
+++ b/src/main/java/com/wanichnun/lineexam/service/TodoService.java
@@ -0,0 +1,38 @@
+package com.wanichnun.lineexam.service;
+
+import com.linecorp.bot.model.message.TextMessage;
+import com.wanichnun.lineexam.document.Todo;
+import com.wanichnun.lineexam.repository.TodoRepository;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.UUID;
+
+@Slf4j
+@Service
+public class TodoService {
+
+    private TodoRepository todoRepository;
+
+    @Autowired
+    public TodoService(TodoRepository todoRepository) {
+        this.todoRepository = todoRepository;
+    }
+
+    public Todo create(String userId, String taskName, Boolean isPinned, Boolean isDone, Long order, Date date) {
+        Todo todo = new Todo();
+        todo.setId(UUID.randomUUID().toString());
+        todo.setUserId(userId);
+        todo.setIsDone(isDone);
+        todo.setIsPinned(isPinned);
+        todo.setOrder(order);
+        todo.setDate(date);
+
+        Todo result = todoRepository.save(todo);
+        log.info("Saved todo {}", result);
+
+        return result;
+    }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..95bb834
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,14 @@
+line:
+  bot:
+    channelToken: 8G/19OV1PFe3LtbbUIK1YhzQBtigpfk2ncxGA+Ul3yzDhRKEl2O6rJUj/RmMMe93lojH6foXpZ5Ruw6CpN6+/klIWoQT3dIGI3iMl6aYvd8qYjcpSMpC4/WsYi6OaSUhf+UADvVyOBdHvIPpN8dL5QdB04t89/1O/w1cDnyilFU=
+    channelSecret: 52f1f89f193bd08fa092371e9865afc8
+
+spring:
+  devtools:
+    restart:
+      enabled: true
+      additional-paths: src
+  data:
+      mongodb:
+        host: localhost
+        database: todo
\ No newline at end of file
diff --git a/src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java b/src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java
new file mode 100644
index 0000000..afadfe1
--- /dev/null
+++ b/src/test/java/com/wanichnun/lineexam/handler/MessageHandlerTest.java
@@ -0,0 +1,18 @@
+package com.wanichnun.lineexam.handler;
+
+import com.linecorp.bot.model.event.message.TextMessageContent;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+public class MessageHandlerTest {
+    @Autowired
+    MessageHandler messageHandler;
+
+//    @Test
+//    public void testHandleTextMessageEvent() {
+//        TextMessageContent textMessageContent = new TextMessageContent("123", "edit");
+//    }
+}
diff --git a/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
new file mode 100644
index 0000000..62897f8
--- /dev/null
+++ b/src/test/java/com/wanichnun/lineexam/service/TodoServiceTest.java
@@ -0,0 +1,73 @@
+package com.wanichnun.lineexam.service;
+
+import com.wanichnun.lineexam.document.Todo;
+import com.wanichnun.lineexam.repository.TodoRepository;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class TodoServiceTest {
+    private TodoService todoService;
+
+    @Mock
+    private TodoRepository todoRepository;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        todoService = new TodoService(todoRepository);
+    }
+
+    @Test
+    public void testCreateTodo() {
+        String mockUserId = "U1";
+        String mockTaskName = "mock-task";
+        Boolean mockIsPinned = false;
+        Boolean mockIsDone = false;
+        Long mockOrder = 1L;
+        Date mockDate = new Date();
+
+        Todo mockTodo = new Todo();
+        mockTodo.setUserId(mockUserId);
+        mockTodo.setTaskName(mockTaskName);
+        mockTodo.setOrder(mockOrder);
+        mockTodo.setIsPinned(mockIsPinned);
+        mockTodo.setIsDone(mockIsDone);
+        mockTodo.setDate(mockDate);
+
+
+        when(todoRepository.save(any())).thenReturn(mockTodo);
+
+        Todo actual = todoService.create(mockUserId, mockTaskName, mockIsPinned, mockIsDone, mockOrder, mockDate);
+
+        verify(todoRepository, times(1)).save(any());
+
+        Assert.assertEquals(mockTaskName, actual.getTaskName());
+        Assert.assertEquals(mockUserId, actual.getUserId());
+        Assert.assertEquals(mockOrder, actual.getOrder());
+        Assert.assertEquals(mockIsDone, actual.getIsDone());
+        Assert.assertEquals(mockIsPinned, actual.getIsPinned());
+        Assert.assertEquals(mockDate, actual.getDate());
+    }
+
+    @Test
+    public void test() throws ParseException {
+        String test = "2/1/2018 12:00";
+        DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH);
+        Date date = format.parse(test);
+        System.out.println(date);
+    }
+}
