From 2e8b8bc6f5e3be62b2ccbfe98534572869176efb Mon Sep 17 00:00:00 2001 From: Leafguyk Date: Fri, 10 Jan 2025 19:27:55 +0900 Subject: [PATCH 1/5] Tag Exception Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - TagExceptions에서 에러코드 수정 - TagController에서 ErrorHandler 지움 --- .../memoWithTags/exception/TagExceptions.kt | 4 ++-- .../memoWithTags/tag/controller/TagController.kt | 11 ----------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/TagExceptions.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/TagExceptions.kt index e1d6af9..598c38c 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/TagExceptions.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/TagExceptions.kt @@ -9,6 +9,6 @@ class TagNotFoundException : CustomException( ) class WrongUserException : CustomException( errorCode = 0, - httpErrorCode = HttpStatus.UNAUTHORIZED, - msg = "토큰이 만료되었습니다." + httpErrorCode = HttpStatus.FORBIDDEN, + msg = "유저가 가지고 있는 태그가 아닙니다." ) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt index c0b3c13..452989c 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt @@ -40,17 +40,6 @@ class TagController( tagService.deleteTag(tagId, user) return ResponseEntity.noContent().build() } - - @ExceptionHandler - fun handleTagNotFoundException(e: Exception): ResponseEntity { - val status = when (e) { - is TagNotFoundException -> 404 - is WrongUserException -> 403 - is AuthenticationFailedException -> 401 - else -> 404 - } - return ResponseEntity.status(status).build() - } } data class CreateTagRequest( From 04eb403c8489887818d732cd94b6d555d1738f7d Mon Sep 17 00:00:00 2001 From: Leafguyk Date: Fri, 10 Jan 2025 19:31:05 +0900 Subject: [PATCH 2/5] ktlint fix --- .../toyproject/memoWithTags/tag/controller/TagController.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt index 452989c..f6ce070 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/TagController.kt @@ -1,13 +1,9 @@ package com.wafflestudio.toyproject.memoWithTags.tag.controller -import com.wafflestudio.toyproject.memoWithTags.exception.AuthenticationFailedException -import com.wafflestudio.toyproject.memoWithTags.exception.TagNotFoundException -import com.wafflestudio.toyproject.memoWithTags.exception.WrongUserException import com.wafflestudio.toyproject.memoWithTags.tag.service.TagService import com.wafflestudio.toyproject.memoWithTags.user.AuthUser import com.wafflestudio.toyproject.memoWithTags.user.contoller.User import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping From f93bc70233c8a299b7f093ca1469f3c44f2e9dbc Mon Sep 17 00:00:00 2001 From: Leafguyk Date: Fri, 31 Jan 2025 18:26:08 +0900 Subject: [PATCH 3/5] added createdAt & updatedAt field to UpdateRequest --- .../toyproject/memoWithTags/tag/dto/TagRequest.kt | 4 +++- .../toyproject/memoWithTags/tag/service/TagService.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt index 209aeeb..cfc29d5 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt @@ -17,6 +17,8 @@ sealed class TagRequest { val id: UUID, val name: String, val colorHex: String, - val embeddingVector: List + val embeddingVector: List, + val createdAt: Instant, + val updatedAt: Instant? ) : TagResponse() } diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt index dc71b94..fe4fa7e 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt @@ -53,7 +53,7 @@ class TagService( tagEntity.name = request.name tagEntity.colorHex = request.colorHex tagEntity.embeddingVector = Tag.convertEmbeddingVectorToString(request.embeddingVector) - tagEntity.updatedAt = Instant.now() + tagEntity.updatedAt = request.updatedAt val savedTagEntity = tagRepository.save(tagEntity) return Tag( savedTagEntity.id, From da620334a96f8c9a282f5ddaedf10c6b172cb922 Mon Sep 17 00:00:00 2001 From: Leafguyk Date: Fri, 31 Jan 2025 18:31:55 +0900 Subject: [PATCH 4/5] ktlint --- .../toyproject/memoWithTags/tag/service/TagService.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt index fe4fa7e..9877173 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt @@ -11,7 +11,6 @@ import com.wafflestudio.toyproject.memoWithTags.tag.persistence.TagRepository import com.wafflestudio.toyproject.memoWithTags.user.controller.User import com.wafflestudio.toyproject.memoWithTags.user.persistence.UserRepository import org.springframework.stereotype.Service -import java.time.Instant import java.util.UUID @Service From 0985e69e60b679b6eb3bfe871adabe7dc2f00b3b Mon Sep 17 00:00:00 2001 From: Leafguyk Date: Fri, 31 Jan 2025 20:53:02 +0900 Subject: [PATCH 5/5] Tag embeddingVector Converter fix --- .../toyproject/memoWithTags/tag/controller/Tag.kt | 10 ++-------- .../toyproject/memoWithTags/tag/dto/TagRequest.kt | 4 ++-- .../memoWithTags/tag/persistence/TagEntity.kt | 7 +++++-- .../toyproject/memoWithTags/tag/service/TagService.kt | 10 +++++----- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/Tag.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/Tag.kt index 867d408..4331456 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/Tag.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/controller/Tag.kt @@ -8,7 +8,7 @@ data class Tag( val id: UUID, val name: String, val colorHex: String, - val embeddingVector: List, + val embeddingVector: List, val createdAt: Instant, val updatedAt: Instant? ) { @@ -18,16 +18,10 @@ data class Tag( id = entity.id, name = entity.name, colorHex = entity.colorHex, - embeddingVector = convertStringToEmbeddingVector(entity.embeddingVector), + embeddingVector = entity.embeddingVector, createdAt = entity.createdAt, updatedAt = entity.updatedAt ) } - fun convertEmbeddingVectorToString(embeddingVector: List): String { - return embeddingVector.joinToString(",") - } - fun convertStringToEmbeddingVector(embeddingVector: String): List { - return embeddingVector.split(",").map { it.toFloat() } - } } } diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt index cfc29d5..80a4074 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/dto/TagRequest.kt @@ -8,7 +8,7 @@ sealed class TagRequest { val id: UUID, val name: String, val colorHex: String, - val embeddingVector: List, + val embeddingVector: List, val createdAt: Instant, val updatedAt: Instant? ) : TagRequest() @@ -17,7 +17,7 @@ sealed class TagRequest { val id: UUID, val name: String, val colorHex: String, - val embeddingVector: List, + val embeddingVector: List, val createdAt: Instant, val updatedAt: Instant? ) : TagResponse() diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/persistence/TagEntity.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/persistence/TagEntity.kt index 880f31f..fbadaa2 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/persistence/TagEntity.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/persistence/TagEntity.kt @@ -1,9 +1,11 @@ package com.wafflestudio.toyproject.memoWithTags.tag.persistence +import com.wafflestudio.toyproject.memoWithTags.memo.persistence.EmbeddingVectorConverter import com.wafflestudio.toyproject.memoWithTags.memo.persistence.MemoTagEntity import com.wafflestudio.toyproject.memoWithTags.user.persistence.UserEntity import jakarta.persistence.CascadeType import jakarta.persistence.Column +import jakarta.persistence.Convert import jakarta.persistence.Entity import jakarta.persistence.Id import jakarta.persistence.JoinColumn @@ -23,8 +25,9 @@ class TagEntity( @Column(name = "color", nullable = false) var colorHex: String, - @Column(name = "embedding_vector", nullable = false) - var embeddingVector: String, + @Convert(converter = EmbeddingVectorConverter::class) + @Column(columnDefinition = "TEXT") + var embeddingVector: List = emptyList(), @ManyToOne @JoinColumn(name = "user_id") diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt index 9877173..ce791fe 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/tag/service/TagService.kt @@ -19,7 +19,7 @@ class TagService( private val userRepository: UserRepository ) { fun getTags(user: User): List { - return tagRepository.findByUserId(user.id).map { Tag(it.id, it.name, it.colorHex, Tag.convertStringToEmbeddingVector(it.embeddingVector), it.createdAt, it.updatedAt) } + return tagRepository.findByUserId(user.id).map { Tag(it.id, it.name, it.colorHex, it.embeddingVector, it.createdAt, it.updatedAt) } } fun createTag(request: CreateTagRequest, user: User): Tag { @@ -28,7 +28,7 @@ class TagService( id = request.id, name = request.name, colorHex = request.colorHex, - embeddingVector = Tag.convertEmbeddingVectorToString(request.embeddingVector), + embeddingVector = request.embeddingVector, createdAt = request.createdAt, updatedAt = request.updatedAt, user = userEntity @@ -38,7 +38,7 @@ class TagService( savedTagEntity.id, savedTagEntity.name, savedTagEntity.colorHex, - Tag.convertStringToEmbeddingVector(savedTagEntity.embeddingVector), + savedTagEntity.embeddingVector, savedTagEntity.createdAt, savedTagEntity.updatedAt ) @@ -51,14 +51,14 @@ class TagService( } tagEntity.name = request.name tagEntity.colorHex = request.colorHex - tagEntity.embeddingVector = Tag.convertEmbeddingVectorToString(request.embeddingVector) + tagEntity.embeddingVector = request.embeddingVector tagEntity.updatedAt = request.updatedAt val savedTagEntity = tagRepository.save(tagEntity) return Tag( savedTagEntity.id, savedTagEntity.name, savedTagEntity.colorHex, - Tag.convertStringToEmbeddingVector(savedTagEntity.embeddingVector), + savedTagEntity.embeddingVector, savedTagEntity.createdAt, savedTagEntity.updatedAt )