Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javax.validation.constraints.Size;
import java.time.LocalDate;

public class ToDo {
public class Todo {
private int id;

@Size(min=10, message="Enter at-least 10 characters")
Expand All @@ -13,7 +13,7 @@ public class ToDo {
private boolean done;


public ToDo(int id, String description,String userName, LocalDate targetDate, boolean done) {
public Todo(int id, String description,String userName, LocalDate targetDate, boolean done) {
this.id = id;
this.userName = userName;
this.description = description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.todoapplication.myfirstwebapp.todo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;


Expand All @@ -16,43 +14,41 @@

@Controller
@SessionAttributes("name")
public class toDoController {
public class TodoController {


private ToDoService toDoService;
private TodoService todoService;

public toDoController(ToDoService toDoService) {
this.toDoService = toDoService;
public TodoController(TodoService todoService) {
this.todoService = todoService;
}

@RequestMapping("list-todos")
public String toDoController(ModelMap model){
List<ToDo> alvin = toDoService.findByUserName("alvin");
List<Todo> alvin = todoService.findByUserName("alvin");
model.put("todos", alvin);
return "listToDos";
return "listTodos";
}


@RequestMapping(value="add-todo", method = RequestMethod.GET)
public String addToDoController(ModelMap model){
String userName = (String) model.get("name");
ToDo todo = new ToDo(7,"",userName,LocalDate.now().plusYears(3),false);
Todo todo = new Todo(7,"",userName,LocalDate.now().plusYears(3),false);
model.put("todo", todo);
return "todo";
}


@RequestMapping(value="add-todo", method = RequestMethod.POST)
public String newToDoController(ModelMap model, @Valid ToDo todo, BindingResult result){
String userName = (String) model.get("name");
ToDo todos = new ToDo(7,"",userName,LocalDate.now().plusYears(3),false);
model.put("todo", todos);
public String newToDoController(ModelMap model, @Valid Todo todo, BindingResult result){

if(result.hasErrors()) {
return "todo";
}
String userName = (String) model.get("name");

// String userName = (String) model.get("name");
toDoService.addToDo( userName, todo.getDescription(), LocalDate.now(), false);
todoService.addToDo( userName, todo.getDescription(), LocalDate.now(), false);
return "redirect:list-todos";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.todoapplication.myfirstwebapp.todo;

import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
public class TodoService {

private static List<Todo> todos = new ArrayList<>();

private static int toDoCount = 5;
static{
todos.add(new Todo(1,"testingAlvin","alvin", LocalDate.now().plusYears(1),false));
todos.add(new Todo(2,"rest","alvin", LocalDate.now().plusYears(2),false));
todos.add(new Todo(3,"java","alvin", LocalDate.now().plusYears(3),false));
todos.add(new Todo(4,"testCase","alvin", LocalDate.now().plusYears(4),false));
todos.add(new Todo(5,"caseTest","alvin", LocalDate.now().plusYears(5),false));
}


public List<Todo> findByUserName(String UserName){

return todos;
}

public void addToDo(String username,String Description,LocalDate targetDate,boolean isdone){
Todo todo = new Todo(5,Description,username, targetDate.now().plusYears(5),isdone);
todos.add(todo);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/resources/WEB-INF/jsp/todo.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

<form:input type="hidden" path="id"/>



<form:input type="hidden" path="done"/>

<input type="submit" class="btn btn-success"/>
Expand Down