Skip to content

Commit

Permalink
Merge pull request #28 from mash-up-kr/yaeoni/string-id
Browse files Browse the repository at this point in the history
feat; 모든 도메인 모델의 id를 string type으로 바꿔요
  • Loading branch information
yaeoni authored Jun 29, 2024
2 parents 0b54fea + 64fc8a6 commit dd0f6a8
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 38 deletions.
4 changes: 2 additions & 2 deletions api/src/main/kotlin/com/mashup/dojo/SampleController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SampleController(
]
)
fun test(
@PathVariable id: Long,
): DojoApiResponse<Long> {
@PathVariable id: String,
): DojoApiResponse<String> {
return DojoApiResponse.success(sampleUseCase.getSampleId())
}
}
6 changes: 4 additions & 2 deletions entity/src/main/kotlin/com/mashup/dojo/ImageRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.mashup.dojo

import com.mashup.dojo.base.BaseEntity
import jakarta.persistence.Entity
import jakarta.persistence.Id
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface ImageRepository : JpaRepository<ImageEntity, Long>
interface ImageRepository : JpaRepository<ImageEntity, String>

@Entity
class ImageEntity(
val uuid: String,
@Id
val id: String,
val url: String,
) : BaseEntity()
3 changes: 3 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/SampleEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.mashup.dojo

import com.mashup.dojo.base.BaseEntity
import jakarta.persistence.Entity
import jakarta.persistence.Id

@Entity
class SampleEntity(
@Id
val id: String,
val name: String,
) : BaseEntity()
2 changes: 1 addition & 1 deletion entity/src/main/kotlin/com/mashup/dojo/SampleRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface SampleRepository : JpaRepository<SampleEntity, Long>
interface SampleRepository : JpaRepository<SampleEntity, String>
8 changes: 0 additions & 8 deletions entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package com.mashup.dojo.base

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.MappedSuperclass
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
Expand All @@ -14,11 +11,6 @@ import java.time.LocalDateTime
@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
val id: Long = 0L

@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
lateinit var createdAt: LocalDateTime
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/kotlin/com/mashup/dojo/domain/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class Image(
val url: String,
) {
companion object {
val MOCK_USER_IMAGE =
val MOCK_IMAGE =
Image(
id = ImageId("12345678"),
url = "https://example.com/image/1"
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/kotlin/com/mashup/dojo/domain/Member.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.time.LocalDateTime
* (Mashup)Member
*/
@JvmInline
value class MemberId(val value: Long)
value class MemberId(val value: String)

data class Member(
val id: MemberId,
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/kotlin/com/mashup/dojo/domain/Pick.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mashup.dojo.domain
import java.time.LocalDateTime

@JvmInline
value class PickId(val value: Long)
value class PickId(val value: String)

data class Pick(
val id: PickId,
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/kotlin/com/mashup/dojo/domain/Question.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mashup.dojo.domain
import java.time.LocalDateTime

@JvmInline
value class QuestionId(val value: Long)
value class QuestionId(val value: String)

data class Question(
val id: QuestionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mashup.dojo.domain
import java.time.LocalDateTime

@JvmInline
value class QuestionSetId(val value: Long)
value class QuestionSetId(val value: String)

data class QuestionOrder(
val questionId: QuestionId,
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/kotlin/com/mashup/dojo/domain/Sample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mashup.dojo.domain
import java.time.LocalDateTime

data class Sample(
val id: Long,
val id: String,
val name: String,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class DefaultImageService(
uuid: String,
imageUrl: String,
): ImageId {
val entity = ImageEntity(uuid = uuid, url = imageUrl)
val entity = ImageEntity(id = uuid, url = imageUrl)
val saved = imageRepository.save(entity)
return ImageId(saved.uuid)
return ImageId(saved.id)
}

override fun load(imageId: ImageId): Image {
Expand Down
28 changes: 14 additions & 14 deletions service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DefaultQuestionService : QuestionService {
companion object {
val SAMPLE_QUESTION =
Question(
id = QuestionId(8181818),
id = QuestionId("1234564"),
content = "세상에서 제일 멋쟁이인 사람",
type = QuestionType.FRIEND,
category = QuestionCategory.ROMANCE,
Expand All @@ -75,21 +75,21 @@ class DefaultQuestionService : QuestionService {

val SAMPLE_QUESTION_SET =
QuestionSet(
id = QuestionSetId(1),
id = QuestionSetId("1"),
questionIds =
listOf(
QuestionOrder(QuestionId(1), 1),
QuestionOrder(QuestionId(2), 2),
QuestionOrder(QuestionId(3), 3),
QuestionOrder(QuestionId(4), 4),
QuestionOrder(QuestionId(5), 5),
QuestionOrder(QuestionId(6), 6),
QuestionOrder(QuestionId(7), 7),
QuestionOrder(QuestionId(8), 8),
QuestionOrder(QuestionId(9), 9),
QuestionOrder(QuestionId(10), 10),
QuestionOrder(QuestionId(11), 11),
QuestionOrder(QuestionId(12), 12)
QuestionOrder(QuestionId("1"), 1),
QuestionOrder(QuestionId("2"), 2),
QuestionOrder(QuestionId("3"), 3),
QuestionOrder(QuestionId("4"), 4),
QuestionOrder(QuestionId("5"), 5),
QuestionOrder(QuestionId("6"), 6),
QuestionOrder(QuestionId("7"), 7),
QuestionOrder(QuestionId("8"), 8),
QuestionOrder(QuestionId("9"), 9),
QuestionOrder(QuestionId("10"), 10),
QuestionOrder(QuestionId("11"), 11),
QuestionOrder(QuestionId("12"), 12)
),
publishedAt = LocalDateTime.now()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class SampleService(
private val sampleRepository: SampleRepository,
) {
fun getSample(): Sample {
val sampleEntity = sampleRepository.findByIdOrNull(0L) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST)
val sampleEntity = sampleRepository.findByIdOrNull("123456") ?: throw DojoException.of(DojoExceptionType.NOT_EXIST)
return sampleEntity.buildDomain()
}

private fun SampleEntity.buildDomain(): Sample {
return Sample(
id = id,
id = "sample Id",
name = name,
createdAt = createdAt,
updatedAt = updatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component
class SampleUseCase(
private val sampleService: SampleService,
) {
fun getSampleId(): Long {
fun getSampleId(): String {
return sampleService.getSample().id
}
}

0 comments on commit dd0f6a8

Please sign in to comment.