Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

도메인 구조를 리패키징하고 래핑했습니다. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.usw.usgo.domain
package com.usw.usgo.domain.core

import jakarta.persistence.*
import org.springframework.data.annotation.CreatedDate
Expand All @@ -11,12 +11,16 @@ import java.time.LocalDateTime
abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null
val id: Long = 0L
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 안그래도 궁금했던 부분 중 하나..!
JPA에서 Wrapper 타입을 사용하는건 0과 같은 값이 ID일 때 유효한가?에 대한 판단을 위해서인데
이렇게 0을 써도 무방해 부라더?? 잘 모르겠움 😭

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto increment는 GenerationType.IDENTITY옵션을 쓰면 전적으로 DBMS가 부여하는 PK를 쓰는걸로 알고있어서 기본값을 0L로 지정해도 무관하다고 알고있어요!

물론 형이 하신대로 하셔도 진짜 노상관이라서 이것도 굳이 반영안하고 형 생각대로 가도 될 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몰라서 물어본거라 편하게 정해도 좋습니다 ㅋㅋ


@Column(name = "is_deleted")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name을 딱히 매핑해주지 않아도 자동으로 snake_case로 변환해주는데 굳이 붙인 이유가 있을까??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하다가 빼먹은 컬럼이 많긴하지만 명시적으로 컬럼을 네이밍하는게 조금 더 보기 좋은 것 같긴해서 써놨어요~

이것도 컨벤션 정해놓으면 좋을것같네요?!

var isDeleted: Boolean = false

@CreatedDate
@Column(updatable = false)
@Column(name = "created_at", updatable = false)
val createdAt: LocalDateTime = LocalDateTime.now()

@LastModifiedDate
@Column(name = "modified_at")
var modifiedAt: LocalDateTime = LocalDateTime.now()
}
20 changes: 20 additions & 0 deletions core/src/main/kotlin/com/usw/usgo/domain/core/notice/Notice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.usw.usgo.domain.core.notice

import com.usw.usgo.domain.core.BaseEntity
import com.usw.usgo.domain.embeddable.Content
import com.usw.usgo.domain.embeddable.Title
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.Table

@Entity
@Table(name = "notice")
class Notice(

@Embedded
var title: Title,

@Embedded
var content: Content,
) : BaseEntity() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.usw.usgo.domain.core.productpost

import com.usw.usgo.domain.core.BaseEntity
import com.usw.usgo.domain.core.user.User
import com.usw.usgo.domain.embeddable.Content
import com.usw.usgo.domain.embeddable.Price
import com.usw.usgo.domain.embeddable.Title
import com.usw.usgo.domain.enumerated.ContactPlace
import jakarta.persistence.*

@Entity
@Table(name = "product_post")
class ProductPost(

@Embedded
var title: Title,

@Embedded
var content: Content,

@Embedded
var price: Price,

@Enumerated(EnumType.STRING)
var contactPlace: ContactPlace,

@Enumerated(EnumType.STRING)
var status: Status = Status.NORMAL,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val user: User,

) : BaseEntity()

enum class Status {
NORMAL,
RESTRICTED,
DELETED,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.usw.usgo.domain.user
package com.usw.usgo.domain.core.user

import jakarta.persistence.Embeddable
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.usw.usgo.domain.user
package com.usw.usgo.domain.core.user

import jakarta.persistence.Embeddable
import java.math.BigDecimal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.usw.usgo.domain.user
package com.usw.usgo.domain.core.user

import com.usw.usgo.domain.BaseEntity
import com.usw.usgo.domain.core.BaseEntity
import jakarta.persistence.*

@Entity
@Table(name = "users")
@Table(name = "user")
class User(
@Column(length = 50)
@Column(name = "login_id", length = 50, nullable = false)
val loginId: String,

@Column(length = 50)
@Column(name = "email", length = 50, nullable = false)
val email: String,

@Column(length = 50)
@Column(name = "nickname", length = 50, nullable = false)
var nickname: String,

@Column(length = 50)
@Column(name = "password", length = 50, nullable = false)
var password: String,

@Embedded
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/kotlin/com/usw/usgo/domain/core/userpost/PostLike.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.usw.usgo.domain.core.userpost

import com.usw.usgo.domain.core.BaseEntity
import com.usw.usgo.domain.core.productpost.ProductPost
import com.usw.usgo.domain.core.user.User
import jakarta.persistence.*

@Entity
@Table(name = "post_like")
class PostLike(

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val user: User,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_post_id")
val productPost: ProductPost,

) : BaseEntity()
11 changes: 11 additions & 0 deletions core/src/main/kotlin/com/usw/usgo/domain/embeddable/Content.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.usw.usgo.domain.embeddable

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
class Content(

@Column(nullable = false)
val value: String,
)
11 changes: 11 additions & 0 deletions core/src/main/kotlin/com/usw/usgo/domain/embeddable/Price.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.usw.usgo.domain.embeddable

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
class Price(

@Column(nullable = false)
val value: Int,
)
11 changes: 11 additions & 0 deletions core/src/main/kotlin/com/usw/usgo/domain/embeddable/Title.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.usw.usgo.domain.embeddable

import jakarta.persistence.Column
import jakarta.persistence.Embeddable

@Embeddable
class Title(

@Column(nullable = false)
val value: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.usw.usgo.domain.enumerated

enum class ContactPlace {

IT, ACE, GLOBAL,
}
17 changes: 0 additions & 17 deletions core/src/main/kotlin/com/usw/usgo/domain/notice/Notice.kt

This file was deleted.

14 changes: 0 additions & 14 deletions core/src/main/kotlin/com/usw/usgo/domain/productpost/PostLike.kt

This file was deleted.

This file was deleted.