Skip to content

Refactor: MainImage, Attachments interface 간결화, 패키지 이동 #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.common.entity

import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity

interface AttachmentAttachable {
val attachments: List<AttachmentEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.common.entity

import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity

interface MainImageAttachable {
val mainImage: MainImageEntity?
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,17 +27,15 @@ class AboutEntity(
var locations: MutableList<String> = mutableListOf(),

@OneToMany(mappedBy = "about", cascade = [CascadeType.ALL], orphanRemoval = true)
var attachments: MutableList<AttachmentEntity> = mutableListOf(),
override var attachments: MutableList<AttachmentEntity> = 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<AttachmentEntity> = attachments
) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable {

companion object {
fun of(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,13 +24,12 @@ class AcademicsEntity(
var year: Int?,

@OneToMany(mappedBy = "academics", cascade = [CascadeType.ALL], orphanRemoval = true)
var attachments: MutableList<AttachmentEntity> = mutableListOf(),
override var attachments: MutableList<AttachmentEntity> = 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -20,7 +20,5 @@ class CouncilFileEntity(
val key: String,

@OneToMany(mappedBy = "councilFile", cascade = [CascadeType.ALL], orphanRemoval = true)
val attachments: MutableList<AttachmentEntity> = mutableListOf()
) : BaseTimeEntity(), AttachmentContentEntityType {
override fun bringAttachments(): List<AttachmentEntity> = attachments
}
override val attachments: MutableList<AttachmentEntity> = mutableListOf()
) : BaseTimeEntity(), AttachmentAttachable
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -48,12 +48,11 @@ class ProfessorEntity(
var careers: MutableList<String> = 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,12 +25,11 @@ class StaffEntity(
var tasks: MutableList<String> = 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<AttachmentEntity> = mutableListOf(),
override var attachments: MutableList<AttachmentEntity> = mutableListOf(),

@OneToMany(mappedBy = "news", cascade = [CascadeType.ALL])
var newsTags: MutableSet<NewsTagEntity> = mutableSetOf()

) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType {
override fun bringMainImage() = mainImage
override fun bringAttachments() = attachments
) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable {

companion object {
fun of(newsDto: NewsDto): NewsEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,10 +38,9 @@ class NoticeEntity(
val author: UserEntity,

@OneToMany(mappedBy = "notice", cascade = [CascadeType.ALL], orphanRemoval = true)
var attachments: MutableList<AttachmentEntity> = mutableListOf()
override var attachments: MutableList<AttachmentEntity> = mutableListOf()

) : BaseTimeEntity(), AttachmentContentEntityType {
override fun bringAttachments() = attachments
) : BaseTimeEntity(), AttachmentAttachable {

fun update(updateNoticeRequest: NoticeDto) {
// Update plainTextDescription if description is changed
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,12 +27,11 @@ class ResearchEntity(
var labs: MutableSet<LabEntity> = 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,7 +31,7 @@ interface AttachmentService {
): AttachmentDto

fun uploadAllAttachments(
contentEntityType: AttachmentContentEntityType,
contentEntityType: AttachmentAttachable,
requestAttachments: List<MultipartFile>
): List<AttachmentDto>

Expand Down Expand Up @@ -80,7 +80,7 @@ class AttachmentServiceImpl(

@Transactional
override fun uploadAllAttachments(
contentEntityType: AttachmentContentEntityType,
contentEntityType: AttachmentAttachable,
requestAttachments: List<MultipartFile>
): List<AttachmentDto> {
Files.createDirectories(Paths.get(path))
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,7 +27,7 @@ import java.nio.file.Paths

interface MainImageService {
fun uploadMainImage(
contentEntityType: MainImageContentEntityType,
contentEntityType: MainImageAttachable,
requestImage: MultipartFile
): MainImageDto

Expand All @@ -47,7 +47,7 @@ class MainImageServiceImpl(

@Transactional
override fun uploadMainImage(
contentEntityType: MainImageContentEntityType,
contentEntityType: MainImageAttachable,
requestImage: MultipartFile
): MainImageDto {
Files.createDirectories(Paths.get(path))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<AttachmentEntity> = mutableListOf()
override var attachments: MutableList<AttachmentEntity> = mutableListOf()

) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType {
override fun bringMainImage(): MainImageEntity? = mainImage
override fun bringAttachments() = attachments
) : BaseTimeEntity(), MainImageAttachable, AttachmentAttachable {

companion object {
fun of(seminarDto: SeminarDto): SeminarEntity {
Expand Down
Loading