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

Feat: JPA Entitiy 추가 작업 #14

Merged
merged 20 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c045a38
feat: UserTable 변경으로 인한 Entity 수정
jinsu4755 Dec 9, 2023
09e1a34
feat: Couple Table 수정으로 인한 Entity 수정
jinsu4755 Dec 9, 2023
b2a2e35
feat: user couple 정보 추가
jinsu4755 Dec 9, 2023
f2d532f
feat: entity 수정으로 인한 변경 사항 적용
jinsu4755 Dec 10, 2023
3754db7
feat: ID가 초기화 되지 않은 경우 exception 추가
jinsu4755 Dec 10, 2023
a931a3c
test: Add Jwt Authentication Test
jinsu4755 Dec 13, 2023
db09edc
test: Test DB를 h2 로 사용하도록 변경
jinsu4755 Dec 13, 2023
2ee75c7
feat: Game Entity Table 수정 및 생성
jinsu4755 Dec 13, 2023
3a4939a
style: 불필요한 라인 정리
jinsu4755 Dec 13, 2023
a19e6f8
feat: short game entity 수정으로 인한 변경 사항 적용
jinsu4755 Dec 13, 2023
77b7433
feat: short game entity 수정으로 인한 변경 사항 적용
jinsu4755 Dec 13, 2023
0a0447a
feat: Mission Category Table 수정으로 인한 코드 추가
jinsu4755 Dec 13, 2023
c16f009
feat: Mission Content Table 수정사항 반영
jinsu4755 Dec 13, 2023
4912eeb
feat: Game Round Table 수정 내용 반영
jinsu4755 Dec 13, 2023
181061a
feat: 사용자 알림 정보 테이블 수정 내용 적용
jinsu4755 Dec 13, 2023
e18f943
feat: user mission Table 수정 내용 적용
jinsu4755 Dec 13, 2023
d1fe5d7
feat: wish coupon Table 수정 내용 적용
jinsu4755 Dec 13, 2023
eaa13ee
style: fix ktlint
jinsu4755 Dec 13, 2023
4bfc10e
fix: 사용하지 않는 Dsl 코드 삭제
jinsu4755 Dec 13, 2023
fac4f64
fix: user Table 이름 변경
jinsu4755 Dec 13, 2023
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,5 +1,10 @@
package universe.sparkle.domain

enum class GameType {
SHORT, LONG
SHORT, LONG;

companion object {
const val CONTRACT_SHORT = "SHORT"
const val CONTRACT_LONG = "LONG"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package universe.sparkle.domain

enum class UserMissionState {
SUCCESS, FAILED, UNDECIDED
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class AuthenticationToken(
val id: Long,
val nickname: String?,
val image: String?,
val couple: Couple?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package universe.sparkle.domain.model

import java.time.LocalDate

data class Couple(
val id: Long? = null,
val startDate: LocalDate,
val heartToken: Int = 5,
val isDelete: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class User(
val snsAuthCode: String,
val nickname: String? = null,
val image: String? = null,
val fcmToken: String? = null,
val couple: Couple? = null,
) {

init {
Expand All @@ -23,7 +23,7 @@ data class User(
snsAuthCode = this.snsAuthCode,
nickname = updateNickname,
image = updateImage,
fcmToken = this.fcmToken,
couple = this.couple,
)
}

Expand All @@ -37,5 +37,6 @@ fun User.toAuthenticationToken() = this.id?.let { userId ->
id = userId,
nickname = this.nickname,
image = this.image,
couple = this.couple,
)
}
5 changes: 4 additions & 1 deletion module-infrastructure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ dependencies {
developmentOnly libs.spring.boot.devtools

testRuntimeOnly libs.db.h2
testImplementation libs.test.spring.boot.starter
testImplementation(libs.test.spring.boot.starter) {
exclude module: 'mockito-core'
}
testImplementation libs.test.mockk
testImplementation libs.test.spring.security
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package universe.sparkle.infrastructure.config

import com.querydsl.jpa.impl.JPAQueryFactory
/*import com.querydsl.jpa.impl.JPAQueryFactory
import jakarta.persistence.EntityManager
import jakarta.persistence.PersistenceContext
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -13,4 +13,4 @@ class QueryDslConfig @Autowired constructor(
) {
@Bean
fun jpaQueryFactory(): JPAQueryFactory = JPAQueryFactory(entityManager)
}
}*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package universe.sparkle.infrastructure.persistence

class NotInitializedIdException(
override val message: String = "ID has not been initialized yet"
) : IllegalArgumentException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class CoupleEntity(
id: Long? = null,
startDate: LocalDate,
heartToken: Int = 5,
isDelete: Boolean = false,
) {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "couple_id")
@Column(name = "id")
var id: Long? = id
protected set

Expand All @@ -30,4 +31,8 @@ class CoupleEntity(
@ColumnDefault("5")
var heartToken: Int = heartToken
protected set

@Column(name = "is_delete", nullable = false)
@ColumnDefault("false")
var isDelete: Boolean = isDelete
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package universe.sparkle.infrastructure.persistence.entity

import jakarta.persistence.Column
import jakarta.persistence.Convert
import jakarta.persistence.DiscriminatorColumn
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
Expand All @@ -9,33 +10,47 @@ import jakarta.persistence.Id
import jakarta.persistence.Inheritance
import jakarta.persistence.InheritanceType
import jakarta.persistence.Table
import java.time.LocalDateTime
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import universe.sparkle.domain.GameResult
import universe.sparkle.infrastructure.persistence.entity.converter.GameResultAttributeConverter
import java.time.Instant

@Entity
@Table(name = "game")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
open class GameEntity(
@DiscriminatorColumn(name = "GAME_TYPE")
class GameEntity(
id: Long? = null,
finishedAt: Instant? = null,
result: GameResult = GameResult.UNDECIDED,
coupleId: Long,
enable: Boolean = true,
finishedAt: LocalDateTime? = null,
onDelete: Boolean = false,
) {

@Id
@Column(name = "game_id")
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Long? = null
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
var id: Long? = id
protected set

@Column(name = "couple_id", nullable = false)
var coupleId = coupleId
@Column(name = "finished_at")
var finishedAt: Instant? = finishedAt
protected set

@Column(name = "enable", nullable = false)
var enable: Boolean = enable
@Size(max = 10)
@Convert(converter = GameResultAttributeConverter::class)
@Column(name = "result", length = 10)
var result: GameResult = result
protected set

@Column(name = "finished_at")
var finishedAt: LocalDateTime? = finishedAt
@NotNull
@Column(name = "couple_id", nullable = false)
var couple: Long = coupleId
protected set

@NotNull
@Column(name = "on_delete", nullable = false)
var onDelete: Boolean = onDelete
protected set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package universe.sparkle.infrastructure.persistence.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull
import java.time.Instant

@Entity
@Table(name = "game_round")
class GameRoundEntity(
id: Long? = null,
gameId: Long,
missionCategoryId: Long,
winnerUserId: Long,
updatedAt: Instant,
) {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
var id: Long? = id
protected set

@NotNull
@Column(name = "game_id", nullable = false)
var gameId: Long = gameId
protected set

@Column(name = "mission_category_id")
var missionCategoryId: Long = missionCategoryId
protected set

@Column(name = "winner_user_id")
var winnerUserId: Long = winnerUserId
protected set

@Column(name = "updated_at")
var updatedAt: Instant? = updatedAt
protected set
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import universe.sparkle.domain.MissionTool
import universe.sparkle.domain.MissionType
import universe.sparkle.infrastructure.persistence.entity.converter.MissionToolAttributeConverter
Expand All @@ -23,55 +25,72 @@ class MissionCategoryEntity(
example: String,
image: String,
level: Int,
expectedTime: Int,
expectedTime: Int? = null,
missionType: MissionType,
missionTool: MissionTool,
) {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "mission_category_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
var id: Long? = id
protected set

@Column(name = "title", nullable = false)
@Size(max = 50)
@NotNull
@Column(name = "title", nullable = false, length = 50)
var title: String = title
protected set

@Size(max = 255)
@NotNull
@Column(name = "description", nullable = false)
var description: String = description
protected set

@Size(max = 255)
@NotNull
@Column(name = "rule", nullable = false)
var rule: String = rule
protected set

@Size(max = 255)
@NotNull
@Column(name = "tip", nullable = false)
var tip: String = tip
protected set

@Size(max = 255)
@NotNull
@Column(name = "example", nullable = false)
var example: String = example
protected set

@Size(max = 255)
@NotNull
@Column(name = "image", nullable = false)
var image: String = image
protected set

@NotNull
@Column(name = "level", nullable = false)
var level: Int = level
protected set

@Column(name = "expected_time", nullable = false)
var expectedTime: Int = expectedTime
var expectedTime: Int? = expectedTime
protected set

@Column(name = "mission_type", nullable = false)
@Size(max = 30)
@NotNull
@Convert(converter = MissionTypeAttributeConverter::class)
@Column(name = "mission_type", nullable = false, length = 30)
var missionType: MissionType = missionType
protected set

@Column(name = "mission_tool", nullable = false)
@Size(max = 30)
@NotNull
@Convert(converter = MissionToolAttributeConverter::class)
@Column(name = "mission_tool", nullable = false, length = 30)
var missionTool: MissionTool = missionTool
protected set
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ package universe.sparkle.infrastructure.persistence.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import org.hibernate.annotations.OnDelete
import org.hibernate.annotations.OnDeleteAction

@Entity
@Table(name = "mission_content")
class MissionContentEntity(
id: Long? = null,
missionCategoryId: Long,
missionCategoryEntity: MissionCategoryEntity,
content: String,
recommendTime: String,
recommendTime: Int? = null,
) {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "mission_content_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
var id: Long? = id
protected set

@Column(name = "mission_category_id", nullable = false)
var missionCategoryId: Long = missionCategoryId
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "mission_category_id", nullable = false)
var missionCategory: MissionCategoryEntity = missionCategoryEntity
protected set

@Size(max = 255)
@NotNull
@Column(name = "content", nullable = false)
var content: String = content
protected set

@Column(name = "recommend_time", nullable = false)
var recommendTime: String = recommendTime
@Column(name = "recommend_time")
var recommendTime: Int? = recommendTime
protected set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package universe.sparkle.infrastructure.persistence.entity

import jakarta.persistence.Column
import jakarta.persistence.EmbeddedId
import jakarta.persistence.Entity
import jakarta.persistence.Table

@Entity
@Table(name = "notification_information")
class NotificationInformationEntity(
id: NotificationInformationEntityId,
enableAllNotification: Boolean = true,
) {
@EmbeddedId
var id: NotificationInformationEntityId = id
protected set

@Column(name = "enable_all_notification")
var enableAllNotification: Boolean = enableAllNotification
protected set
}
Loading
Loading