From 0c21f765c40b6ef7c0d64c36fd0620a869d01a5f Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Thu, 11 Jan 2024 01:41:38 +0900 Subject: [PATCH 01/20] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A4=EC=A7=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/application/todoService.java | 30 +++++++++++++ .../org/idiot/yesslave/todo/domain/todo.java | 42 +++++++++++++++++++ .../todo/repository/todoRepository.java | 7 ++++ .../yesslave/todo/ui/todoController.java | 26 ++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 src/main/java/org/idiot/yesslave/todo/application/todoService.java create mode 100644 src/main/java/org/idiot/yesslave/todo/domain/todo.java create mode 100644 src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java create mode 100644 src/main/java/org/idiot/yesslave/todo/ui/todoController.java diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java new file mode 100644 index 0000000..27f33e0 --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -0,0 +1,30 @@ +package org.idiot.yesslave.todo.application; + +import lombok.RequiredArgsConstructor; +import org.idiot.yesslave.todo.domain.todo; +import org.idiot.yesslave.todo.repository.todoRepository; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.time.LocalDateTime; + +@Service +@RequiredArgsConstructor +@Transactional + +public class todoService { + private final todoRepository todoRepository ; + LocalDateTime time = LocalDateTime.now(); + // 저장 + public void save(String text){ + todoRepository.save(todo.builder() + .todo(text) + .registerDate(time) + .build()); + } + // 수정 + public void update(){} + // 체크박스 true,false + public void changeStatus(){} + +} diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java new file mode 100644 index 0000000..bd25578 --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -0,0 +1,42 @@ +package org.idiot.yesslave.todo.domain; + +import lombok.*; +import javax.persistence.*; +import java.time.LocalDateTime; + +@Entity +@Getter +@AllArgsConstructor +@Table(name = "TODO") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class todo { + + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID", nullable = false) + private Long id; + + @Column(name = "TODO", nullable = false) + private String todo; + + @Column(name = "REGISTER_DATE", nullable = false) + private LocalDateTime registerDate; + + @Column(name = "UPDATE_DATE", nullable = true) + private LocalDateTime updateDate; + + @Column(name = "TODO_CHECK", nullable = false) + private boolean todoCheck = false; + + @Builder + public todo(String todo, LocalDateTime registerDate){ + this.todo = todo; + this.registerDate = registerDate; + } + public void changeCheck(boolean todoCheck){ + this.todoCheck = todoCheck; + } + + +} \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java b/src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java new file mode 100644 index 0000000..92a45fd --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java @@ -0,0 +1,7 @@ +package org.idiot.yesslave.todo.repository; + +import org.idiot.yesslave.todo.domain.todo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface todoRepository extends JpaRepository{ +} diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java new file mode 100644 index 0000000..a9578de --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -0,0 +1,26 @@ +package org.idiot.yesslave.todo.ui; + +import lombok.RequiredArgsConstructor; +import org.idiot.yesslave.todo.application.todoService; +import org.springframework.http.ResponseEntity; +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; + +import java.net.URI; + +@RestController +@RequestMapping("/todo") +@RequiredArgsConstructor +public class todoController { + + private final todoService todoService; + + @PostMapping() + public ResponseEntity todoSave(@RequestBody String text){ + todoService.save(text); + return ResponseEntity.created(URI.create("/todo")).build(); + } + +} From 777c053973953ea26afc570fcefdbae48571c492 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Thu, 11 Jan 2024 13:11:46 +0900 Subject: [PATCH 02/20] =?UTF-8?q?refactor:=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20Dto=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yesslave/todo/application/todoService.java | 5 +++-- .../java/org/idiot/yesslave/todo/dto/saveDto.java | 14 ++++++++++++++ .../org/idiot/yesslave/todo/ui/todoController.java | 5 +++-- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/idiot/yesslave/todo/dto/saveDto.java diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index 27f33e0..546f90e 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.idiot.yesslave.todo.domain.todo; +import org.idiot.yesslave.todo.dto.saveDto; import org.idiot.yesslave.todo.repository.todoRepository; import org.springframework.stereotype.Service; @@ -16,9 +17,9 @@ public class todoService { private final todoRepository todoRepository ; LocalDateTime time = LocalDateTime.now(); // 저장 - public void save(String text){ + public void save(saveDto saveDto){ todoRepository.save(todo.builder() - .todo(text) + .todo(saveDto.getTodo()) .registerDate(time) .build()); } diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java new file mode 100644 index 0000000..7fa981a --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java @@ -0,0 +1,14 @@ +package org.idiot.yesslave.todo.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class saveDto { + private String todo; + + @Builder + public saveDto(String todo){ + this.todo = todo; + } +} diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index a9578de..4070efe 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.idiot.yesslave.todo.application.todoService; +import org.idiot.yesslave.todo.dto.saveDto; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -18,8 +19,8 @@ public class todoController { private final todoService todoService; @PostMapping() - public ResponseEntity todoSave(@RequestBody String text){ - todoService.save(text); + public ResponseEntity todoSave(@RequestBody saveDto saveDto){ + todoService.save(saveDto); return ResponseEntity.created(URI.create("/todo")).build(); } From 7d1b5a9f9a58f284e85a6a5024b8c66859efd80e Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Thu, 11 Jan 2024 21:55:45 +0900 Subject: [PATCH 03/20] =?UTF-8?q?refactor:=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B4=80=EB=A0=A8=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/idiot/yesslave/todo/application/todoService.java | 4 +++- src/main/java/org/idiot/yesslave/todo/domain/todo.java | 2 ++ src/main/java/org/idiot/yesslave/todo/dto/saveDto.java | 3 +++ src/main/java/org/idiot/yesslave/todo/ui/todoController.java | 5 +++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index 546f90e..5684d35 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -15,7 +15,7 @@ public class todoService { private final todoRepository todoRepository ; - LocalDateTime time = LocalDateTime.now(); + private LocalDateTime time = LocalDateTime.now(); // 저장 public void save(saveDto saveDto){ todoRepository.save(todo.builder() @@ -23,6 +23,8 @@ public void save(saveDto saveDto){ .registerDate(time) .build()); } + + // 수정 public void update(){} // 체크박스 true,false diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index bd25578..f7d15a4 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -34,6 +34,8 @@ public todo(String todo, LocalDateTime registerDate){ this.todo = todo; this.registerDate = registerDate; } + + public void changeCheck(boolean todoCheck){ this.todoCheck = todoCheck; } diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java index 7fa981a..c60897f 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java @@ -1,9 +1,12 @@ package org.idiot.yesslave.todo.dto; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class saveDto { private String todo; diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index 4070efe..1690c57 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -18,10 +18,11 @@ public class todoController { private final todoService todoService; - @PostMapping() - public ResponseEntity todoSave(@RequestBody saveDto saveDto){ + @PostMapping + public ResponseEntity todoSave(@RequestBody saveDto saveDto){ todoService.save(saveDto); return ResponseEntity.created(URI.create("/todo")).build(); + } } From 492408351e2efddcc7617d33243ea170045f3ed3 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Thu, 11 Jan 2024 22:20:53 +0900 Subject: [PATCH 04/20] =?UTF-8?q?refactor:=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B4=80=EB=A0=A8=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/idiot/yesslave/todo/application/todoService.java | 1 + src/main/java/org/idiot/yesslave/todo/domain/todo.java | 2 -- src/main/java/org/idiot/yesslave/todo/dto/saveDto.java | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index 5684d35..c43ad65 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -27,6 +27,7 @@ public void save(saveDto saveDto){ // 수정 public void update(){} + // 체크박스 true,false public void changeStatus(){} diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index f7d15a4..ffd3b09 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -6,12 +6,10 @@ @Entity @Getter -@AllArgsConstructor @Table(name = "TODO") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class todo { - @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID", nullable = false) diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java index c60897f..138ebce 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java @@ -7,10 +7,10 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) +// cannot deserialize from Object value (no delegate- or property-based Creator)에러로 인해 기본 생성자 필요 public class saveDto { private String todo; - @Builder public saveDto(String todo){ this.todo = todo; } From bdc8fdda56d9220cfda6111822525c1a3b01a508 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Fri, 12 Jan 2024 00:28:48 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A4=EC=A7=90=20=EC=88=98=EC=A0=95=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/BusinessExceptionHandler.java | 13 ++++++++ .../yesslave/global/exception/errorCode.java | 17 ++++++++++ .../todo/application/todoService.java | 31 ++++++++++++++++--- .../org/idiot/yesslave/todo/domain/todo.java | 9 ++++++ .../idiot/yesslave/todo/dto/updateDto.java | 16 ++++++++++ .../yesslave/todo/ui/todoController.java | 11 ++++--- 6 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java create mode 100644 src/main/java/org/idiot/yesslave/global/exception/errorCode.java create mode 100644 src/main/java/org/idiot/yesslave/todo/dto/updateDto.java diff --git a/src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java b/src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java new file mode 100644 index 0000000..886a9fc --- /dev/null +++ b/src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java @@ -0,0 +1,13 @@ +package org.idiot.yesslave.global.exception; + +import lombok.Getter; + +public class BusinessExceptionHandler extends RuntimeException{ + @Getter + private final errorCode errorCode; + + public BusinessExceptionHandler(errorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } +} \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/global/exception/errorCode.java b/src/main/java/org/idiot/yesslave/global/exception/errorCode.java new file mode 100644 index 0000000..ddef081 --- /dev/null +++ b/src/main/java/org/idiot/yesslave/global/exception/errorCode.java @@ -0,0 +1,17 @@ +package org.idiot.yesslave.global.exception; + +import lombok.Getter; + +public enum errorCode { + ID_NOT_FOUND("해당 ID를 찾을 수 없습니다."), + ID_DELETE("삭제된 ID입니다."); + + + + @Getter + private String message; + + errorCode(String message) { + this.message = message; + } +} \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index c43ad65..8372e8b 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -1,13 +1,17 @@ package org.idiot.yesslave.todo.application; import lombok.RequiredArgsConstructor; +import org.idiot.yesslave.global.exception.BusinessExceptionHandler; +import org.idiot.yesslave.global.exception.errorCode; import org.idiot.yesslave.todo.domain.todo; import org.idiot.yesslave.todo.dto.saveDto; +import org.idiot.yesslave.todo.dto.updateDto; import org.idiot.yesslave.todo.repository.todoRepository; import org.springframework.stereotype.Service; import javax.transaction.Transactional; import java.time.LocalDateTime; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -15,20 +19,39 @@ public class todoService { private final todoRepository todoRepository ; - private LocalDateTime time = LocalDateTime.now(); + // 저장 public void save(saveDto saveDto){ todoRepository.save(todo.builder() .todo(saveDto.getTodo()) - .registerDate(time) + .registerDate(time()) .build()); } // 수정 - public void update(){} - + public void update(Long id, updateDto updateDto){ + todo todo = existId(id); + deleteStatus(todo); + todo.update(updateDto.getTodo(), time()); + } + // 체크박스 true,false public void changeStatus(){} + private static void deleteStatus(todo todo) { + if (todo.isDelete()) throw new BusinessExceptionHandler(errorCode.ID_DELETE); + } + public todo existId(Long id) { + Optional op = todoRepository.findById(id); + todo todo = op.orElseThrow(() -> new BusinessExceptionHandler(errorCode.ID_NOT_FOUND)); + return todo; + } + private LocalDateTime time (){ + LocalDateTime time = LocalDateTime.now(); + return time; + } + + + } diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index ffd3b09..8698bba 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -27,6 +27,10 @@ public class todo { @Column(name = "TODO_CHECK", nullable = false) private boolean todoCheck = false; + @Column(name = "delete", nullable = false) + private boolean delete = false; + + @Builder public todo(String todo, LocalDateTime registerDate){ this.todo = todo; @@ -38,5 +42,10 @@ public void changeCheck(boolean todoCheck){ this.todoCheck = todoCheck; } + public void update(String todo, LocalDateTime updateDate){ + this.todo = todo; + this.updateDate = updateDate; + } + } \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java b/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java new file mode 100644 index 0000000..3524c67 --- /dev/null +++ b/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java @@ -0,0 +1,16 @@ +package org.idiot.yesslave.todo.dto; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) + +public class updateDto { + private String todo; + + public updateDto(String todo){ + this.todo = todo; + } +} diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index 1690c57..a3e7dc2 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -3,11 +3,9 @@ import lombok.RequiredArgsConstructor; import org.idiot.yesslave.todo.application.todoService; import org.idiot.yesslave.todo.dto.saveDto; +import org.idiot.yesslave.todo.dto.updateDto; import org.springframework.http.ResponseEntity; -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; +import org.springframework.web.bind.annotation.*; import java.net.URI; @@ -22,7 +20,12 @@ public class todoController { public ResponseEntity todoSave(@RequestBody saveDto saveDto){ todoService.save(saveDto); return ResponseEntity.created(URI.create("/todo")).build(); + } + @PatchMapping("/{id}") + public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody updateDto updateDto){ + todoService.update(id, updateDto); + return ResponseEntity.ok("Todo updated successfully"); } } From dabe9443d3bf941d56898a3b8ebcd0c45428a39e Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Fri, 12 Jan 2024 00:37:22 +0900 Subject: [PATCH 06/20] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A4=EC=A7=90=20=EC=88=98=ED=96=89=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/idiot/yesslave/todo/application/todoService.java | 6 +++++- .../java/org/idiot/yesslave/todo/ui/todoController.java | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index 8372e8b..bb96110 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -37,7 +37,11 @@ public void update(Long id, updateDto updateDto){ } // 체크박스 true,false - public void changeStatus(){} + public void changeCheck(Long id){ + todo todo = existId(id); + deleteStatus(todo); + todo.changeCheck(!todo.isTodoCheck()); + } private static void deleteStatus(todo todo) { if (todo.isDelete()) throw new BusinessExceptionHandler(errorCode.ID_DELETE); diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index a3e7dc2..40cd691 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -28,4 +28,12 @@ public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody updateDto u return ResponseEntity.ok("Todo updated successfully"); } + @PostMapping("/{id}") + public ResponseEntity changeCheck(@PathVariable Long id){ + todoService.changeCheck(id); + return ResponseEntity.ok("Todo change successfully"); + } + + + } From b1ec9c35f1efe8efeb129670d214dede2c62068b Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Fri, 12 Jan 2024 00:45:58 +0900 Subject: [PATCH 07/20] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A4=EC=A7=90=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/idiot/yesslave/todo/application/todoService.java | 6 ++++++ src/main/java/org/idiot/yesslave/todo/domain/todo.java | 4 +++- .../java/org/idiot/yesslave/todo/ui/todoController.java | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index bb96110..9ee3d3c 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -43,6 +43,12 @@ public void changeCheck(Long id){ todo.changeCheck(!todo.isTodoCheck()); } + public void delete(Long id){ + todo todo = existId(id); + deleteStatus(todo); + todo.delete(true); + } + private static void deleteStatus(todo todo) { if (todo.isDelete()) throw new BusinessExceptionHandler(errorCode.ID_DELETE); } diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index 8698bba..ddb0939 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -46,6 +46,8 @@ public void update(String todo, LocalDateTime updateDate){ this.todo = todo; this.updateDate = updateDate; } - + public void delete (boolean delete){ + this.delete = delete; + } } \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index 40cd691..4e9387d 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -34,6 +34,10 @@ public ResponseEntity changeCheck(@PathVariable Long id){ return ResponseEntity.ok("Todo change successfully"); } - + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable Long id){ + todoService.delete(id); + return ResponseEntity.ok("Todo delete successfully"); + } } From 5a7c0fb3df2b078e332a42fe3f8c3d0651013b58 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Fri, 12 Jan 2024 15:29:47 +0900 Subject: [PATCH 08/20] =?UTF-8?q?refactor:=20Controller=EC=9D=98=20todoSav?= =?UTF-8?q?e=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yesslave/todo/application/todoService.java | 18 +++++++++++------- .../org/idiot/yesslave/todo/domain/todo.java | 10 +++++----- .../org/idiot/yesslave/todo/dto/saveDto.java | 3 ++- .../org/idiot/yesslave/todo/dto/updateDto.java | 3 +-- .../idiot/yesslave/todo/ui/todoController.java | 10 +++++----- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/todoService.java index 9ee3d3c..2041eda 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/todoService.java @@ -16,48 +16,52 @@ @Service @RequiredArgsConstructor @Transactional - public class todoService { private final todoRepository todoRepository ; // 저장 - public void save(saveDto saveDto){ + public void save(saveDto saveDto) { todoRepository.save(todo.builder() .todo(saveDto.getTodo()) .registerDate(time()) .build()); } - // 수정 - public void update(Long id, updateDto updateDto){ + public void update(Long id, updateDto updateDto) { todo todo = existId(id); deleteStatus(todo); todo.update(updateDto.getTodo(), time()); } // 체크박스 true,false - public void changeCheck(Long id){ + public void changeCheck(Long id) { todo todo = existId(id); deleteStatus(todo); todo.changeCheck(!todo.isTodoCheck()); } - public void delete(Long id){ + // 논리적 삭제 + public void delete(Long id) { todo todo = existId(id); deleteStatus(todo); todo.delete(true); } + // 삭제 상태 확인 private static void deleteStatus(todo todo) { if (todo.isDelete()) throw new BusinessExceptionHandler(errorCode.ID_DELETE); } + + //id 존재 확인 public todo existId(Long id) { Optional op = todoRepository.findById(id); todo todo = op.orElseThrow(() -> new BusinessExceptionHandler(errorCode.ID_NOT_FOUND)); return todo; } - private LocalDateTime time (){ + + //시간 갱신 + private LocalDateTime time() { LocalDateTime time = LocalDateTime.now(); return time; } diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index ddb0939..d2eb33b 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -11,7 +11,7 @@ public class todo { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", nullable = false) private Long id; @@ -32,21 +32,21 @@ public class todo { @Builder - public todo(String todo, LocalDateTime registerDate){ + public todo(String todo, LocalDateTime registerDate) { this.todo = todo; this.registerDate = registerDate; } - public void changeCheck(boolean todoCheck){ + public void changeCheck(boolean todoCheck) { this.todoCheck = todoCheck; } - public void update(String todo, LocalDateTime updateDate){ + public void update(String todo, LocalDateTime updateDate) { this.todo = todo; this.updateDate = updateDate; } - public void delete (boolean delete){ + public void delete (boolean delete) { this.delete = delete; } diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java index 138ebce..d9f9ed5 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java @@ -11,7 +11,8 @@ public class saveDto { private String todo; - public saveDto(String todo){ + public saveDto(String todo) { this.todo = todo; } + } diff --git a/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java b/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java index 3524c67..3e23572 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java @@ -6,11 +6,10 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) - public class updateDto { private String todo; - public updateDto(String todo){ + public updateDto(String todo) { this.todo = todo; } } diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java index 4e9387d..5870c15 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/todoController.java @@ -17,25 +17,25 @@ public class todoController { private final todoService todoService; @PostMapping - public ResponseEntity todoSave(@RequestBody saveDto saveDto){ + public ResponseEntity todoSave(@RequestBody saveDto saveDto) { todoService.save(saveDto); - return ResponseEntity.created(URI.create("/todo")).build(); + return ResponseEntity.ok("Todo save successfully"); } @PatchMapping("/{id}") - public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody updateDto updateDto){ + public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody updateDto updateDto) { todoService.update(id, updateDto); return ResponseEntity.ok("Todo updated successfully"); } @PostMapping("/{id}") - public ResponseEntity changeCheck(@PathVariable Long id){ + public ResponseEntity changeCheck(@PathVariable Long id) { todoService.changeCheck(id); return ResponseEntity.ok("Todo change successfully"); } @DeleteMapping("/{id}") - public ResponseEntity delete(@PathVariable Long id){ + public ResponseEntity delete(@PathVariable Long id) { todoService.delete(id); return ResponseEntity.ok("Todo delete successfully"); } From 0a7a116684c0b67c5002ae729965f7626ecad8af Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sat, 13 Jan 2024 00:05:35 +0900 Subject: [PATCH 09/20] =?UTF-8?q?feat:=20todoController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/idiot/yesslave/todo/dto/saveDto.java | 2 +- .../yesslave/todo/ui/todoControllerTest.java | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java index d9f9ed5..4415b10 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java @@ -10,7 +10,7 @@ // cannot deserialize from Object value (no delegate- or property-based Creator)에러로 인해 기본 생성자 필요 public class saveDto { private String todo; - + @Builder public saveDto(String todo) { this.todo = todo; } diff --git a/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java b/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java new file mode 100644 index 0000000..a9821d0 --- /dev/null +++ b/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java @@ -0,0 +1,135 @@ +package org.idiot.yesslave.todo.ui; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.assertj.core.api.Assertions; +import org.idiot.yesslave.todo.domain.todo; +import org.idiot.yesslave.todo.dto.saveDto; +import org.idiot.yesslave.todo.repository.todoRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import java.time.LocalDateTime; + + +@SpringBootTest +@AutoConfigureMockMvc +public class todoControllerTest { + @Autowired + ObjectMapper mapper; + + @Autowired + MockMvc mvc; + + @Autowired + private todoRepository todoRepository; + + private static final String BASE_URL = "/todo"; + + @Test + @DisplayName("저장 테스트") + void save_test() throws Exception { + //given + String text = "Test schedule"; + + //when + String body = mapper.writeValueAsString( + saveDto.builder() + .todo(text) + .build() + ); + + //then + mvc.perform(post(BASE_URL) + .content(body) //HTTP Body에 데이터를 담는다 + .contentType(MediaType.APPLICATION_JSON) //보내는 데이터의 타입을 명시 + ) + .andExpect(status().isOk()) + .andExpect(content().string("Todo save successfully")); + } + + @Test + @DisplayName("수정 테스트") + void patch_test() throws Exception { + + //given + String text = "Test schedule"; + String change_text = "Change test schedule"; + LocalDateTime time = LocalDateTime.now(); + + //when + todoRepository.save(todo.builder() + .todo(text) + .registerDate(time) + .build()); + + String body = mapper.writeValueAsString( + saveDto.builder() + .todo(change_text) + .build() + ); + + //then + mvc.perform(patch(BASE_URL + "/1") + .contentType(MediaType.APPLICATION_JSON) + .content(body) + ) + .andExpect(status().isOk()) + .andExpect(content().string("Todo updated successfully")); + + } + + @Test + @DisplayName("체크 변경 테스트") + void change_check_test() throws Exception { + + //given + String text = "Test schedule"; + LocalDateTime time = LocalDateTime.now(); + + //when + todoRepository.save(todo.builder() + .todo(text) + .registerDate(time) + .build()); + + //then + mvc.perform(post(BASE_URL + "/1") + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(content().string("Todo change successfully")); + + } + + @DisplayName("삭제 테스트") + @Test + public void delete_Test() throws Exception { + + //given + String text = "Test schedule"; + LocalDateTime time = LocalDateTime.now(); + + //when + todoRepository.save(todo.builder() + .todo(text) + .registerDate(time) + .build()); + + //then + mvc.perform(delete(BASE_URL + "/1")) + .andExpect(status().isOk()) + .andExpect(content().string("Todo delete successfully")); + + Assertions.assertThat(todoRepository.findById(1L).isEmpty()); + } +} From a9bd5eac28ddd2be5083b5fc23b2472e92a09268 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sat, 13 Jan 2024 00:33:31 +0900 Subject: [PATCH 10/20] =?UTF-8?q?refactor:=20todoController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/idiot/yesslave/todo/ui/todoControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java b/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java index a9821d0..cf213c6 100644 --- a/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java +++ b/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java @@ -79,7 +79,7 @@ void patch_test() throws Exception { ); //then - mvc.perform(patch(BASE_URL + "/1") + mvc.perform(patch(BASE_URL + "/2") .contentType(MediaType.APPLICATION_JSON) .content(body) ) From c55dc0d97fe9649e727c44b1be35b3141377db72 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sun, 14 Jan 2024 16:33:12 +0900 Subject: [PATCH 11/20] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=AA=85=20=EC=8B=9C=EC=9E=91=20=EB=8C=80=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{todoService.java => TodoService.java} | 14 +++++++------- .../todo/dto/{saveDto.java => SaveDto.java} | 4 ++-- .../todo/dto/{updateDto.java => UpdateDto.java} | 4 ++-- .../{todoRepository.java => TodoRepository.java} | 2 +- .../{todoController.java => TodoController.java} | 16 +++++++--------- ...ntrollerTest.java => TodoControllerTest.java} | 14 +++++++------- 6 files changed, 26 insertions(+), 28 deletions(-) rename src/main/java/org/idiot/yesslave/todo/application/{todoService.java => TodoService.java} (83%) rename src/main/java/org/idiot/yesslave/todo/dto/{saveDto.java => SaveDto.java} (87%) rename src/main/java/org/idiot/yesslave/todo/dto/{updateDto.java => UpdateDto.java} (79%) rename src/main/java/org/idiot/yesslave/todo/repository/{todoRepository.java => TodoRepository.java} (70%) rename src/main/java/org/idiot/yesslave/todo/ui/{todoController.java => TodoController.java} (73%) rename src/test/java/org/idiot/yesslave/todo/ui/{todoControllerTest.java => TodoControllerTest.java} (92%) diff --git a/src/main/java/org/idiot/yesslave/todo/application/todoService.java b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java similarity index 83% rename from src/main/java/org/idiot/yesslave/todo/application/todoService.java rename to src/main/java/org/idiot/yesslave/todo/application/TodoService.java index 2041eda..6c926d4 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/todoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java @@ -4,9 +4,9 @@ import org.idiot.yesslave.global.exception.BusinessExceptionHandler; import org.idiot.yesslave.global.exception.errorCode; import org.idiot.yesslave.todo.domain.todo; -import org.idiot.yesslave.todo.dto.saveDto; -import org.idiot.yesslave.todo.dto.updateDto; -import org.idiot.yesslave.todo.repository.todoRepository; +import org.idiot.yesslave.todo.dto.SaveDto; +import org.idiot.yesslave.todo.dto.UpdateDto; +import org.idiot.yesslave.todo.repository.TodoRepository; import org.springframework.stereotype.Service; import javax.transaction.Transactional; @@ -16,11 +16,11 @@ @Service @RequiredArgsConstructor @Transactional -public class todoService { - private final todoRepository todoRepository ; +public class TodoService { + private final TodoRepository todoRepository ; // 저장 - public void save(saveDto saveDto) { + public void save(SaveDto saveDto) { todoRepository.save(todo.builder() .todo(saveDto.getTodo()) .registerDate(time()) @@ -28,7 +28,7 @@ public void save(saveDto saveDto) { } // 수정 - public void update(Long id, updateDto updateDto) { + public void update(Long id, UpdateDto updateDto) { todo todo = existId(id); deleteStatus(todo); todo.update(updateDto.getTodo(), time()); diff --git a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java b/src/main/java/org/idiot/yesslave/todo/dto/SaveDto.java similarity index 87% rename from src/main/java/org/idiot/yesslave/todo/dto/saveDto.java rename to src/main/java/org/idiot/yesslave/todo/dto/SaveDto.java index 4415b10..125f9fb 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/saveDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/SaveDto.java @@ -8,10 +8,10 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) // cannot deserialize from Object value (no delegate- or property-based Creator)에러로 인해 기본 생성자 필요 -public class saveDto { +public class SaveDto { private String todo; @Builder - public saveDto(String todo) { + public SaveDto(String todo) { this.todo = todo; } diff --git a/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java b/src/main/java/org/idiot/yesslave/todo/dto/UpdateDto.java similarity index 79% rename from src/main/java/org/idiot/yesslave/todo/dto/updateDto.java rename to src/main/java/org/idiot/yesslave/todo/dto/UpdateDto.java index 3e23572..a6bfa95 100644 --- a/src/main/java/org/idiot/yesslave/todo/dto/updateDto.java +++ b/src/main/java/org/idiot/yesslave/todo/dto/UpdateDto.java @@ -6,10 +6,10 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class updateDto { +public class UpdateDto { private String todo; - public updateDto(String todo) { + public UpdateDto(String todo) { this.todo = todo; } } diff --git a/src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java b/src/main/java/org/idiot/yesslave/todo/repository/TodoRepository.java similarity index 70% rename from src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java rename to src/main/java/org/idiot/yesslave/todo/repository/TodoRepository.java index 92a45fd..9c296b3 100644 --- a/src/main/java/org/idiot/yesslave/todo/repository/todoRepository.java +++ b/src/main/java/org/idiot/yesslave/todo/repository/TodoRepository.java @@ -3,5 +3,5 @@ import org.idiot.yesslave.todo.domain.todo; import org.springframework.data.jpa.repository.JpaRepository; -public interface todoRepository extends JpaRepository{ +public interface TodoRepository extends JpaRepository{ } diff --git a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java b/src/main/java/org/idiot/yesslave/todo/ui/TodoController.java similarity index 73% rename from src/main/java/org/idiot/yesslave/todo/ui/todoController.java rename to src/main/java/org/idiot/yesslave/todo/ui/TodoController.java index 5870c15..2e9117c 100644 --- a/src/main/java/org/idiot/yesslave/todo/ui/todoController.java +++ b/src/main/java/org/idiot/yesslave/todo/ui/TodoController.java @@ -1,29 +1,27 @@ package org.idiot.yesslave.todo.ui; import lombok.RequiredArgsConstructor; -import org.idiot.yesslave.todo.application.todoService; -import org.idiot.yesslave.todo.dto.saveDto; -import org.idiot.yesslave.todo.dto.updateDto; +import org.idiot.yesslave.todo.application.TodoService; +import org.idiot.yesslave.todo.dto.SaveDto; +import org.idiot.yesslave.todo.dto.UpdateDto; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.net.URI; - @RestController @RequestMapping("/todo") @RequiredArgsConstructor -public class todoController { +public class TodoController { - private final todoService todoService; + private final TodoService todoService; @PostMapping - public ResponseEntity todoSave(@RequestBody saveDto saveDto) { + public ResponseEntity todoSave(@RequestBody SaveDto saveDto) { todoService.save(saveDto); return ResponseEntity.ok("Todo save successfully"); } @PatchMapping("/{id}") - public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody updateDto updateDto) { + public ResponseEntity todoUpdate(@PathVariable Long id, @RequestBody UpdateDto updateDto) { todoService.update(id, updateDto); return ResponseEntity.ok("Todo updated successfully"); } diff --git a/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java similarity index 92% rename from src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java rename to src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java index cf213c6..d11c599 100644 --- a/src/test/java/org/idiot/yesslave/todo/ui/todoControllerTest.java +++ b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java @@ -8,8 +8,8 @@ import org.assertj.core.api.Assertions; import org.idiot.yesslave.todo.domain.todo; -import org.idiot.yesslave.todo.dto.saveDto; -import org.idiot.yesslave.todo.repository.todoRepository; +import org.idiot.yesslave.todo.dto.SaveDto; +import org.idiot.yesslave.todo.repository.TodoRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +23,7 @@ @SpringBootTest @AutoConfigureMockMvc -public class todoControllerTest { +public class TodoControllerTest { @Autowired ObjectMapper mapper; @@ -31,7 +31,7 @@ public class todoControllerTest { MockMvc mvc; @Autowired - private todoRepository todoRepository; + private TodoRepository todoRepository; private static final String BASE_URL = "/todo"; @@ -43,7 +43,7 @@ void save_test() throws Exception { //when String body = mapper.writeValueAsString( - saveDto.builder() + SaveDto.builder() .todo(text) .build() ); @@ -73,7 +73,7 @@ void patch_test() throws Exception { .build()); String body = mapper.writeValueAsString( - saveDto.builder() + SaveDto.builder() .todo(change_text) .build() ); @@ -103,7 +103,7 @@ void change_check_test() throws Exception { .build()); //then - mvc.perform(post(BASE_URL + "/1") + mvc.perform(post(BASE_URL + "/2") .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) From 9053905f2837fc34412e34a7eb7910e555395b05 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sun, 14 Jan 2024 17:48:16 +0900 Subject: [PATCH 12/20] =?UTF-8?q?refactor:=20BusinessExceptionHandler?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/{errorCode.java => ErrorCode.java} | 4 ++-- .../{BusinessExceptionHandler.java => TodoIdHandler.java} | 6 +++--- .../org/idiot/yesslave/todo/application/TodoService.java | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/org/idiot/yesslave/global/exception/{errorCode.java => ErrorCode.java} (81%) rename src/main/java/org/idiot/yesslave/global/exception/{BusinessExceptionHandler.java => TodoIdHandler.java} (50%) diff --git a/src/main/java/org/idiot/yesslave/global/exception/errorCode.java b/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java similarity index 81% rename from src/main/java/org/idiot/yesslave/global/exception/errorCode.java rename to src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java index ddef081..501c311 100644 --- a/src/main/java/org/idiot/yesslave/global/exception/errorCode.java +++ b/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java @@ -2,7 +2,7 @@ import lombok.Getter; -public enum errorCode { +public enum ErrorCode { ID_NOT_FOUND("해당 ID를 찾을 수 없습니다."), ID_DELETE("삭제된 ID입니다."); @@ -11,7 +11,7 @@ public enum errorCode { @Getter private String message; - errorCode(String message) { + ErrorCode(String message) { this.message = message; } } \ No newline at end of file diff --git a/src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java b/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java similarity index 50% rename from src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java rename to src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java index 886a9fc..0a1eeec 100644 --- a/src/main/java/org/idiot/yesslave/global/exception/BusinessExceptionHandler.java +++ b/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java @@ -2,11 +2,11 @@ import lombok.Getter; -public class BusinessExceptionHandler extends RuntimeException{ +public class TodoIdHandler extends RuntimeException { @Getter - private final errorCode errorCode; + private final ErrorCode errorCode; - public BusinessExceptionHandler(errorCode errorCode) { + public TodoIdHandler(ErrorCode errorCode) { super(errorCode.getMessage()); this.errorCode = errorCode; } diff --git a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java index 6c926d4..b64471c 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java @@ -1,8 +1,8 @@ package org.idiot.yesslave.todo.application; import lombok.RequiredArgsConstructor; -import org.idiot.yesslave.global.exception.BusinessExceptionHandler; -import org.idiot.yesslave.global.exception.errorCode; +import org.idiot.yesslave.global.exception.TodoIdHandler; +import org.idiot.yesslave.global.exception.ErrorCode; import org.idiot.yesslave.todo.domain.todo; import org.idiot.yesslave.todo.dto.SaveDto; import org.idiot.yesslave.todo.dto.UpdateDto; @@ -50,13 +50,13 @@ public void delete(Long id) { // 삭제 상태 확인 private static void deleteStatus(todo todo) { - if (todo.isDelete()) throw new BusinessExceptionHandler(errorCode.ID_DELETE); + if (todo.isDelete()) throw new TodoIdHandler(ErrorCode.ID_DELETE); } //id 존재 확인 public todo existId(Long id) { Optional op = todoRepository.findById(id); - todo todo = op.orElseThrow(() -> new BusinessExceptionHandler(errorCode.ID_NOT_FOUND)); + todo todo = op.orElseThrow(() -> new TodoIdHandler(ErrorCode.ID_NOT_FOUND)); return todo; } From 618bd23595d12d312dd21a0e5e9a935ed79514f5 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sun, 14 Jan 2024 18:41:51 +0900 Subject: [PATCH 13/20] =?UTF-8?q?refactor:=20TodoService=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/application/TodoService.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java index b64471c..82d5635 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java @@ -11,7 +11,6 @@ import javax.transaction.Transactional; import java.time.LocalDateTime; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -19,7 +18,6 @@ public class TodoService { private final TodoRepository todoRepository ; - // 저장 public void save(SaveDto saveDto) { todoRepository.save(todo.builder() .todo(saveDto.getTodo()) @@ -27,40 +25,36 @@ public void save(SaveDto saveDto) { .build()); } - // 수정 public void update(Long id, UpdateDto updateDto) { todo todo = existId(id); - deleteStatus(todo); + checkDeleteStatus(todo); todo.update(updateDto.getTodo(), time()); } - // 체크박스 true,false public void changeCheck(Long id) { todo todo = existId(id); - deleteStatus(todo); + checkDeleteStatus(todo); todo.changeCheck(!todo.isTodoCheck()); } - // 논리적 삭제 public void delete(Long id) { todo todo = existId(id); - deleteStatus(todo); + checkDeleteStatus(todo); todo.delete(true); } - // 삭제 상태 확인 - private static void deleteStatus(todo todo) { - if (todo.isDelete()) throw new TodoIdHandler(ErrorCode.ID_DELETE); + private void checkDeleteStatus(todo todo) { + if (todo.isDelete()) { + throw new TodoIdHandler(ErrorCode.ID_DELETE); + } } - //id 존재 확인 public todo existId(Long id) { - Optional op = todoRepository.findById(id); - todo todo = op.orElseThrow(() -> new TodoIdHandler(ErrorCode.ID_NOT_FOUND)); + todo todo = todoRepository.findById(id) + .orElseThrow(() -> new TodoIdHandler(ErrorCode.ID_NOT_FOUND)); return todo; } - //시간 갱신 private LocalDateTime time() { LocalDateTime time = LocalDateTime.now(); return time; From fe43643322ec82ac24fdca490093fd9d81ad0c16 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Sun, 14 Jan 2024 19:01:57 +0900 Subject: [PATCH 14/20] =?UTF-8?q?refactor:=20TodoService=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/idiot/yesslave/todo/application/TodoService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java index 82d5635..1b12766 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java @@ -14,7 +14,7 @@ @Service @RequiredArgsConstructor -@Transactional + public class TodoService { private final TodoRepository todoRepository ; @@ -24,7 +24,7 @@ public void save(SaveDto saveDto) { .registerDate(time()) .build()); } - + @Transactional public void update(Long id, UpdateDto updateDto) { todo todo = existId(id); checkDeleteStatus(todo); From 0d3a612c183e89010d82bdbdcb1be3ec18598599 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Mon, 15 Jan 2024 01:31:12 +0900 Subject: [PATCH 15/20] =?UTF-8?q?refactor:=20todo=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idiot/yesslave/YesSlaveApplication.java | 2 ++ .../todo/application/TodoService.java | 16 ++++------- .../org/idiot/yesslave/todo/domain/todo.java | 27 +++++++++---------- .../yesslave/todo/ui/TodoControllerTest.java | 5 ---- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/YesSlaveApplication.java b/src/main/java/org/idiot/yesslave/YesSlaveApplication.java index 45ef084..f784cb7 100644 --- a/src/main/java/org/idiot/yesslave/YesSlaveApplication.java +++ b/src/main/java/org/idiot/yesslave/YesSlaveApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class YesSlaveApplication { diff --git a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java index 1b12766..6b71bcf 100644 --- a/src/main/java/org/idiot/yesslave/todo/application/TodoService.java +++ b/src/main/java/org/idiot/yesslave/todo/application/TodoService.java @@ -10,33 +10,34 @@ import org.springframework.stereotype.Service; import javax.transaction.Transactional; -import java.time.LocalDateTime; @Service @RequiredArgsConstructor - public class TodoService { private final TodoRepository todoRepository ; + @Transactional public void save(SaveDto saveDto) { todoRepository.save(todo.builder() .todo(saveDto.getTodo()) - .registerDate(time()) .build()); } + @Transactional public void update(Long id, UpdateDto updateDto) { todo todo = existId(id); checkDeleteStatus(todo); - todo.update(updateDto.getTodo(), time()); + todo.update(updateDto.getTodo()); } + @Transactional public void changeCheck(Long id) { todo todo = existId(id); checkDeleteStatus(todo); todo.changeCheck(!todo.isTodoCheck()); } + @Transactional public void delete(Long id) { todo todo = existId(id); checkDeleteStatus(todo); @@ -55,11 +56,4 @@ public todo existId(Long id) { return todo; } - private LocalDateTime time() { - LocalDateTime time = LocalDateTime.now(); - return time; - } - - - } diff --git a/src/main/java/org/idiot/yesslave/todo/domain/todo.java b/src/main/java/org/idiot/yesslave/todo/domain/todo.java index d2eb33b..c43b8db 100644 --- a/src/main/java/org/idiot/yesslave/todo/domain/todo.java +++ b/src/main/java/org/idiot/yesslave/todo/domain/todo.java @@ -1,40 +1,40 @@ package org.idiot.yesslave.todo.domain; import lombok.*; +import org.hibernate.annotations.Comment; +import org.idiot.yesslave.global.jpa.AuditInformation; + import javax.persistence.*; -import java.time.LocalDateTime; + @Entity @Getter @Table(name = "TODO") @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class todo { +public class todo extends AuditInformation { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", nullable = false) + @Comment("id는 todo 테이블의 pk 값 입니다") private Long id; @Column(name = "TODO", nullable = false) + @Comment("todo는 오늘의 다짐을 적는 부분입니다.") private String todo; - @Column(name = "REGISTER_DATE", nullable = false) - private LocalDateTime registerDate; - - @Column(name = "UPDATE_DATE", nullable = true) - private LocalDateTime updateDate; - @Column(name = "TODO_CHECK", nullable = false) + @Comment("todoCheck는 실행 여부를 체크하는 부분입니다.") private boolean todoCheck = false; - @Column(name = "delete", nullable = false) + @Column(name = "DELETE", nullable = false) + @Comment("delete는 삭제 여부를 체크하는 부분입니다.") private boolean delete = false; @Builder - public todo(String todo, LocalDateTime registerDate) { + public todo(String todo) { this.todo = todo; - this.registerDate = registerDate; } @@ -42,12 +42,11 @@ public void changeCheck(boolean todoCheck) { this.todoCheck = todoCheck; } - public void update(String todo, LocalDateTime updateDate) { + public void update(String todo) { this.todo = todo; - this.updateDate = updateDate; } public void delete (boolean delete) { this.delete = delete; } -} \ No newline at end of file +} diff --git a/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java index d11c599..06a2d35 100644 --- a/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java +++ b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java @@ -64,12 +64,10 @@ void patch_test() throws Exception { //given String text = "Test schedule"; String change_text = "Change test schedule"; - LocalDateTime time = LocalDateTime.now(); //when todoRepository.save(todo.builder() .todo(text) - .registerDate(time) .build()); String body = mapper.writeValueAsString( @@ -94,12 +92,10 @@ void change_check_test() throws Exception { //given String text = "Test schedule"; - LocalDateTime time = LocalDateTime.now(); //when todoRepository.save(todo.builder() .todo(text) - .registerDate(time) .build()); //then @@ -122,7 +118,6 @@ public void delete_Test() throws Exception { //when todoRepository.save(todo.builder() .todo(text) - .registerDate(time) .build()); //then From 6bceafcfb19675d11f691e334267d17dd9fe7aca Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Mon, 15 Jan 2024 01:34:45 +0900 Subject: [PATCH 16/20] =?UTF-8?q?refactor:=20TodoIdHandler=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/idiot/yesslave/global/exception/ErrorCode.java | 4 +--- .../org/idiot/yesslave/global/exception/TodoIdHandler.java | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java b/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java index 501c311..cc5ac7e 100644 --- a/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java +++ b/src/main/java/org/idiot/yesslave/global/exception/ErrorCode.java @@ -6,12 +6,10 @@ public enum ErrorCode { ID_NOT_FOUND("해당 ID를 찾을 수 없습니다."), ID_DELETE("삭제된 ID입니다."); - - @Getter private String message; ErrorCode(String message) { this.message = message; } -} \ No newline at end of file +} diff --git a/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java b/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java index 0a1eeec..5510988 100644 --- a/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java +++ b/src/main/java/org/idiot/yesslave/global/exception/TodoIdHandler.java @@ -3,6 +3,7 @@ import lombok.Getter; public class TodoIdHandler extends RuntimeException { + @Getter private final ErrorCode errorCode; @@ -10,4 +11,4 @@ public TodoIdHandler(ErrorCode errorCode) { super(errorCode.getMessage()); this.errorCode = errorCode; } -} \ No newline at end of file +} From d573d353ccfa47e52c26d1cf2e39b8a0ea77c519 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Tue, 16 Jan 2024 22:06:16 +0900 Subject: [PATCH 17/20] =?UTF-8?q?refactor:=20yml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f3f9fb7..369a30b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,4 +20,5 @@ spring: add-mappings: false mvc: throw-exception-if-no-handler-found: true - \ No newline at end of file + main: + allow-bean-definition-overriding: true From 4d3188befa5fe4a4de7812e9ebc91a7ecf269858 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Tue, 16 Jan 2024 23:08:12 +0900 Subject: [PATCH 18/20] =?UTF-8?q?refactor:=20TodoControllerTest=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 4 ++-- .../java/org/idiot/yesslave/todo/ui/TodoControllerTest.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 369a30b..b95d115 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,5 +20,5 @@ spring: add-mappings: false mvc: throw-exception-if-no-handler-found: true - main: - allow-bean-definition-overriding: true + + diff --git a/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java index 06a2d35..b7fce2b 100644 --- a/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java +++ b/src/test/java/org/idiot/yesslave/todo/ui/TodoControllerTest.java @@ -113,7 +113,6 @@ public void delete_Test() throws Exception { //given String text = "Test schedule"; - LocalDateTime time = LocalDateTime.now(); //when todoRepository.save(todo.builder() From b483b3a695cc13394d290ba5802ef053f0d23514 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Tue, 16 Jan 2024 23:24:17 +0900 Subject: [PATCH 19/20] =?UTF-8?q?refactor:=20yml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b95d115..e6034a2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,5 +20,6 @@ spring: add-mappings: false mvc: throw-exception-if-no-handler-found: true - + main: + allow-bean-definition-overriding: true From 703ae3ee4737c4772a670d201cece51bc37fd3b5 Mon Sep 17 00:00:00 2001 From: jucheolkang Date: Tue, 16 Jan 2024 23:46:35 +0900 Subject: [PATCH 20/20] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idiot/yesslave/worktimer/ui/WorkTimerControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/idiot/yesslave/worktimer/ui/WorkTimerControllerTest.java b/src/test/java/org/idiot/yesslave/worktimer/ui/WorkTimerControllerTest.java index 9082829..8d8274a 100644 --- a/src/test/java/org/idiot/yesslave/worktimer/ui/WorkTimerControllerTest.java +++ b/src/test/java/org/idiot/yesslave/worktimer/ui/WorkTimerControllerTest.java @@ -29,7 +29,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -@WebMvcTest +@WebMvcTest(WorkTimerController.class) @ExtendWith(SpringExtension.class) class WorkTimerControllerTest {