diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/controller/AttachmentContentEntityType.kt b/src/main/kotlin/com/wafflestudio/csereal/common/controller/AttachmentContentEntityType.kt deleted file mode 100644 index 6972e8e7..00000000 --- a/src/main/kotlin/com/wafflestudio/csereal/common/controller/AttachmentContentEntityType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.wafflestudio.csereal.common.controller - -import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity - -interface AttachmentContentEntityType { - fun bringAttachments(): List -} diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/controller/MainImageContentEntityType.kt b/src/main/kotlin/com/wafflestudio/csereal/common/controller/MainImageContentEntityType.kt deleted file mode 100644 index 0923842a..00000000 --- a/src/main/kotlin/com/wafflestudio/csereal/common/controller/MainImageContentEntityType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.wafflestudio.csereal.common.controller - -import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity - -interface MainImageContentEntityType { - fun bringMainImage(): MainImageEntity? -} diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/entity/AttachmentAttachable.kt b/src/main/kotlin/com/wafflestudio/csereal/common/entity/AttachmentAttachable.kt new file mode 100644 index 00000000..0b92c6e0 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/common/entity/AttachmentAttachable.kt @@ -0,0 +1,7 @@ +package com.wafflestudio.csereal.common.entity + +import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity + +interface AttachmentAttachable { + val attachments: List +} diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/entity/MainImageAttachable.kt b/src/main/kotlin/com/wafflestudio/csereal/common/entity/MainImageAttachable.kt new file mode 100644 index 00000000..6c23ea29 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/common/entity/MainImageAttachable.kt @@ -0,0 +1,7 @@ +package com.wafflestudio.csereal.common.entity + +import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity + +interface MainImageAttachable { + val mainImage: MainImageEntity? +} diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutEntity.kt index 9220090c..625f6086 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutEntity.kt @@ -1,8 +1,8 @@ package com.wafflestudio.csereal.core.about.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.enums.LanguageType import com.wafflestudio.csereal.common.utils.StringListConverter import com.wafflestudio.csereal.common.utils.cleanTextFromHtml @@ -27,17 +27,15 @@ class AboutEntity( var locations: MutableList = mutableListOf(), @OneToMany(mappedBy = "about", cascade = [CascadeType.ALL], orphanRemoval = true) - var attachments: MutableList = mutableListOf(), + override var attachments: MutableList = mutableListOf(), @OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true) - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @Column(columnDefinition = "TEXT") var searchContent: String -) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType { - override fun bringMainImage(): MainImageEntity? = mainImage - override fun bringAttachments(): List = attachments +) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable { companion object { fun of( diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/AcademicsEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/AcademicsEntity.kt index 5515102a..0f306d66 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/AcademicsEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/AcademicsEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.academics.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable import com.wafflestudio.csereal.common.enums.LanguageType import com.wafflestudio.csereal.core.academics.api.req.CreateYearReq import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity @@ -24,13 +24,12 @@ class AcademicsEntity( var year: Int?, @OneToMany(mappedBy = "academics", cascade = [CascadeType.ALL], orphanRemoval = true) - var attachments: MutableList = mutableListOf(), + override var attachments: MutableList = mutableListOf(), @OneToOne(mappedBy = "academics", cascade = [CascadeType.ALL], orphanRemoval = true) var academicsSearch: AcademicsSearchEntity? = null -) : BaseTimeEntity(), AttachmentContentEntityType { - override fun bringAttachments() = attachments +) : BaseTimeEntity(), AttachmentAttachable { companion object { fun createYearResponse( diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilEntity.kt index d0d8c275..0ff8d47e 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.council.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.core.council.dto.ReportCreateRequest import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity import jakarta.persistence.* @@ -17,12 +17,11 @@ class CouncilEntity( var description: String, @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, var sequence: Int, var name: String -) : BaseTimeEntity(), MainImageContentEntityType { - override fun bringMainImage() = mainImage +) : BaseTimeEntity(), MainImageAttachable { companion object { fun createReport(req: ReportCreateRequest): CouncilEntity = diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilFileEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilFileEntity.kt index 4d405d5e..a442f187 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilFileEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/council/database/CouncilFileEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.council.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable import com.wafflestudio.csereal.core.council.type.CouncilFileType import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity import jakarta.persistence.* @@ -20,7 +20,5 @@ class CouncilFileEntity( val key: String, @OneToMany(mappedBy = "councilFile", cascade = [CascadeType.ALL], orphanRemoval = true) - val attachments: MutableList = mutableListOf() -) : BaseTimeEntity(), AttachmentContentEntityType { - override fun bringAttachments(): List = attachments -} + override val attachments: MutableList = mutableListOf() +) : BaseTimeEntity(), AttachmentAttachable diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/ProfessorEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/ProfessorEntity.kt index a2a938ba..521f46bc 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/ProfessorEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/ProfessorEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.member.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.enums.LanguageType import com.wafflestudio.csereal.common.utils.StringListConverter import com.wafflestudio.csereal.core.member.dto.ProfessorDto @@ -48,12 +48,11 @@ class ProfessorEntity( var careers: MutableList = mutableListOf(), @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @OneToOne(mappedBy = "professor", cascade = [CascadeType.ALL], orphanRemoval = true) var memberSearch: MemberSearchEntity? = null -) : BaseTimeEntity(), MainImageContentEntityType { - override fun bringMainImage(): MainImageEntity? = mainImage +) : BaseTimeEntity(), MainImageAttachable { companion object { fun of(languageType: LanguageType, professorDto: ProfessorDto): ProfessorEntity { diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt index 0436b182..a7c0d558 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.member.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.enums.LanguageType import com.wafflestudio.csereal.common.utils.StringListConverter import com.wafflestudio.csereal.core.member.dto.StaffDto @@ -25,12 +25,11 @@ class StaffEntity( var tasks: MutableList = mutableListOf(), @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @OneToOne(mappedBy = "staff", cascade = [CascadeType.ALL], orphanRemoval = true) var memberSearch: MemberSearchEntity? = null -) : BaseTimeEntity(), MainImageContentEntityType { - override fun bringMainImage(): MainImageEntity? = mainImage +) : BaseTimeEntity(), MainImageAttachable { companion object { fun of(languageType: LanguageType, staffDto: StaffDto): StaffEntity { diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsEntity.kt index 34c122f0..c6a3b7b0 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsEntity.kt @@ -1,8 +1,8 @@ package com.wafflestudio.csereal.core.news.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.utils.cleanTextFromHtml import com.wafflestudio.csereal.core.news.dto.NewsDto import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity @@ -31,17 +31,15 @@ class NewsEntity( var importantUntil: LocalDate? = null, @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @OneToMany(mappedBy = "news", cascade = [CascadeType.ALL], orphanRemoval = true) - var attachments: MutableList = mutableListOf(), + override var attachments: MutableList = mutableListOf(), @OneToMany(mappedBy = "news", cascade = [CascadeType.ALL]) var newsTags: MutableSet = mutableSetOf() -) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType { - override fun bringMainImage() = mainImage - override fun bringAttachments() = attachments +) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable { companion object { fun of(newsDto: NewsDto): NewsEntity { diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt index c4839742..5bc559b9 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt @@ -2,7 +2,7 @@ package com.wafflestudio.csereal.core.notice.database import com.wafflestudio.csereal.common.utils.cleanTextFromHtml import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable import com.wafflestudio.csereal.core.notice.dto.NoticeDto import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity import com.wafflestudio.csereal.core.user.database.UserEntity @@ -38,10 +38,9 @@ class NoticeEntity( val author: UserEntity, @OneToMany(mappedBy = "notice", cascade = [CascadeType.ALL], orphanRemoval = true) - var attachments: MutableList = mutableListOf() + override var attachments: MutableList = mutableListOf() -) : BaseTimeEntity(), AttachmentContentEntityType { - override fun bringAttachments() = attachments +) : BaseTimeEntity(), AttachmentAttachable { fun update(updateNoticeRequest: NoticeDto) { // Update plainTextDescription if description is changed diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/recruit/database/RecruitEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/recruit/database/RecruitEntity.kt index 980090c2..e897aa86 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/recruit/database/RecruitEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/recruit/database/RecruitEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.recruit.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity import jakarta.persistence.Column import jakarta.persistence.Entity @@ -15,7 +15,5 @@ class RecruitEntity( var description: String, @OneToOne - var mainImage: MainImageEntity? = null -) : BaseTimeEntity(), MainImageContentEntityType { - override fun bringMainImage(): MainImageEntity? = mainImage -} + override var mainImage: MainImageEntity? = null +) : BaseTimeEntity(), MainImageAttachable diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/research/database/ResearchEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/research/database/ResearchEntity.kt index 7437592f..9ed4409f 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/research/database/ResearchEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/research/database/ResearchEntity.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.research.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.enums.LanguageType import com.wafflestudio.csereal.core.research.dto.ResearchDto import com.wafflestudio.csereal.core.research.type.ResearchType @@ -27,12 +27,11 @@ class ResearchEntity( var labs: MutableSet = mutableSetOf(), @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @OneToOne(mappedBy = "research", cascade = [CascadeType.ALL], orphanRemoval = true) var researchSearch: ResearchSearchEntity? = null -) : BaseTimeEntity(), MainImageContentEntityType { - override fun bringMainImage() = mainImage +) : BaseTimeEntity(), MainImageAttachable { companion object { fun of(languageType: LanguageType, researchDto: ResearchDto): ResearchEntity { diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/resource/attachment/service/AttachmentService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/resource/attachment/service/AttachmentService.kt index d40dc567..b51d0d37 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/resource/attachment/service/AttachmentService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/resource/attachment/service/AttachmentService.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.resource.attachment.service import com.wafflestudio.csereal.common.CserealException -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable import com.wafflestudio.csereal.common.properties.EndpointProperties import com.wafflestudio.csereal.core.about.database.AboutEntity import com.wafflestudio.csereal.core.academics.database.AcademicsEntity @@ -31,7 +31,7 @@ interface AttachmentService { ): AttachmentDto fun uploadAllAttachments( - contentEntityType: AttachmentContentEntityType, + contentEntityType: AttachmentAttachable, requestAttachments: List ): List @@ -80,7 +80,7 @@ class AttachmentServiceImpl( @Transactional override fun uploadAllAttachments( - contentEntityType: AttachmentContentEntityType, + contentEntityType: AttachmentAttachable, requestAttachments: List ): List { Files.createDirectories(Paths.get(path)) @@ -186,7 +186,7 @@ class AttachmentServiceImpl( } } - private fun connectAttachmentToEntity(contentEntity: AttachmentContentEntityType, attachment: AttachmentEntity) { + private fun connectAttachmentToEntity(contentEntity: AttachmentAttachable, attachment: AttachmentEntity) { when (contentEntity) { is NewsEntity -> { contentEntity.attachments.add(attachment) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/resource/mainImage/service/MainImageService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/resource/mainImage/service/MainImageService.kt index 219c883e..d84cbded 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/resource/mainImage/service/MainImageService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/resource/mainImage/service/MainImageService.kt @@ -1,7 +1,7 @@ package com.wafflestudio.csereal.core.resource.mainImage.service import com.wafflestudio.csereal.common.CserealException -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.properties.EndpointProperties import com.wafflestudio.csereal.core.about.database.AboutEntity import com.wafflestudio.csereal.core.council.database.CouncilEntity @@ -27,7 +27,7 @@ import java.nio.file.Paths interface MainImageService { fun uploadMainImage( - contentEntityType: MainImageContentEntityType, + contentEntityType: MainImageAttachable, requestImage: MultipartFile ): MainImageDto @@ -47,7 +47,7 @@ class MainImageServiceImpl( @Transactional override fun uploadMainImage( - contentEntityType: MainImageContentEntityType, + contentEntityType: MainImageAttachable, requestImage: MultipartFile ): MainImageDto { Files.createDirectories(Paths.get(path)) @@ -99,7 +99,7 @@ class MainImageServiceImpl( } // TODO: 각 entity의 interface로 refactoring하기. - private fun connectMainImageToEntity(contentEntity: MainImageContentEntityType, mainImage: MainImageEntity) { + private fun connectMainImageToEntity(contentEntity: MainImageAttachable, mainImage: MainImageEntity) { when (contentEntity) { is NewsEntity -> { contentEntity.mainImage = mainImage diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarEntity.kt index 01f36a51..54a7bbb3 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarEntity.kt @@ -1,8 +1,8 @@ package com.wafflestudio.csereal.core.seminar.database import com.wafflestudio.csereal.common.entity.BaseTimeEntity -import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType -import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.entity.AttachmentAttachable +import com.wafflestudio.csereal.common.entity.MainImageAttachable import com.wafflestudio.csereal.common.utils.cleanTextFromHtml import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity @@ -58,14 +58,12 @@ class SeminarEntity( var plainTextAdditionalNote: String?, @OneToOne - var mainImage: MainImageEntity? = null, + override var mainImage: MainImageEntity? = null, @OneToMany(mappedBy = "seminar", cascade = [CascadeType.ALL], orphanRemoval = true) - var attachments: MutableList = mutableListOf() + override var attachments: MutableList = mutableListOf() -) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType { - override fun bringMainImage(): MainImageEntity? = mainImage - override fun bringAttachments() = attachments +) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable { companion object { fun of(seminarDto: SeminarDto): SeminarEntity {