OSDN Git Service

ある程度完成 master
authortkskjri05 <t.kujirai@nagatake.co.jp>
Mon, 3 May 2021 06:09:48 +0000 (15:09 +0900)
committertkskjri05 <t.kujirai@nagatake.co.jp>
Mon, 3 May 2021 06:09:48 +0000 (15:09 +0900)
src/main/java/com/example/logic/TodoLogic.java
src/main/java/com/example/mapper/TodoListMapper.java
src/main/java/com/example/rest/TodoRestController.java
src/main/java/com/example/service/TodoService.java

index 43e10b5..6eb4957 100644 (file)
@@ -66,4 +66,27 @@ public class TodoLogic {
                                .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
index 7246d39..4aaf7c4 100644 (file)
@@ -2,11 +2,14 @@ package com.example.mapper;
 
 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;
 
@@ -48,4 +51,27 @@ public interface TodoListMapper {
        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
index 7c83e59..1afcbbd 100644 (file)
@@ -4,6 +4,7 @@ import java.util.List;
 \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
@@ -45,4 +46,22 @@ public class TodoRestController {
        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
index 4916083..1a6f7e6 100644 (file)
@@ -25,4 +25,16 @@ public class TodoService {
        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);
+       }
 }