From a1e1956b698f722d9cfc7f1b2c3feec3083d251e Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 12:56:59 +0900 Subject: [PATCH 01/12] =?UTF-8?q?refactor=20:=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/org/grida/domain/image/Image.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/image/Image.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/image/Image.kt index 0c8daa6f..b5602739 100644 --- a/grida-core/core-domain/src/main/kotlin/org/grida/domain/image/Image.kt +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/image/Image.kt @@ -6,12 +6,4 @@ data class Image( val url: String, val status: ImageStatus = ImageStatus.ACTIVATE, val timestamp: Timestamp = Timestamp() -) { - fun activate(): Image { - return Image(this.url, ImageStatus.ACTIVATE) - } - - fun deactivate(): Image { - return Image(this.url, ImageStatus.DEACTIVATE) - } -} +) From 891975ecae277c0511cd2315b67de7ad35ed50e6 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 13:00:24 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat=20:=20diaryImage=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/org/grida/domain/diaryimage/DiaryImage.kt | 10 ++++++++++ .../grida/domain/diaryimage/DiaryImageRepository.kt | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImage.kt create mode 100644 grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageRepository.kt diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImage.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImage.kt new file mode 100644 index 00000000..55f48a1a --- /dev/null +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImage.kt @@ -0,0 +1,10 @@ +package org.grida.domain.diaryimage + +import org.grida.domain.image.Image + +data class DiaryImage( + val id: Long = 0, + val userId: Long, + val diaryId: Long, + val image: Image +) diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageRepository.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageRepository.kt new file mode 100644 index 00000000..8157809c --- /dev/null +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageRepository.kt @@ -0,0 +1,8 @@ +package org.grida.domain.diaryimage + +import org.grida.domain.diary.Diary +import org.grida.domain.user.User + +interface DiaryImageRepository { + fun save(diaryImage: DiaryImage, diary: Diary, user: User): Long +} \ No newline at end of file From a2633a166b789cb2fccb5ff6cd4c70fc422c80b9 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 13:00:41 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat=20:=20diaryImage=20jpa=20entity=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diaryimage/DiaryImageEntity.kt | 42 +++++++++++++++++++ .../diaryimage/DiaryImageEntityRepository.kt | 30 +++++++++++++ .../diaryimage/DiaryImageMapper.kt | 32 ++++++++++++++ .../diaryimage/DiaryJpaEntityRepository.kt | 6 +++ 4 files changed, 110 insertions(+) create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt new file mode 100644 index 00000000..1644cbdc --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt @@ -0,0 +1,42 @@ +package org.grida.persistence.diaryimage + +import org.grida.domain.diaryimage.DiaryImage +import org.grida.domain.image.ImageStatus +import org.grida.persistence.base.BaseEntity +import org.grida.persistence.diary.DiaryEntity +import org.grida.persistence.user.UserEntity +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.EnumType +import javax.persistence.Enumerated +import javax.persistence.FetchType +import javax.persistence.GeneratedValue +import javax.persistence.GenerationType +import javax.persistence.Id +import javax.persistence.JoinColumn +import javax.persistence.ManyToOne +import javax.persistence.Table + +@Entity +@Table(name = "diary-image") +class DiaryImageEntity( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "diary_id") + val id: Long, + + @Column(length = 511) + var imageUrl: String, + + @Enumerated(EnumType.STRING) + @Column(length = 127) + var status: ImageStatus, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + var user: UserEntity, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "diary_id") + var diary: DiaryEntity, +) : BaseEntity() \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt new file mode 100644 index 00000000..5311e348 --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt @@ -0,0 +1,30 @@ +package org.grida.persistence.diaryimage + +import org.grida.domain.diary.Diary +import org.grida.domain.diaryimage.DiaryImage +import org.grida.domain.diaryimage.DiaryImageRepository +import org.grida.domain.user.User +import org.grida.persistence.diary.DiaryEntity +import org.grida.persistence.user.UserEntity +import org.springframework.stereotype.Repository +import org.springframework.transaction.annotation.Transactional + +@Repository +@Transactional(readOnly = true) +class DiaryImageEntityRepository( + private val diaryImageJpaEntityRepository: DiaryJpaEntityRepository +) : DiaryImageRepository { + + override fun save( + diaryImage: DiaryImage, + diary: Diary, + user: User + ): Long { + val diaryEntity = diaryImage.toEntity( + UserEntity.from(user), + DiaryEntity.from(diary, user) + ) + diaryImageJpaEntityRepository.save(diaryEntity) + return diaryEntity.id + } +} \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt new file mode 100644 index 00000000..3a67657f --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt @@ -0,0 +1,32 @@ +package org.grida.persistence.diaryimage + +import org.grida.domain.diaryimage.DiaryImage +import org.grida.domain.image.Image +import org.grida.persistence.diary.DiaryEntity +import org.grida.persistence.user.UserEntity + +fun DiaryImage.toEntity( + userEntity: UserEntity, + diaryEntity: DiaryEntity +): DiaryImageEntity { + return DiaryImageEntity( + id = this.id, + imageUrl = this.image.url, + status = this.image.status, + user = userEntity, + diary = diaryEntity + ) +} + +fun DiaryImageEntity.toDomain(): DiaryImage { + return DiaryImage( + id = this.id, + userId = this.user.id, + diaryId = this.diary.id, + image = Image( + url = imageUrl, + status = this.status, + timestamp = this.toTimeStamp() + ) + ) +} \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt new file mode 100644 index 00000000..f8760185 --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt @@ -0,0 +1,6 @@ +package org.grida.persistence.diaryimage + +import org.springframework.data.jpa.repository.JpaRepository + +interface DiaryJpaEntityRepository : JpaRepository { +} \ No newline at end of file From d0ac832d40fb88e2d9241b945b9634fc5a23ce3b Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:26:35 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat=20:=20(=EC=9E=84=EC=8B=9C)=20diaryIm?= =?UTF-8?q?ageGenerator=20=EC=9E=84=EC=8B=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grida/domain/diaryimage/DiaryImageGenerator.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageGenerator.kt diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageGenerator.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageGenerator.kt new file mode 100644 index 00000000..07f95ebc --- /dev/null +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageGenerator.kt @@ -0,0 +1,12 @@ +package org.grida.domain.diaryimage + +import org.springframework.stereotype.Component + +@Component +class DiaryImageGenerator { + + fun generate(diaryContent: String): String { + // TODO + return "https://tmpImageUrl.com" + } +} \ No newline at end of file From 5536e7c026d4857f54c5a5686a510aecefe45b8c Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:27:28 +0900 Subject: [PATCH 05/12] =?UTF-8?q?refactor=20:=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=EA=B0=92=20=EC=B6=94=EA=B0=80,=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/grida/persistence/diaryimage/DiaryImageEntity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt index 1644cbdc..b701b369 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.kt @@ -18,12 +18,12 @@ import javax.persistence.ManyToOne import javax.persistence.Table @Entity -@Table(name = "diary-image") +@Table(name = "diary_image") class DiaryImageEntity( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "diary_id") - val id: Long, + @Column(name = "diary_image_id") + var id: Long = 0, @Column(length = 511) var imageUrl: String, From f4efb1564363c4406e4ca73b2c699c3a04c9d311 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:27:38 +0900 Subject: [PATCH 06/12] =?UTF-8?q?refactor=20:=20=ED=8A=B8=EB=9E=9C?= =?UTF-8?q?=EC=9E=AD=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grida/persistence/diaryimage/DiaryImageEntityRepository.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt index 5311e348..fcc24a73 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt @@ -12,9 +12,10 @@ import org.springframework.transaction.annotation.Transactional @Repository @Transactional(readOnly = true) class DiaryImageEntityRepository( - private val diaryImageJpaEntityRepository: DiaryJpaEntityRepository + private val diaryImageJpaEntityRepository: DiaryImageJpaEntityRepository ) : DiaryImageRepository { + @Transactional override fun save( diaryImage: DiaryImage, diary: Diary, From a3293ea632a87a7bd48fe0fa78353c4f949f4399 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:28:05 +0900 Subject: [PATCH 07/12] =?UTF-8?q?refactor=20:=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=EB=A6=84=20=EC=A4=91=EB=B3=B5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...yJpaEntityRepository.kt => DiaryImageJpaEntityRepository.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/{DiaryJpaEntityRepository.kt => DiaryImageJpaEntityRepository.kt} (56%) diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageJpaEntityRepository.kt similarity index 56% rename from grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt rename to grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageJpaEntityRepository.kt index f8760185..157bfe2a 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryJpaEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageJpaEntityRepository.kt @@ -2,5 +2,5 @@ package org.grida.persistence.diaryimage import org.springframework.data.jpa.repository.JpaRepository -interface DiaryJpaEntityRepository : JpaRepository { +interface DiaryImageJpaEntityRepository : JpaRepository { } \ No newline at end of file From 4efd2a5abae86f90a9eb82eb963c2d2495c9130f Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:28:29 +0900 Subject: [PATCH 08/12] =?UTF-8?q?feat=20:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=83=9D=EC=84=B1=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/diaryimage/DiaryImageController.kt | 27 ++++++++++++++++ .../domain/diaryimage/DiaryImageAppender.kt | 25 +++++++++++++++ .../domain/diaryimage/DiaryImageService.kt | 32 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/diaryimage/DiaryImageController.kt create mode 100644 grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageAppender.kt create mode 100644 grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageService.kt diff --git a/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/diaryimage/DiaryImageController.kt b/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/diaryimage/DiaryImageController.kt new file mode 100644 index 00000000..5ec48196 --- /dev/null +++ b/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/diaryimage/DiaryImageController.kt @@ -0,0 +1,27 @@ +package org.grida.presentation.v1.diaryimage + +import io.wwan13.wintersecurity.resolve.RequestUserId +import org.grida.api.ApiResponse +import org.grida.api.dto.IdResponse +import org.grida.domain.diaryimage.DiaryImageService +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/v1/diary") +class DiaryImageController( + private val diaryImageService: DiaryImageService +) { + + @PostMapping("/{diaryId}/image") + fun generateDiaryImage( + @RequestUserId userId: Long, + @PathVariable diaryId: Long + ): ApiResponse { + val generatedDiaryImageId = diaryImageService.generateDiaryImage(diaryId, userId) + val response = IdResponse(generatedDiaryImageId) + return ApiResponse.success(response) + } +} diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageAppender.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageAppender.kt new file mode 100644 index 00000000..8a23d9e2 --- /dev/null +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageAppender.kt @@ -0,0 +1,25 @@ +package org.grida.domain.diaryimage + +import org.grida.domain.diary.DiaryReader +import org.grida.domain.user.UserReader +import org.springframework.stereotype.Component +import org.springframework.transaction.annotation.Transactional + +@Component +class DiaryImageAppender( + private val diaryImageRepository: DiaryImageRepository, + private val diaryReader: DiaryReader, + private val userReader: UserReader +) { + + @Transactional + fun append( + diaryImage: DiaryImage, + diaryId: Long, + userId: Long + ): Long { + val diary = diaryReader.read(diaryId) + val user = userReader.read(userId) + return diaryImageRepository.save(diaryImage, diary, user) + } +} \ No newline at end of file diff --git a/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageService.kt b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageService.kt new file mode 100644 index 00000000..034543b4 --- /dev/null +++ b/grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageService.kt @@ -0,0 +1,32 @@ +package org.grida.domain.diaryimage + +import org.grida.domain.diary.DiaryReader +import org.grida.domain.diary.DiaryValidator +import org.grida.domain.image.Image +import org.grida.domain.image.ImageStatus +import org.springframework.stereotype.Service + +@Service +class DiaryImageService( + private val diaryImageAppender: DiaryImageAppender, + private val diaryImageGenerator: DiaryImageGenerator, + private val diaryReader: DiaryReader, + private val diaryValidator: DiaryValidator +) { + + fun generateDiaryImage( + diaryId: Long, + userId: Long + ): Long { + val diary = diaryReader.read(diaryId) + diaryValidator.validateIsOwner(diary, userId) + val generatedImageUrl = diaryImageGenerator.generate(diary.content) + + val diaryImage = DiaryImage( + userId = userId, + diaryId = diaryId, + image = Image(generatedImageUrl, ImageStatus.DEACTIVATE) + ) + return diaryImageAppender.append(diaryImage, diaryId, userId) + } +} \ No newline at end of file From e79bdc08616271fb1c2e8e188ebd820a39c54d33 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:28:49 +0900 Subject: [PATCH 09/12] =?UTF-8?q?refactor=20:=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/org/grida/presentation/v1/user/UserController.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/user/UserController.kt b/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/user/UserController.kt index e91749b6..fd892022 100644 --- a/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/user/UserController.kt +++ b/grida-core/core-api/src/main/kotlin/org/grida/presentation/v1/user/UserController.kt @@ -23,13 +23,13 @@ class UserController( fun signIn( @RequestBody request: SignInRequest ): ApiResponse { - val ROLEUser = User( + val user = User( username = request.username, password = passwordEncoder.encode(request.password), nickname = request.username, role = Role.ROLE_USER ) - val userId = userService.appendNormalUser(ROLEUser, request.passwordConfirm) + val userId = userService.appendNormalUser(user, request.passwordConfirm) val response = IdResponse(userId) return ApiResponse.success(response) } From 0fd63f6efca11b43febd666e3f2456ab83ceec0e Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 15:53:40 +0900 Subject: [PATCH 10/12] =?UTF-8?q?refactor=20:=20rds=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20entity=20=EB=A7=A4=ED=95=91=20=EB=B0=A9=EC=8B=9D=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grida/persistence/diary/DiaryEntity.kt | 30 +------------- .../persistence/diary/DiaryEntityMapper.kt | 26 ++++++++++++ .../diary/DiaryEntityRepository.kt | 5 ++- ...ageMapper.kt => DiaryImageEntityMapper.kt} | 14 ++++--- .../profileimage/ProfileImageEntity.kt | 41 ------------------- .../profileimage/ProfileImageEntityMapper.kt | 39 ++++++++++++++++++ .../ProfileImageEntityRepository.kt | 10 ++--- .../org/grida/persistence/user/UserEntity.kt | 26 +----------- .../persistence/user/UserEntityMapper.kt | 24 +++++++++++ .../persistence/user/UserEntityRepository.kt | 7 ++-- 10 files changed, 111 insertions(+), 111 deletions(-) create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityMapper.kt rename grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/{DiaryImageMapper.kt => DiaryImageEntityMapper.kt} (69%) create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityMapper.kt create mode 100644 grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityMapper.kt diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntity.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntity.kt index 068f4c46..ffef9336 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntity.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntity.kt @@ -1,8 +1,6 @@ package org.grida.persistence.diary -import org.grida.domain.diary.Diary import org.grida.domain.diary.DiaryScope -import org.grida.domain.user.User import org.grida.persistence.base.BaseEntity import org.grida.persistence.user.UserEntity import java.time.LocalDate @@ -39,17 +37,6 @@ class DiaryEntity( var user: UserEntity ) : BaseEntity() { - fun toDiary(): Diary { - return Diary( - id = id, - timestamp = this.toTimeStamp(), - targetDate = targetDate, - content = content, - scope = scope, - userId = user.id - ) - } - fun updateContent(content: String) { this.content = content } @@ -57,19 +44,4 @@ class DiaryEntity( fun updateScope(scope: DiaryScope) { this.scope = scope } - - companion object { - fun from( - diary: Diary, - user: User - ): DiaryEntity { - return DiaryEntity( - id = diary.id, - targetDate = diary.targetDate, - content = diary.content, - scope = diary.scope, - user = UserEntity.from(user) - ) - } - } -} \ No newline at end of file +} diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityMapper.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityMapper.kt new file mode 100644 index 00000000..788d48e9 --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityMapper.kt @@ -0,0 +1,26 @@ +package org.grida.persistence.diary + +import org.grida.domain.diary.Diary +import org.grida.domain.user.User +import org.grida.persistence.user.toEntity + +fun Diary.toEntity(user: User): DiaryEntity { + return DiaryEntity( + id = this.id, + targetDate = this.targetDate, + content = this.content, + scope = this.scope, + user = user.toEntity() + ) +} + +fun DiaryEntity.toDomain(): Diary { + return Diary( + id = this.id, + timestamp = this.toTimeStamp(), + targetDate = this.targetDate, + content = this.content, + scope = this.scope, + userId = this.user.id + ) +} \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityRepository.kt index 7fda38ec..fceb660c 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityRepository.kt @@ -19,13 +19,14 @@ class DiaryEntityRepository( diary: Diary, user: User ): Long { - val diaryEntity = diaryJpaEntityRepository.save(DiaryEntity.from(diary, user)) + val diaryEntity = diary.toEntity(user) + diaryJpaEntityRepository.save(diaryEntity) return diaryEntity.id } override fun findById(id: Long): Diary { val diaryEntity = diaryJpaEntityRepository.findByIdOrException(id) - return diaryEntity.toDiary() + return diaryEntity.toDomain() } override fun existsByUserIdAndTargetDate( diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityMapper.kt similarity index 69% rename from grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt rename to grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityMapper.kt index 3a67657f..fb5683fd 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageMapper.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityMapper.kt @@ -1,20 +1,22 @@ package org.grida.persistence.diaryimage +import org.grida.domain.diary.Diary import org.grida.domain.diaryimage.DiaryImage import org.grida.domain.image.Image -import org.grida.persistence.diary.DiaryEntity -import org.grida.persistence.user.UserEntity +import org.grida.domain.user.User +import org.grida.persistence.diary.toEntity +import org.grida.persistence.user.toEntity fun DiaryImage.toEntity( - userEntity: UserEntity, - diaryEntity: DiaryEntity + user: User, + diary: Diary ): DiaryImageEntity { return DiaryImageEntity( id = this.id, imageUrl = this.image.url, status = this.image.status, - user = userEntity, - diary = diaryEntity + user = user.toEntity(), + diary = diary.toEntity(user) ) } diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntity.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntity.kt index dc392bcc..b0a10c90 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntity.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntity.kt @@ -1,11 +1,7 @@ package org.grida.persistence.profileimage -import org.grida.domain.image.Image import org.grida.domain.image.ImageStatus -import org.grida.domain.profileimage.Appearance import org.grida.domain.profileimage.Gender -import org.grida.domain.profileimage.ProfileImage -import org.grida.domain.user.User import org.grida.persistence.base.BaseEntity import org.grida.persistence.user.UserEntity import javax.persistence.Column @@ -50,44 +46,7 @@ class ProfileImageEntity( var user: UserEntity ) : BaseEntity() { - fun toProfileImage(): ProfileImage { - return ProfileImage( - id = id, - userId = user.id, - image = Image( - url = imageUrl, - status = status, - timestamp = toTimeStamp() - ), - appearance = Appearance( - gender = gender, - age = age, - hairStyle = hairStyle, - glasses = glasses, - bodyShape = bodyShape - ) - ) - } - fun updateStatue(status: ImageStatus) { this.status = status } - - companion object { - fun from( - profileImage: ProfileImage, - user: User - ): ProfileImageEntity { - return ProfileImageEntity( - imageUrl = profileImage.image.url, - status = profileImage.image.status, - gender = profileImage.appearance.gender, - age = profileImage.appearance.age, - hairStyle = profileImage.appearance.hairStyle, - glasses = profileImage.appearance.glasses, - bodyShape = profileImage.appearance.bodyShape, - user = UserEntity.from(user) - ) - } - } } diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityMapper.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityMapper.kt new file mode 100644 index 00000000..49322e8f --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityMapper.kt @@ -0,0 +1,39 @@ +package org.grida.persistence.profileimage + +import org.grida.domain.image.Image +import org.grida.domain.profileimage.Appearance +import org.grida.domain.profileimage.ProfileImage +import org.grida.domain.user.User +import org.grida.persistence.user.toEntity + +fun ProfileImage.toEntity(user: User): ProfileImageEntity { + return ProfileImageEntity( + imageUrl = this.image.url, + status = this.image.status, + gender = this.appearance.gender, + age = this.appearance.age, + hairStyle = this.appearance.hairStyle, + glasses = this.appearance.glasses, + bodyShape = this.appearance.bodyShape, + user = user.toEntity() + ) +} + +fun ProfileImageEntity.toDomain(): ProfileImage { + return ProfileImage( + id = this.id, + userId = this.user.id, + image = Image( + url = this.imageUrl, + status = this.status, + timestamp = this.toTimeStamp() + ), + appearance = Appearance( + gender = this.gender, + age = this.age, + hairStyle = this.hairStyle, + glasses = this.glasses, + bodyShape = this.bodyShape + ) + ) +} \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityRepository.kt index 96ea7537..3150c6ed 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/profileimage/ProfileImageEntityRepository.kt @@ -18,25 +18,25 @@ class ProfileImageEntityRepository( profileImage: ProfileImage, user: User ): Long { - val profileImageEntity = - profileImageJpaEntityRepository.save(ProfileImageEntity.from(profileImage, user)) + val profileImageEntity = profileImage.toEntity(user) + profileImageJpaEntityRepository.save(profileImageEntity) return profileImageEntity.id } override fun findById(id: Long): ProfileImage { val profileImageEntity = profileImageJpaEntityRepository.findByIdOrException(id) - return profileImageEntity.toProfileImage() + return profileImageEntity.toDomain() } override fun findByUserIdAndStatus(userId: Long, status: ImageStatus): ProfileImage { val profileImageEntity = profileImageJpaEntityRepository.findByUserIdAndStatusOrException(userId, status) - return profileImageEntity.toProfileImage() + return profileImageEntity.toDomain() } override fun findAllByUserId(userId: Long): List { val profileImageEntities = profileImageJpaEntityRepository.findAllByUserId(userId) - return profileImageEntities.map { it.toProfileImage() } + return profileImageEntities.map { it.toDomain() } } override fun existsByUserIdAndStatus(userId: Long, status: ImageStatus): Boolean { diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntity.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntity.kt index f7bf8e6b..c8119ced 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntity.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntity.kt @@ -29,28 +29,4 @@ class UserEntity( var role: Role, var nickname: String -) : BaseEntity() { - - fun toUser(): User { - return User( - id = id, - username = username, - password = password, - role = role, - nickname = nickname, - timestamp = toTimeStamp() - ) - } - - companion object { - fun from(user: User): UserEntity { - return UserEntity( - id = user.id, - username = user.username, - password = user.password, - role = user.role, - nickname = user.nickname - ) - } - } -} +) : BaseEntity() diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityMapper.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityMapper.kt new file mode 100644 index 00000000..a348bb22 --- /dev/null +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityMapper.kt @@ -0,0 +1,24 @@ +package org.grida.persistence.user + +import org.grida.domain.user.User + +fun User.toEntity(): UserEntity { + return UserEntity( + id = this.id, + username = this.username, + password = this.password, + role = this.role, + nickname = this.nickname + ) +} + +fun UserEntity.toDomain(): User { + return User( + id = this.id, + username = this.username, + password = this.password, + role = this.role, + nickname = this.nickname, + timestamp = this.toTimeStamp() + ) +} \ No newline at end of file diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityRepository.kt index 1b2aa8e5..a4cff1b5 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/user/UserEntityRepository.kt @@ -13,18 +13,19 @@ class UserEntityRepository( @Transactional override fun save(user: User): Long { - val userEntity = userJpaEntityRepository.save(UserEntity.from(user)) + val userEntity = user.toEntity() + userJpaEntityRepository.save(userEntity) return userEntity.id } override fun findById(id: Long): User { val userEntity = userJpaEntityRepository.findByIdOrException(id) - return userEntity.toUser() + return userEntity.toDomain() } override fun findByUsername(username: String): User { val userEntity = userJpaEntityRepository.findByUsernameOrException(username) - return userEntity.toUser() + return userEntity.toDomain() } override fun existsByUsername(username: String): Boolean { From 18f43db601b4e4c61376c2d71d906c0f6453142a Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 16:15:42 +0900 Subject: [PATCH 11/12] =?UTF-8?q?refactor=20:=20rds=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20entity=20=EB=A7=A4=ED=95=91=20=EB=B0=A9=EC=8B=9D=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/diaryimage/DiaryImageEntityRepository.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt index fcc24a73..2be8d18d 100644 --- a/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt +++ b/grida-database/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.kt @@ -21,10 +21,7 @@ class DiaryImageEntityRepository( diary: Diary, user: User ): Long { - val diaryEntity = diaryImage.toEntity( - UserEntity.from(user), - DiaryEntity.from(diary, user) - ) + val diaryEntity = diaryImage.toEntity(user, diary) diaryImageJpaEntityRepository.save(diaryEntity) return diaryEntity.id } From 0b067bac5488315a88306ee5d24d5f278f5d173c Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 30 Jul 2024 16:16:35 +0900 Subject: [PATCH 12/12] =?UTF-8?q?docs=20:=20=EC=9D=BC=EA=B8=B0=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=83=9D=EC=84=B1=20API=20=EB=AC=B8?= =?UTF-8?q?=EC=84=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/diaryimage/DiaryImageApiDocsTest.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 grida-core/core-api/src/test/kotlin/org/grida/docs/diaryimage/DiaryImageApiDocsTest.kt diff --git a/grida-core/core-api/src/test/kotlin/org/grida/docs/diaryimage/DiaryImageApiDocsTest.kt b/grida-core/core-api/src/test/kotlin/org/grida/docs/diaryimage/DiaryImageApiDocsTest.kt new file mode 100644 index 00000000..17e2aaef --- /dev/null +++ b/grida-core/core-api/src/test/kotlin/org/grida/docs/diaryimage/DiaryImageApiDocsTest.kt @@ -0,0 +1,46 @@ +package org.grida.docs.diaryimage + +import com.ninjasquad.springmockk.MockkBean +import io.mockk.every +import io.wwan13.api.document.snippets.NUMBER +import io.wwan13.api.document.snippets.isTypeOf +import io.wwan13.api.document.snippets.whichMeans +import org.grida.docs.ApiDocsTest +import org.grida.domain.diaryimage.DiaryImageService +import org.grida.presentation.v1.diaryimage.DiaryImageController +import org.junit.jupiter.api.Test +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest + +@WebMvcTest(controllers = [DiaryImageController::class]) +class DiaryImageApiDocsTest( + private val diaryImageController: DiaryImageController +) : ApiDocsTest( + diaryImageController, + "diary-image" +) { + + @MockkBean + private lateinit var diaryImageService: DiaryImageService + + @Test + fun `일기 이미지 생성 API`() { + every { diaryImageService.generateDiaryImage(any(), any()) } returns 1L + + val api = api.post("/api/v1/diary/{diaryId}/image", 1L) { + withBearerToken() + } + + documentFor(api, "generate-diary-image") { + summary("일기 이미지 생성 API") + requestHeaders( + "Authorization" whichMeans "인증 토큰" + ) + pathParameters( + "diaryId" whichMeans "생성하려는 일기의 ID" + ) + responseFields( + "data.id" isTypeOf NUMBER whichMeans "생성된 일기 이미지 ID" + ) + } + } +}