Skip to content

Commit

Permalink
Feat: Change pagename -> name, add language and mainType column, add …
Browse files Browse the repository at this point in the history
…unique constraints.
  • Loading branch information
huGgW committed Feb 10, 2024
1 parent 0e5cd6e commit 4d49b2b
Showing 1 changed file with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@
package com.wafflestudio.csereal.core.admissions.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.admissions.api.req.AdmissionReqBody
import com.wafflestudio.csereal.core.admissions.dto.AdmissionsDto
import com.wafflestudio.csereal.core.admissions.type.AdmissionsMainType
import com.wafflestudio.csereal.core.admissions.type.AdmissionsPostType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.Table
import jakarta.persistence.UniqueConstraint

@Entity(name = "admissions")
@Table(
uniqueConstraints = [
UniqueConstraint(columnNames = ["language", "mainType", "postType"])
]
)
class AdmissionsEntity(
val name: String,

@Enumerated(EnumType.STRING)
val language: LanguageType,

@Enumerated(EnumType.STRING)
val mainType: AdmissionsMainType,

@Enumerated(EnumType.STRING)
val postType: AdmissionsPostType,
val pageName: String,

@Column(columnDefinition = "mediumText")
val description: String
) : BaseTimeEntity() {
companion object {
fun of(postType: AdmissionsPostType, pageName: String, admissionsDto: AdmissionsDto): AdmissionsEntity {
return AdmissionsEntity(
postType = postType,
pageName = pageName,
description = admissionsDto.description
)
}
fun of(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
name: String,
admissionsDto: AdmissionsDto
) = AdmissionsEntity(
mainType = mainType,
postType = postType,
name = name,
description = admissionsDto.description,
language = LanguageType.makeStringToLanguageType(admissionsDto.language)
)

fun of(
mainType: AdmissionsMainType,
postType: AdmissionsPostType,
req: AdmissionReqBody
) = AdmissionsEntity(
mainType = mainType,
postType = postType,
name = req.name!!,
description = req.description!!,
language = LanguageType.makeStringToLanguageType(req.language)
)
}
}

0 comments on commit 4d49b2b

Please sign in to comment.