From 05ae223b5bf64ecdeaa1c24ffefa600191b2b0ce Mon Sep 17 00:00:00 2001 From: chaaehyun Date: Mon, 20 Jan 2025 17:20:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=8B=A8=EC=9D=BC=20ToDo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/controller/ToDoApiController.java | 36 +++++++- .../controller/dto/ToDoCreateRequest.java | 15 +--- .../controller/dto/ToDoUpdateRequest.java | 51 ++++++++++++ .../official/memento/todo/domain/ToDo.java | 35 ++++++-- .../memento/todo/domain/ToDoRepository.java | 2 + .../official/memento/todo/domain/ToDoTag.java | 30 ++++++- .../todo/domain/ToDoTagRepository.java | 6 ++ .../infrastructure/ToDoRepositoryAdapter.java | 39 ++++++++- .../ToDoTagRepositoryAdapter.java | 42 +++++++++- .../persistence/ToDoEntity.java | 82 ++++++++++++++++++- .../persistence/ToDoTagEntity.java | 47 ++++++++++- .../persistence/ToDoTagJpaRepository.java | 7 ++ .../memento/todo/service/ToDoService.java | 40 ++++++++- .../todo/service/ToDoUpdateUseCase.java | 8 ++ .../service/command/ToDoUpdateCommand.java | 38 +++++++++ 15 files changed, 443 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/official/memento/todo/controller/dto/ToDoUpdateRequest.java create mode 100644 src/main/java/com/official/memento/todo/service/ToDoUpdateUseCase.java create mode 100644 src/main/java/com/official/memento/todo/service/command/ToDoUpdateCommand.java diff --git a/src/main/java/com/official/memento/todo/controller/ToDoApiController.java b/src/main/java/com/official/memento/todo/controller/ToDoApiController.java index f56f019..fc3f8e8 100644 --- a/src/main/java/com/official/memento/todo/controller/ToDoApiController.java +++ b/src/main/java/com/official/memento/todo/controller/ToDoApiController.java @@ -3,13 +3,17 @@ import com.official.memento.global.annotation.Authorization; import com.official.memento.global.annotation.AuthorizationUser; import com.official.memento.global.dto.SuccessResponse; +import com.official.memento.global.entity.enums.RepeatOption; import com.official.memento.schedule.service.command.ScheduleDeleteCommand; import com.official.memento.todo.controller.dto.ToDoCreateRequest; +import com.official.memento.todo.controller.dto.ToDoUpdateRequest; import com.official.memento.todo.domain.ToDo; import com.official.memento.todo.service.ToDoCreateUseCase; import com.official.memento.todo.service.ToDoDeleteUseCase; +import com.official.memento.todo.service.ToDoUpdateUseCase; import com.official.memento.todo.service.command.ToDoCreateCommand; import com.official.memento.todo.service.command.ToDoDeleteCommand; +import com.official.memento.todo.service.command.ToDoUpdateCommand; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -20,13 +24,16 @@ public class ToDoApiController { private final ToDoCreateUseCase toDoCreateUseCase; private final ToDoDeleteUseCase toDoDeleteUseCase; + private final ToDoUpdateUseCase toDoUpdateUseCase; public ToDoApiController( final ToDoCreateUseCase toDoCreateUseCase, - final ToDoDeleteUseCase toDoDeleteUseCase + final ToDoDeleteUseCase toDoDeleteUseCase, + final ToDoUpdateUseCase toDoUpdateUseCase ) { this.toDoCreateUseCase = toDoCreateUseCase; this.toDoDeleteUseCase = toDoDeleteUseCase; + this.toDoUpdateUseCase = toDoUpdateUseCase; } @PostMapping @@ -42,8 +49,8 @@ public ResponseEntity> createToDo( request.date(), request.description(), request.deadline(), - request.repeatOption(), - request.repeatExpiredDate(), + RepeatOption.NONE, + null, request.tagId(), request.priorityUrgency(), request.priorityImportance() @@ -67,4 +74,27 @@ ResponseEntity> deleteToDo( "단일 스케줄 삭제 성공" ); } + + @PatchMapping("/{toDoId}") + ResponseEntity> updateToDo( + //@Authorization final AuthorizationUser authorizationUser, + @PathVariable final long toDoId, + @RequestBody final ToDoUpdateRequest request + ) { + toDoUpdateUseCase.update(ToDoUpdateCommand.of( + 2, + toDoId, + request.date(), + request.description(), + request.deadline(), + request.tagId(), + request.priorityUrgency(), + request.priorityImportance() + )); + return SuccessResponse.of( + HttpStatus.OK, + "단일 스케줄 업데이트 성공" + ); + } + } diff --git a/src/main/java/com/official/memento/todo/controller/dto/ToDoCreateRequest.java b/src/main/java/com/official/memento/todo/controller/dto/ToDoCreateRequest.java index 25313d0..5c001f6 100644 --- a/src/main/java/com/official/memento/todo/controller/dto/ToDoCreateRequest.java +++ b/src/main/java/com/official/memento/todo/controller/dto/ToDoCreateRequest.java @@ -16,10 +16,6 @@ public record ToDoCreateRequest( String description, @Schema(description = "마감 기한", example = "2025-01-25") LocalDate deadline, - @Schema(description = "반복 옵션") - RepeatOption repeatOption, - @Schema(description = "반복 종료 날짜") - LocalDate repeatExpiredDate, @Schema(description = "태그 ID", example = "12345") Long tagId, @Schema(description = "긴급도 우선순위 (0~1)", example = "0.5") @@ -31,13 +27,11 @@ public ToDoCreateRequest( final LocalDate date, final String description, final LocalDate deadline, - final RepeatOption repeatOption, - final LocalDate repeatExpiredDate, final Long tagId, final Double priorityUrgency, final Double priorityImportance ) { - checkNullData(date, description, repeatOption); + checkNullData(date, description); if (description.length() > 30) { throw new IllegalArgumentException("30자 이하로만 작성이 가능합니다."); @@ -46,8 +40,6 @@ public ToDoCreateRequest( this.date = date; this.description = description; this.deadline = deadline; - this.repeatOption = repeatOption; - this.repeatExpiredDate = repeatExpiredDate; this.tagId = tagId; this.priorityUrgency = priorityUrgency; this.priorityImportance = priorityImportance; @@ -55,10 +47,9 @@ public ToDoCreateRequest( private static void checkNullData( final LocalDate date, - final String description, - final RepeatOption repeatOption + final String description ) { - if (date == null || description == null || repeatOption == null) { + if (date == null || description == null) { throw new NullPointException(NULL_DATA_ERROR); } } diff --git a/src/main/java/com/official/memento/todo/controller/dto/ToDoUpdateRequest.java b/src/main/java/com/official/memento/todo/controller/dto/ToDoUpdateRequest.java new file mode 100644 index 0000000..140d06f --- /dev/null +++ b/src/main/java/com/official/memento/todo/controller/dto/ToDoUpdateRequest.java @@ -0,0 +1,51 @@ +package com.official.memento.todo.controller.dto; + +import com.official.memento.global.entity.enums.RepeatOption; +import com.official.memento.global.exception.NullPointException; +import io.swagger.v3.oas.annotations.media.Schema; + +import java.time.LocalDate; + +import static com.official.memento.global.exception.ErrorCode.NULL_DATA_ERROR; + +@Schema(name = " ToDo 수정 요청") +public record ToDoUpdateRequest( + @Schema(description = "수정 ToDo 날짜 (Today or 사용자 지정)", example = "2025-01-20") + LocalDate date, + @Schema(description = "수정 ToDo 내용", maxLength = 30, example = "팀 프로젝트 준비") + String description, + @Schema(description = "수정 마감 기한", example = "2025-01-25") + LocalDate deadline, + @Schema(description = "수정 태그 ID", example = "12345") + Long tagId, + @Schema(description = "수정 긴급도 우선순위 (0~1)", example = "0.5") + Double priorityUrgency, + @Schema(description = "수정 중요도 우선순위 (0~1)", example = "0.5") + Double priorityImportance +) { + public ToDoUpdateRequest of( + final LocalDate date, + final String description, + final LocalDate deadline, + final Long tagId, + final Double priorityUrgency, + final Double priorityImportance + ) { + checkNullData(date, description); + + if (description.length() > 30) { + throw new IllegalArgumentException("30자 이하로만 작성이 가능합니다."); + } + + return new ToDoUpdateRequest(date, description, deadline, tagId, priorityUrgency, priorityImportance); + } + + private static void checkNullData( + final LocalDate date, + final String description + ) { + if (date == null || description == null) { + throw new NullPointException(NULL_DATA_ERROR); + } + } +} diff --git a/src/main/java/com/official/memento/todo/domain/ToDo.java b/src/main/java/com/official/memento/todo/domain/ToDo.java index 2f759c9..a69c61a 100644 --- a/src/main/java/com/official/memento/todo/domain/ToDo.java +++ b/src/main/java/com/official/memento/todo/domain/ToDo.java @@ -1,12 +1,14 @@ package com.official.memento.todo.domain; +import com.official.memento.global.entity.BaseTimeEntity; import com.official.memento.global.entity.enums.RepeatOption; import com.official.memento.todo.domain.enums.PriorityType; import com.official.memento.todo.domain.enums.ToDoType; import java.time.LocalDate; +import java.time.LocalDateTime; -public class ToDo { +public class ToDo extends BaseTimeEntity { private Long id; private long memberId; private String groupId; @@ -36,8 +38,10 @@ private ToDo( final Double priorityImportance, final Double priorityValue, final String priorityType, - final ToDoType type - ) { + final ToDoType type, + final LocalDateTime createdAt, + final LocalDateTime updatedAt + ) { this.id = id; this.memberId = memberId; this.groupId = groupId; @@ -52,6 +56,8 @@ private ToDo( this.priorityValue = priorityValue; this.priorityType = priorityType; this.type = type; + this.createdAt = createdAt; + this.updatedAt = updatedAt; } private ToDo( @@ -98,7 +104,9 @@ public static ToDo withId( final Double priorityImportance, final Double priorityValue, final String priorityType, - final ToDoType type + final ToDoType type, + final LocalDateTime createdAt, + final LocalDateTime updatedAt ) { return new ToDo( id, @@ -114,7 +122,9 @@ public static ToDo withId( priorityImportance, priorityValue, priorityType, - type + type, + createdAt, + updatedAt ); } @@ -150,6 +160,21 @@ public static ToDo of( ); } + public void update( + final LocalDate date, + final String description, + final LocalDate deadline, + final Double priorityUrgency, + final Double priorityImportance + ){ + this.date=date; + this.description=description; + this.deadline=deadline; + this.priorityUrgency = priorityUrgency; + this.priorityImportance=priorityImportance; + + } + public Long getId() { return id; } diff --git a/src/main/java/com/official/memento/todo/domain/ToDoRepository.java b/src/main/java/com/official/memento/todo/domain/ToDoRepository.java index 2ff0513..162d3a4 100644 --- a/src/main/java/com/official/memento/todo/domain/ToDoRepository.java +++ b/src/main/java/com/official/memento/todo/domain/ToDoRepository.java @@ -6,6 +6,8 @@ public interface ToDoRepository { ToDo save(final ToDo toDo); + ToDo update(final ToDo toDo); + ToDo findById(final long toDoId); void deleteById(final long toDoId); diff --git a/src/main/java/com/official/memento/todo/domain/ToDoTag.java b/src/main/java/com/official/memento/todo/domain/ToDoTag.java index 4d1116c..025c204 100644 --- a/src/main/java/com/official/memento/todo/domain/ToDoTag.java +++ b/src/main/java/com/official/memento/todo/domain/ToDoTag.java @@ -1,14 +1,26 @@ package com.official.memento.todo.domain; -public class ToDoTag { +import com.official.memento.global.entity.BaseTimeEntity; + +import java.time.LocalDateTime; + +public class ToDoTag extends BaseTimeEntity { private Long id; private long tagId; private long toDoId; - public ToDoTag(final Long id, final long tagId, final long toDoId) { + public ToDoTag( + final Long id, + final long tagId, + final long toDoId, + final LocalDateTime createdAt, + final LocalDateTime updatedAt + ) { this.id = id; this.tagId = tagId; this.toDoId = toDoId; + this.createdAt = createdAt; + this.updatedAt = updatedAt; } public ToDoTag(final long tagId, final long toDoId) { @@ -19,9 +31,11 @@ public ToDoTag(final long tagId, final long toDoId) { public static ToDoTag withId( final Long id, final long tagId, - final long toDoId + final long toDoId, + final LocalDateTime createdAt, + final LocalDateTime updatedAt ) { - return new ToDoTag(id, tagId, toDoId); + return new ToDoTag(id, tagId, toDoId, createdAt, updatedAt); } public static ToDoTag of( @@ -31,6 +45,14 @@ public static ToDoTag of( return new ToDoTag(tagId, toDoId); } + public void updateTag( + final long tagId, + final LocalDateTime updatedAt + ) { + this.tagId = tagId; + this.updatedAt = updatedAt; + } + public Long getId() { return id; } diff --git a/src/main/java/com/official/memento/todo/domain/ToDoTagRepository.java b/src/main/java/com/official/memento/todo/domain/ToDoTagRepository.java index 387f8e9..6b3f422 100644 --- a/src/main/java/com/official/memento/todo/domain/ToDoTagRepository.java +++ b/src/main/java/com/official/memento/todo/domain/ToDoTagRepository.java @@ -2,4 +2,10 @@ public interface ToDoTagRepository { ToDoTag save(final ToDoTag toDoTag); + + ToDoTag update(final ToDoTag toDoTag); + + ToDoTag findByToDoId(final long toDoId); + + void deleteByToDoId(final long toDoId); } diff --git a/src/main/java/com/official/memento/todo/infrastructure/ToDoRepositoryAdapter.java b/src/main/java/com/official/memento/todo/infrastructure/ToDoRepositoryAdapter.java index 2a69f79..e5e211f 100644 --- a/src/main/java/com/official/memento/todo/infrastructure/ToDoRepositoryAdapter.java +++ b/src/main/java/com/official/memento/todo/infrastructure/ToDoRepositoryAdapter.java @@ -34,7 +34,40 @@ public ToDo save(final ToDo toDo) { toDoEntity.getPriorityImportance(), toDoEntity.getPriorityValue(), toDoEntity.getPriorityType(), - toDoEntity.getType() + toDoEntity.getType(), + toDoEntity.getCreatedAt(), + toDoEntity.getUpdatedAt() + ); + } + + @Override + public ToDo update(final ToDo toDo){ + ToDoEntity toDoEntity = toDoJpaRepository.save(ToDoEntity.withId(toDo)); + toDoEntity.update( + toDo.getDate(), + toDo.getDescription(), + toDo.getDeadline(), + toDo.getPriorityUrgency(), + toDo.getPriorityImportance() + ); + + return ToDo.withId( + toDoEntity.getId(), + toDoEntity.getMemberId(), + toDoEntity.getGroupId(), + toDoEntity.getDate(), + toDoEntity.getDescription(), + toDoEntity.getDeadline(), + toDoEntity.isCompleted(), + toDoEntity.getRepeatOption(), + toDoEntity.getRepeatExpiredDate(), + toDoEntity.getPriorityUrgency(), + toDoEntity.getPriorityImportance(), + toDoEntity.getPriorityValue(), + toDoEntity.getPriorityType(), + toDoEntity.getType(), + toDoEntity.getCreatedAt(), + toDoEntity.getUpdatedAt() ); } @@ -58,7 +91,9 @@ public ToDo findById(long toDoId) { toDoEntity.getPriorityImportance(), toDoEntity.getPriorityValue(), toDoEntity.getPriorityType(), - toDoEntity.getType() + toDoEntity.getType(), + toDoEntity.getCreatedAt(), + toDoEntity.getUpdatedAt() ); } diff --git a/src/main/java/com/official/memento/todo/infrastructure/ToDoTagRepositoryAdapter.java b/src/main/java/com/official/memento/todo/infrastructure/ToDoTagRepositoryAdapter.java index 3ed03eb..494eabf 100644 --- a/src/main/java/com/official/memento/todo/infrastructure/ToDoTagRepositoryAdapter.java +++ b/src/main/java/com/official/memento/todo/infrastructure/ToDoTagRepositoryAdapter.java @@ -4,9 +4,12 @@ import com.official.memento.todo.domain.ToDo; import com.official.memento.todo.domain.ToDoTag; import com.official.memento.todo.domain.ToDoTagRepository; +import com.official.memento.todo.infrastructure.persistence.ToDoEntity; import com.official.memento.todo.infrastructure.persistence.ToDoTagEntity; import com.official.memento.todo.infrastructure.persistence.ToDoTagJpaRepository; +import java.util.Optional; + @Adapter public class ToDoTagRepositoryAdapter implements ToDoTagRepository { @@ -19,10 +22,47 @@ public ToDoTagRepositoryAdapter(ToDoTagJpaRepository toDoTagJpaRepository){ @Override public ToDoTag save(ToDoTag toDoTag){ ToDoTagEntity toDoTagEntity = toDoTagJpaRepository.save(ToDoTagEntity.of(toDoTag)); + return ToDoTag.withId( toDoTagEntity.getId(), toDoTag.getTagId(), - toDoTag.getToDoId() + toDoTag.getToDoId(), + toDoTag.getCreatedAt(), + toDoTag.getUpdatedAt() + ); + } + + @Override + public ToDoTag update(final ToDoTag toDoTag) { + ToDoTagEntity toDoTagEntity = toDoTagJpaRepository.save(ToDoTagEntity.withId(toDoTag)); + toDoTagEntity.updateTag( + toDoTag.getTagId(), + toDoTag.getUpdatedAt() + ); + + return ToDoTag.withId( + toDoTagEntity.getId(), + toDoTagEntity.getTagId(), + toDoTagEntity.getToDoId(), + toDoTagEntity.getCreatedAt(), + toDoTagEntity.getUpdatedAt() ); } + + @Override + public ToDoTag findByToDoId(final long toDoId){ + Optional toDoTagEntity = toDoTagJpaRepository.findByToDoId(toDoId); + return toDoTagEntity.map(toDoTag -> ToDoTag.withId( + toDoTag.getId(), + toDoTag.getTagId(), + toDoTag.getToDoId(), + toDoTag.getCreatedAt(), + toDoTag.getUpdatedAt() + )).orElse(null); + } + + @Override + public void deleteByToDoId(long toDoId){ + toDoTagJpaRepository.deleteByToDoId(toDoId); + } } diff --git a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoEntity.java b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoEntity.java index 253bebb..5665fd9 100644 --- a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoEntity.java +++ b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoEntity.java @@ -37,6 +37,7 @@ protected ToDoEntity(){ } private ToDoEntity( + final long id, final long memberId, final String groupId, final LocalDate date, @@ -49,8 +50,11 @@ private ToDoEntity( final Double priorityImportance, final Double priorityValue, final String priorityType, - final ToDoType type + final ToDoType type, + final LocalDateTime createdAt, + final LocalDateTime updatedAt ) { + this.id=id; this.memberId = memberId; this.groupId = groupId; this.date = date; @@ -64,6 +68,42 @@ private ToDoEntity( this.priorityValue = priorityValue; this.priorityType = priorityType; this.type = type; + this.createdAt=createdAt; + this.updatedAt=updatedAt; + } + + private ToDoEntity( + final long memberId, + final String groupId, + final LocalDate date, + final String description, + final LocalDate deadline, + final boolean isCompleted, + final RepeatOption repeatOption, + final LocalDate repeatExpiredDate, + final Double priorityUrgency, + final Double priorityImportance, + final Double priorityValue, + final String priorityType, + final ToDoType type, + final LocalDateTime createdAt, + final LocalDateTime updatedAt + ){ + this.memberId = memberId; + this.groupId = groupId; + this.date = date; + this.description = description; + this.deadline = deadline; + this.isCompleted = isCompleted; + this.repeatOption = repeatOption; + this.repeatExpiredDate = repeatExpiredDate; + this.priorityUrgency = priorityUrgency; + this.priorityImportance = priorityImportance; + this.priorityValue = priorityValue; + this.priorityType = priorityType; + this.type = type; + this.createdAt=createdAt; + this.updatedAt=updatedAt; } public static ToDoEntity of(final ToDo toDo) { @@ -80,10 +120,48 @@ public static ToDoEntity of(final ToDo toDo) { toDo.getPriorityImportance(), toDo.getPriorityValue(), toDo.getPriorityType(), - toDo.getType() + toDo.getType(), + toDo.getCreatedAt(), + toDo.getUpdatedAt() + ); + } + + public static ToDoEntity withId(final ToDo toDo) { + return new ToDoEntity( + toDo.getId(), + toDo.getMemberId(), + toDo.getGroupId(), + toDo.getDate(), + toDo.getDescription(), + toDo.getDeadline(), + toDo.isCompleted(), + toDo.getRepeatOption(), + toDo.getRepeatExpiredDate(), + toDo.getPriorityUrgency(), + toDo.getPriorityImportance(), + toDo.getPriorityValue(), + toDo.getPriorityType(), + toDo.getType(), + toDo.getCreatedAt(), + toDo.getUpdatedAt() ); } + public void update( + final LocalDate date, + final String description, + final LocalDate deadline, + final Double priorityUrgency, + final Double priorityImportance + ){ + this.date=date; + this.description=description; + this.deadline=deadline; + this.priorityUrgency = priorityUrgency; + this.priorityImportance=priorityImportance; + + } + public Long getId() { return id; } diff --git a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagEntity.java b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagEntity.java index 9efbd8e..eaa23b6 100644 --- a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagEntity.java +++ b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagEntity.java @@ -7,6 +7,9 @@ import com.official.memento.todo.domain.ToDoTag; import jakarta.persistence.*; +import java.time.LocalDate; +import java.time.LocalDateTime; + @Entity @Table(name = "todo_tag") public class ToDoTagEntity extends BaseTimeEntity { @@ -17,20 +20,56 @@ public class ToDoTagEntity extends BaseTimeEntity { private Long tagId; private Long toDoId; - private ToDoTagEntity(final Long id, final Long tagId,final long toDoId){ - this.id=id; + private ToDoTagEntity( + final Long id, + final Long tagId, + final long toDoId, + final LocalDateTime createdAt, + final LocalDateTime updatedAt + ) { + this.id = id; + this.tagId = tagId; + this.toDoId = toDoId; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + private ToDoTagEntity( + final long tagId, + final long toDoId + ) { this.tagId = tagId; this.toDoId = toDoId; } - public static ToDoTagEntity of(final ToDoTag toDoTag){ + protected ToDoTagEntity() { + } + + public static ToDoTagEntity of(final ToDoTag toDoTag) { return new ToDoTagEntity( - toDoTag.getId(), toDoTag.getTagId(), toDoTag.getToDoId() ); } + public static ToDoTagEntity withId(final ToDoTag toDoTag) { + return new ToDoTagEntity( + toDoTag.getId(), + toDoTag.getTagId(), + toDoTag.getToDoId(), + toDoTag.getCreatedAt(), + toDoTag.getUpdatedAt() + ); + } + + public void updateTag( + final long tagId, + final LocalDateTime updatedAt + ) { + this.tagId = tagId; + this.updatedAt = updatedAt; + } + public Long getId() { return id; } diff --git a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagJpaRepository.java b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagJpaRepository.java index 4240780..fc39e0e 100644 --- a/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagJpaRepository.java +++ b/src/main/java/com/official/memento/todo/infrastructure/persistence/ToDoTagJpaRepository.java @@ -1,6 +1,13 @@ package com.official.memento.todo.infrastructure.persistence; +import com.official.memento.tag.infrastructure.persistence.TagEntity; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface ToDoTagJpaRepository extends JpaRepository { + + void deleteByToDoId(final long toDoId); + + Optional findByToDoId(final long toDoId); } diff --git a/src/main/java/com/official/memento/todo/service/ToDoService.java b/src/main/java/com/official/memento/todo/service/ToDoService.java index b65eb7d..c0d676d 100644 --- a/src/main/java/com/official/memento/todo/service/ToDoService.java +++ b/src/main/java/com/official/memento/todo/service/ToDoService.java @@ -1,6 +1,8 @@ package com.official.memento.todo.service; import com.official.memento.global.entity.enums.RepeatOption; +import com.official.memento.schedule.domain.ScheduleTag; +import com.official.memento.tag.domain.Tag; import com.official.memento.tag.domain.TagRepository; import com.official.memento.todo.domain.ToDo; import com.official.memento.todo.domain.ToDoRepository; @@ -9,16 +11,18 @@ import com.official.memento.todo.domain.enums.PriorityType; import com.official.memento.todo.service.command.ToDoCreateCommand; import com.official.memento.todo.service.command.ToDoDeleteCommand; +import com.official.memento.todo.service.command.ToDoUpdateCommand; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.UUID; import static com.official.memento.todo.domain.enums.ToDoType.NORMAL; @Service -public class ToDoService implements ToDoCreateUseCase, ToDoDeleteUseCase { +public class ToDoService implements ToDoCreateUseCase, ToDoDeleteUseCase, ToDoUpdateUseCase { private final ToDoRepository toDoRepository; private final ToDoTagRepository toDoTagRepository; @@ -51,6 +55,24 @@ public void delete(final ToDoDeleteCommand toDoDeleteCommand){ ToDo toDo = toDoRepository.findById(toDoDeleteCommand.toDoId()); checkOwn(toDoDeleteCommand.memberId(),toDo); toDoRepository.deleteById(toDo.getId()); + toDoTagRepository.deleteByToDoId(toDo.getId()); + //TODO 순서 삭제 + } + + @Override + @Transactional + public void update(final ToDoUpdateCommand command){ + ToDo toDo = toDoRepository.findById(command.toDoId()); + checkOwn(command.memberId(), toDo); + toDo.update( + command.date(), + command.description(), + command.deadline(), + command.priorityUrgency(), + command.priorityImportance() + ); + toDoRepository.update(toDo); + updateOrDeleteTag(toDo, command.tagId()); } private void createSingleToDo(final ToDoCreateCommand command, final String toDoGroupId) { @@ -141,8 +163,22 @@ private static void checkOwn(final long memberId, final ToDo toDo) { } } + private void updateOrDeleteTag(final ToDo toDo, final Long tagId) { + ToDoTag toDoTag = toDoTagRepository.findByToDoId(toDo.getId()); + if (tagId == null) { + toDoTagRepository.deleteByToDoId(toDo.getId()); + } else if (toDoTag == null) { + toDoTag = ToDoTag.of(tagId, toDo.getId()); + toDoTagRepository.save(toDoTag); + } else if (toDoTag.getTagId() != tagId) { + toDoTag.updateTag(tagId, LocalDateTime.now()); + toDoTagRepository.update(toDoTag); + } + } + + + //TODO 순서 로직 private int determineOrder() { - // 순서 결정 로직 (예: 기본값은 0, 나중에 수정 가능) return 0; } } diff --git a/src/main/java/com/official/memento/todo/service/ToDoUpdateUseCase.java b/src/main/java/com/official/memento/todo/service/ToDoUpdateUseCase.java new file mode 100644 index 0000000..37f5e83 --- /dev/null +++ b/src/main/java/com/official/memento/todo/service/ToDoUpdateUseCase.java @@ -0,0 +1,8 @@ +package com.official.memento.todo.service; + +import com.official.memento.todo.service.command.ToDoUpdateCommand; + +@FunctionalInterface +public interface ToDoUpdateUseCase { + void update(final ToDoUpdateCommand toDoUpdateCommand); +} diff --git a/src/main/java/com/official/memento/todo/service/command/ToDoUpdateCommand.java b/src/main/java/com/official/memento/todo/service/command/ToDoUpdateCommand.java new file mode 100644 index 0000000..0b92d3d --- /dev/null +++ b/src/main/java/com/official/memento/todo/service/command/ToDoUpdateCommand.java @@ -0,0 +1,38 @@ +package com.official.memento.todo.service.command; + +import com.official.memento.global.entity.enums.RepeatOption; + +import java.time.LocalDate; + +public record ToDoUpdateCommand( + long memberId, + long toDoId, + LocalDate date, + String description, + LocalDate deadline, + Long tagId, + Double priorityUrgency, + Double priorityImportance +) { + public static ToDoUpdateCommand of( + final long memberId, + final long toDoId, + final LocalDate date, + final String description, + final LocalDate deadline, + final Long tagId, + final Double priorityUrgency, + final Double priorityImportance + ) { + return new ToDoUpdateCommand( + memberId, + toDoId, + date, + description, + deadline, + tagId, + priorityUrgency, + priorityImportance + ); + } +} From fa7c75f9dc5b22f9c6891266cf3fe46d4094a4b1 Mon Sep 17 00:00:00 2001 From: chaaehyun Date: Mon, 20 Jan 2025 17:30:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?TODO=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/official/memento/todo/service/ToDoService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/official/memento/todo/service/ToDoService.java b/src/main/java/com/official/memento/todo/service/ToDoService.java index c0d676d..8dec1cc 100644 --- a/src/main/java/com/official/memento/todo/service/ToDoService.java +++ b/src/main/java/com/official/memento/todo/service/ToDoService.java @@ -47,6 +47,7 @@ public void create(final ToDoCreateCommand command) { } else { createRepeatToDos(command, toDoGroupId); } + //TODO 순서 관련 로직 추가 } @Override @@ -56,7 +57,7 @@ public void delete(final ToDoDeleteCommand toDoDeleteCommand){ checkOwn(toDoDeleteCommand.memberId(),toDo); toDoRepository.deleteById(toDo.getId()); toDoTagRepository.deleteByToDoId(toDo.getId()); - //TODO 순서 삭제 + //TODO 순서 관련 로직 삭제 } @Override @@ -73,6 +74,7 @@ public void update(final ToDoUpdateCommand command){ ); toDoRepository.update(toDo); updateOrDeleteTag(toDo, command.tagId()); + //TODO 순서 관련 로직 수정 } private void createSingleToDo(final ToDoCreateCommand command, final String toDoGroupId) {