Skip to content

Commit

Permalink
Merge pull request #2 from DSM-InQ/db-setting
Browse files Browse the repository at this point in the history
feat: question entity 세팅
  • Loading branch information
12xii authored Oct 4, 2023
2 parents 00f8091 + 37f2c46 commit 96c7814
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kr.hs.dsm.inq.domain.question.persistence

import javax.persistence.*

@Table(name = "tbl_problem")
@Entity
data class Problem (
@Id
@Column(columnDefinition = "BIGINT", nullable = false)
val id: Long = 0L,

@Column(columnDefinition = "VARCHAR(30)", nullable = false)
@Enumerated(EnumType.STRING)
val type: ProblemType
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kr.hs.dsm.inq.domain.question.persistence

enum class ProblemType {
QUESTION,
SET
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kr.hs.dsm.inq.domain.question.persistence

import java.time.LocalDateTime
import javax.persistence.*

@Table(name = "tbl_question_set")
@Entity()
class QuestionSets (
@Id
@Column(columnDefinition = "BIGINT", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long = 0L,

@Column(columnDefinition = "VARCHAR(30)", nullable = false)
var name: String,

@Column(columnDefinition = "VARCHAR(1000)", nullable = false)
var description: String,

@Column(columnDefinition = "DATETIME(6)", nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now(),

@Column(columnDefinition = "INT", nullable = false)
var answerCount: Int,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", columnDefinition = "BIGINT",nullable = false)
var postId: Post,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "problem_id", columnDefinition = "BITINT", nullable = false)
var problemId: Problem,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package kr.hs.dsm.inq.domain.question.persistence

import kr.hs.dsm.inq.domain.user.persistence.User
import java.io.Serializable
import java.time.LocalDateTime
import java.util.Date
import javax.persistence.*

@Table(name = "tbl_question_solving_history")
@Entity
class QuestionSolvingHistory (
@Id
var id: Long,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BIGINT", nullable = false)
var userId: User,

@Column(columnDefinition = "DATETIME(6)", nullable = false)
var solvedAt: LocalDateTime = LocalDateTime.now(),

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "problem", columnDefinition = "BIGINT", nullable = false)
var problem: Problem
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ data class Questions(
@JoinColumn(name = "author_id", columnDefinition = "BIGINT", nullable = false)
var author: User,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "problem_id", columnDefinition = "BIGINT", nullable = false)
var problem: Problem,

@Column(nullable = false, updatable = false, columnDefinition = "DATETIME(6)")
val createdAt: LocalDateTime = LocalDateTime.now()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kr.hs.dsm.inq.domain.question.persistence

import java.io.Serializable
import javax.persistence.*

@Table(name = "tbl_set_question")
@Entity
class SetQuestion (
@EmbeddedId
val id: SetQuestionID,

@MapsId("setId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "set_id", columnDefinition = "BIGINT", nullable = false)
var setId: QuestionSets,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id", columnDefinition = "BIGINT", nullable = false)
var questionId: Questions,

@Column(columnDefinition = "INT", nullable = false)
var index: Int,
)

@Embeddable
data class SetQuestionID (
@Column
val setId: Long,

@Column
val questionId: Long
) : Serializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.hs.dsm.inq.domain.question.persistence.repository

import kr.hs.dsm.inq.domain.question.persistence.QuestionSets
import org.springframework.data.repository.CrudRepository

interface QuestionSetsRepository : CrudRepository<QuestionSets, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.hs.dsm.inq.domain.question.persistence.repository

import kr.hs.dsm.inq.domain.question.persistence.QuestionSolvingHistory
import org.springframework.data.repository.CrudRepository

interface QuestionSolvingHistoryRepository: CrudRepository<QuestionSolvingHistory, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.hs.dsm.inq.domain.question.persistence.repository

import kr.hs.dsm.inq.domain.question.persistence.SetQuestion
import kr.hs.dsm.inq.domain.question.persistence.SetQuestionID
import org.springframework.data.repository.CrudRepository

interface SetQuestionRepository : CrudRepository<SetQuestion, SetQuestionID> {

}

0 comments on commit 96c7814

Please sign in to comment.