From 5aee7c611ad040f0018ae8762a8bc2f66eae7969 Mon Sep 17 00:00:00 2001 From: chaaehyun Date: Fri, 6 Jun 2025 19:09:17 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[FIX]=20=ED=83=9C=EA=B7=B8=20GET=20API=20?= =?UTF-8?q?=EC=8B=9C,=20=ED=83=9C=EA=B7=B8=20id=20=EC=98=A4=EB=A6=84?= =?UTF-8?q?=EC=B0=A8=EC=88=9C=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/official/memento/tag/domain/TagRepository.java | 2 +- .../memento/tag/infrastructure/TagRepositoryAdapter.java | 4 ++-- .../tag/infrastructure/persistence/TagJpaRepository.java | 4 ++-- .../java/com/official/memento/tag/service/TagService.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/official/memento/tag/domain/TagRepository.java b/src/main/java/com/official/memento/tag/domain/TagRepository.java index 084130c..4bfa9e9 100644 --- a/src/main/java/com/official/memento/tag/domain/TagRepository.java +++ b/src/main/java/com/official/memento/tag/domain/TagRepository.java @@ -15,7 +15,7 @@ public interface TagRepository { Tag findById(final Long id); - List findAllByMemberId(final Long memberId); + List findAllByMemberIdOrderById(final Long memberId); Tag findByMemberIdAndTagColor(final Long memberId, final TagColor tagColor); diff --git a/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java b/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java index 25e9ea6..6b66549 100644 --- a/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java +++ b/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java @@ -71,8 +71,8 @@ public Tag findById(Long id) { } @Override - public List findAllByMemberId(Long memberId) { - return tagJpaRepository.findAllByMemberId(memberId) + public List findAllByMemberIdOrderById(Long memberId) { + return tagJpaRepository.findAllByMemberIdOrderById(memberId) .stream() .map(entity -> Tag.withId( entity.getId(), diff --git a/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java b/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java index 642de5c..e9f80d4 100644 --- a/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java +++ b/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java @@ -9,10 +9,10 @@ public interface TagJpaRepository extends JpaRepository { @Query( - value = "SELECT * FROM tag WHERE member_id = :memberId", + value = "SELECT * FROM tag WHERE member_id = :memberId ORDER BY id ASC", nativeQuery = true ) - List findAllByMemberId(Long memberId); + List findAllByMemberIdOrderById(Long memberId); Optional findByMemberIdAndColor(Long memberId, TagColor color); diff --git a/src/main/java/com/official/memento/tag/service/TagService.java b/src/main/java/com/official/memento/tag/service/TagService.java index 1e36751..32a86fa 100644 --- a/src/main/java/com/official/memento/tag/service/TagService.java +++ b/src/main/java/com/official/memento/tag/service/TagService.java @@ -74,7 +74,7 @@ private void validateNotDefaultTag(final Tag tag) { @Transactional(readOnly = true) @Override public List getTags(final long memberId) { - return tagRepository.findAllByMemberId(memberId); + return tagRepository.findAllByMemberIdOrderById(memberId); } @Transactional(readOnly = true) From 0287e50a32db8162f11bc31f5b4535e89ced5ade Mon Sep 17 00:00:00 2001 From: chaaehyun Date: Fri, 6 Jun 2025 19:18:51 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[FIX]=20=ED=83=9C=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=8B=9C,=20=EC=9A=94=EC=B2=AD=20=EA=B0=92=20hexCo?= =?UTF-8?q?de=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/official/memento/tag/controller/TagApiController.java | 4 ++-- .../official/memento/tag/controller/dto/TagUpdateRequest.java | 4 ++-- .../memento/tag/service/command/TagUpdateCommand.java | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/official/memento/tag/controller/TagApiController.java b/src/main/java/com/official/memento/tag/controller/TagApiController.java index 4073211..9c5341d 100644 --- a/src/main/java/com/official/memento/tag/controller/TagApiController.java +++ b/src/main/java/com/official/memento/tag/controller/TagApiController.java @@ -72,10 +72,10 @@ public ResponseEntity> updateTag( @PathVariable final long tagId, @RequestBody final TagUpdateRequest tagUpdateRequest ) { - tagUpdateUseCase.update(TagUpdateCommand.of( + tagUpdateUseCase.update(TagUpdateCommand.updateWithHexColor( authorizationUser.memberId(), tagId, - tagUpdateRequest.color(), + tagUpdateRequest.hexCode(), tagUpdateRequest.name() )); return SuccessResponse.of( diff --git a/src/main/java/com/official/memento/tag/controller/dto/TagUpdateRequest.java b/src/main/java/com/official/memento/tag/controller/dto/TagUpdateRequest.java index 7cef9a0..7567ba7 100644 --- a/src/main/java/com/official/memento/tag/controller/dto/TagUpdateRequest.java +++ b/src/main/java/com/official/memento/tag/controller/dto/TagUpdateRequest.java @@ -7,7 +7,7 @@ public record TagUpdateRequest( @Schema(description = "태그 이름") String name, - @Schema(description = "태그 색상") - TagColor color + @Schema(description = "태그 색상 헥스코드") + String hexCode ) { } diff --git a/src/main/java/com/official/memento/tag/service/command/TagUpdateCommand.java b/src/main/java/com/official/memento/tag/service/command/TagUpdateCommand.java index b5a4c40..acaddc6 100644 --- a/src/main/java/com/official/memento/tag/service/command/TagUpdateCommand.java +++ b/src/main/java/com/official/memento/tag/service/command/TagUpdateCommand.java @@ -16,4 +16,8 @@ public static TagUpdateCommand of( ) { return new TagUpdateCommand(memberId, tagId, color, name); } + + public static TagUpdateCommand updateWithHexColor(Long memberId, Long tagId, String colorHex, String name) { + return new TagUpdateCommand(memberId, tagId, TagColor.fromHex(colorHex), name); + } } From 6e7e8c1d202c17e4a7d0d778f7088e48fb3f2bb6 Mon Sep 17 00:00:00 2001 From: chaaehyun Date: Fri, 6 Jun 2025 19:46:34 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[FIX]=20=ED=83=9C=EA=B7=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=88=98=EC=A0=95=20API=20=EC=8B=9C,=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=9D=B4=EB=A6=84=20=EC=A0=9C=ED=95=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/official/memento/tag/domain/TagRepository.java | 2 ++ .../memento/tag/infrastructure/TagRepositoryAdapter.java | 5 +++++ .../tag/infrastructure/persistence/TagJpaRepository.java | 2 ++ .../java/com/official/memento/tag/service/TagService.java | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/src/main/java/com/official/memento/tag/domain/TagRepository.java b/src/main/java/com/official/memento/tag/domain/TagRepository.java index 4bfa9e9..b29c10a 100644 --- a/src/main/java/com/official/memento/tag/domain/TagRepository.java +++ b/src/main/java/com/official/memento/tag/domain/TagRepository.java @@ -20,4 +20,6 @@ public interface TagRepository { Tag findByMemberIdAndTagColor(final Long memberId, final TagColor tagColor); Tag findDefaultTag(final Long memberId); + + boolean existsByMemberIdAndName(final Long memberId, final String name); } diff --git a/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java b/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java index 6b66549..c9b730a 100644 --- a/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java +++ b/src/main/java/com/official/memento/tag/infrastructure/TagRepositoryAdapter.java @@ -106,4 +106,9 @@ public Tag findDefaultTag(final Long memberId){ entity.getMemberId() ); } + + @Override + public boolean existsByMemberIdAndName(Long memberId, String name) { + return tagJpaRepository.existsByMemberIdAndName(memberId, name); + } } diff --git a/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java b/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java index e9f80d4..327b2e6 100644 --- a/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java +++ b/src/main/java/com/official/memento/tag/infrastructure/persistence/TagJpaRepository.java @@ -23,4 +23,6 @@ public interface TagJpaRepository extends JpaRepository { Optional findDefaultTag(Long memberId); void deleteAllByMemberId(final long memberId); + + boolean existsByMemberIdAndName(Long memberId, String name); } diff --git a/src/main/java/com/official/memento/tag/service/TagService.java b/src/main/java/com/official/memento/tag/service/TagService.java index 32a86fa..f52bb26 100644 --- a/src/main/java/com/official/memento/tag/service/TagService.java +++ b/src/main/java/com/official/memento/tag/service/TagService.java @@ -27,6 +27,7 @@ public class TagService implements TagCreateUseCase, TagGetUseCase, TagUpdateUse @Override @Transactional public Tag create(final TagCreateCommand command) { + validateDuplicateTagName(command.memberId(), command.name()); final Tag tag = Tag.of(command.name(), command.color(), command.memberId()); return tagRepository.save(tag); } @@ -36,6 +37,7 @@ public Tag create(final TagCreateCommand command) { public void update(final TagUpdateCommand command) { Tag tag = tagRepository.findById(command.tagId()); tag.checkOwn(command.memberId()); + validateDuplicateTagName(command.memberId(), command.name()); tag = tag.update( command.name(), @@ -71,6 +73,12 @@ private void validateNotDefaultTag(final Tag tag) { } } + private void validateDuplicateTagName(Long memberId, String name) { + if (tagRepository.existsByMemberIdAndName(memberId, name)) { + throw new InvalidRequestBodyException(ErrorCode.INVALID_JSON_FORMAT); + } + } + @Transactional(readOnly = true) @Override public List getTags(final long memberId) {