.ofNullable(todoListMapper.getMaxId(Integer.valueOf(headerId)))\r
.orElse(0);\r
}\r
+ \r
+ public int createTodoList(TodoListInfo dto) {\r
+ return todoListMapper.insert(to(dto));\r
+ }\r
+ \r
+ private TodoListDto to(TodoListInfo dto) {\r
+ return TodoListDto.builder()\r
+ .headerId(dto.getHeaderId())\r
+ .id(dto.getId())\r
+ .name(dto.getName())\r
+ .done(dto.getDone())\r
+ .created(dto.getCreated())\r
+ .updated(dto.getUpdated())\r
+ .build();\r
+ }\r
+ \r
+ public int deleteTodoList(Integer headerId, Integer id) {\r
+ return todoListMapper.delete(headerId, id);\r
+ }\r
+ \r
+ public int updateTodoList(TodoListInfo dto) {\r
+ return todoListMapper.update(to(dto));\r
+ }\r
}\r
import java.util.List;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
import com.example.dto.TodoListDto;
Integer getMaxId(@Param("headerId") Integer headerId);
//TODO create delete update
+ @Insert({"<script>",
+ "INSERT INTO todo_list(",
+ " id, header_id, name, done, created, updated)",
+ " VALUES (#{id}, #{headerId}, #{name}, #{done}, #{created}, #{updated});",
+ "</script>" })
+ int insert(TodoListDto dto);
+
+ @Delete({"<script>",
+ " delete from todo_list",
+ " where",
+ " header_id = #{headerId}",
+ " and id = #{id}",
+ "</script>" })
+ int delete(@Param("headerId") Integer headerId, @Param("id") Integer id);
+
+ @Update({"<script>",
+ " update todo_list",
+ " set name=#{name}, done=#{done}, updated=#{updated}",
+ " where",
+ " header_id = #{headerId}",
+ " and id = #{id}",
+ "</script>" })
+ int update(TodoListDto dto);
}
\ No newline at end of file
\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.http.MediaType;\r
+import org.springframework.web.bind.annotation.RequestBody;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
import org.springframework.web.bind.annotation.RequestParam;\r
public Integer getMaxId(@RequestParam(name = "headerId") String headerId) {\r
return todoHeaderService.getMaxId(headerId);\r
}\r
+ \r
+ @RequestMapping(value = "/createTodoList", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)\r
+ @ResponseBody\r
+ public int createTodoList(@RequestBody TodoListInfo form) {\r
+ return todoHeaderService.createTodoList(form);\r
+ }\r
+ \r
+ @RequestMapping(value = "/deleteTodoList", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)\r
+ @ResponseBody\r
+ public int deleteTodoList(@RequestBody TodoListInfo form) {\r
+ return todoHeaderService.deleteTodoList(form.getHeaderId(), form.getId());\r
+ }\r
+ \r
+ @RequestMapping(value = "/updateTodoList", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)\r
+ @ResponseBody\r
+ public int updateTodoList(@RequestBody TodoListInfo form) {\r
+ return todoHeaderService.updateTodoList(form);\r
+ }\r
}\r
public Integer getMaxId(String headerId) {
return todoHeaderLogic.getMaxId(headerId);
}
+
+ public int createTodoList(TodoListInfo dto) {
+ return todoHeaderLogic.createTodoList(dto);
+ }
+
+ public int deleteTodoList(Integer headerId, Integer id) {
+ return todoHeaderLogic.deleteTodoList(headerId, id);
+ }
+
+ public int updateTodoList(TodoListInfo dto) {
+ return todoHeaderLogic.updateTodoList(dto);
+ }
}