-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Change pagename -> name, add language and mainType column, add …
…unique constraints.
- Loading branch information
Showing
1 changed file
with
43 additions
and
8 deletions.
There are no files selected for viewing
51 changes: 43 additions & 8 deletions
51
src/main/kotlin/com/wafflestudio/csereal/core/admissions/database/AdmissionsEntity.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 |
---|---|---|
@@ -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) | ||
) | ||
} | ||
} |