-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/Difficulty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package kr.hs.dsm.inq.domain.question.persistence | ||
|
||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
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 | ||
|
||
|
||
@Table(name = "tbl_difficulity") | ||
@Entity | ||
class Difficulty( | ||
|
||
@Id | ||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
var id: Long = 0L, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "questions_id", columnDefinition = "BIGINT", nullable = false) | ||
var questions: Questions, | ||
|
||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
var veryEasyCount: Int = 0, | ||
|
||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
var easyCount: Int = 0, | ||
|
||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
var normalCount: Int = 0, | ||
|
||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
var hardCount: Int = 0, | ||
|
||
@Column(columnDefinition = "BIGINT", nullable = false) | ||
var veryHardCount: Int = 0, | ||
) { | ||
|
||
var total = veryEasyCount + easyCount + normalCount + hardCount + veryHardCount | ||
|
||
fun getPercentage(difficultyLevel: DifficultyLevel): Int { | ||
return getCount(difficultyLevel) * 100 / total | ||
} | ||
|
||
private fun getCount(difficultyLevel: DifficultyLevel): Int { | ||
return when (difficultyLevel) { | ||
DifficultyLevel.VERY_EASY -> veryEasyCount | ||
DifficultyLevel.EASY -> easyCount | ||
DifficultyLevel.NORMAL -> normalCount | ||
DifficultyLevel.HARD -> hardCount | ||
DifficultyLevel.VERY_HARD -> veryHardCount | ||
} | ||
} | ||
|
||
fun addCount(difficultyLevel: DifficultyLevel) { | ||
when (difficultyLevel) { | ||
DifficultyLevel.VERY_EASY -> veryEasyCount++ | ||
DifficultyLevel.EASY -> easyCount++ | ||
DifficultyLevel.NORMAL -> normalCount++ | ||
DifficultyLevel.HARD -> hardCount++ | ||
DifficultyLevel.VERY_HARD -> veryHardCount | ||
} | ||
} | ||
} | ||
|
||
enum class DifficultyLevel { | ||
VERY_EASY, | ||
EASY, | ||
NORMAL, | ||
HARD, | ||
VERY_HARD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/DifficultyRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kr.hs.dsm.inq.domain.question.persistence.repository | ||
|
||
import kr.hs.dsm.inq.domain.question.persistence.Category | ||
import kr.hs.dsm.inq.domain.question.persistence.Difficulty | ||
import kr.hs.dsm.inq.domain.question.persistence.Tags | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface DifficultyRepository : JpaRepository<Difficulty, Long> { | ||
fun queryByQuestionsId(questionsId: Long): Difficulty? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters