Package com.getit.todoapp.domain

Examples of com.getit.todoapp.domain.Todo


  @RequestMapping(value = "/{id}", method = RequestMethod.PUT, headers = "Accept=application/json")
    public ResponseEntity<String> updateFromJson(@RequestBody String json, @PathVariable("id") Long id) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        Todo todo = Todo.fromJsonToTodo(json.toString());
        if (todoService.updateTodo(todo) == null) {
            return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<String>(headers, HttpStatus.OK);
    }
View Full Code Here


    }

  @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
    @ResponseBody
    public ResponseEntity<String> showJson(@PathVariable("id") Long id) {
        Todo todo = todoService.findTodo(id);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json; charset=utf-8");
        if (todo == null) {
            return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<String>(todo.toJson(), headers, HttpStatus.OK);
    }
View Full Code Here

        return new ResponseEntity<String>(Todo.toJsonArray(result), headers, HttpStatus.OK);
    }

  @RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
    public ResponseEntity<String> createFromJson(@RequestBody String json,Authentication authentication) {
        Todo todo = Todo.fromJsonToTodo(json);
        User user=(User) authentication.getPrincipal();
        Userinfo userinfo=userService.findByUserName(user.getUsername()).get(0);
        todo.setUserName(userinfo);
        todoService.saveTodo(todo);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        return new ResponseEntity<String>(headers, HttpStatus.CREATED);
    }
View Full Code Here

  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, headers = "Accept=application/json")
    public ResponseEntity<String> deleteFromJson(@PathVariable("id") Long id,Authentication authentication) {
       
        User user=(User) authentication.getPrincipal();
        Todo todo = todoService.findTodoByUserNameAndId(user.getUsername(),id);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        if (todo == null) {
            return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
        }
        todo.setUserName(null);
        todoService.deleteTodo(todo);
        return new ResponseEntity<String>(headers, HttpStatus.OK);
    }
View Full Code Here

TOP

Related Classes of com.getit.todoapp.domain.Todo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.