diff --git a/src/main/kotlin/com/wafflestudio/csereal/common/Utils.kt b/src/main/kotlin/com/wafflestudio/csereal/common/Utils.kt new file mode 100644 index 00000000..0ec330f2 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/csereal/common/Utils.kt @@ -0,0 +1,10 @@ +package com.wafflestudio.csereal.common + +import org.jsoup.Jsoup +import org.jsoup.parser.Parser +import org.jsoup.safety.Safelist + +fun cleanTextFromHtml(description: String): String { + val cleanDescription = Jsoup.clean(description, Safelist.none()) + return Parser.unescapeEntities(cleanDescription, false) +} diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsRepository.kt index e76c838e..bb1d5740 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsRepository.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/news/database/NewsRepository.kt @@ -3,14 +3,12 @@ package com.wafflestudio.csereal.core.news.database import com.querydsl.core.BooleanBuilder import com.querydsl.jpa.impl.JPAQueryFactory import com.wafflestudio.csereal.common.CserealException +import com.wafflestudio.csereal.common.cleanTextFromHtml import com.wafflestudio.csereal.core.news.database.QNewsEntity.newsEntity import com.wafflestudio.csereal.core.news.database.QNewsTagEntity.newsTagEntity import com.wafflestudio.csereal.core.news.dto.NewsSearchDto import com.wafflestudio.csereal.core.news.dto.NewsSearchResponse import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService -import org.jsoup.Jsoup -import org.jsoup.parser.Parser -import org.jsoup.safety.Safelist import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Component @@ -73,7 +71,7 @@ class NewsRepositoryImpl( NewsSearchDto( id = it.id, title = it.title, - description = clean(it.description), + description = cleanTextFromHtml(it.description), createdAt = it.createdAt, tags = it.newsTags.map { newsTagEntity -> newsTagEntity.tag.name }, imageURL = imageURL @@ -136,9 +134,4 @@ class NewsRepositoryImpl( return prevNext } - - private fun clean(description: String): String { - val cleanDescription = Jsoup.clean(description, Safelist.none()) - return Parser.unescapeEntities(cleanDescription, false) - } } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarRepository.kt index c2b0c474..c2f8f0e4 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarRepository.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/seminar/database/SeminarRepository.kt @@ -3,13 +3,11 @@ package com.wafflestudio.csereal.core.seminar.database import com.querydsl.core.BooleanBuilder import com.querydsl.jpa.impl.JPAQueryFactory import com.wafflestudio.csereal.common.CserealException +import com.wafflestudio.csereal.common.cleanTextFromHtml import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService import com.wafflestudio.csereal.core.seminar.database.QSeminarEntity.seminarEntity import com.wafflestudio.csereal.core.seminar.dto.SeminarSearchDto import com.wafflestudio.csereal.core.seminar.dto.SeminarSearchResponse -import org.jsoup.Jsoup -import org.jsoup.parser.Parser -import org.jsoup.safety.Safelist import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Component @@ -78,7 +76,7 @@ class SeminarRepositoryImpl( SeminarSearchDto( id = seminarEntityList[i].id, title = seminarEntityList[i].title, - description = clean(seminarEntityList[i].description), + description = cleanTextFromHtml(seminarEntityList[i].description), name = seminarEntityList[i].name, affiliation = seminarEntityList[i].affiliation, startDate = seminarEntityList[i].startDate, @@ -135,9 +133,4 @@ class SeminarRepositoryImpl( return prevNext } - - private fun clean(description: String): String { - val cleanDescription = Jsoup.clean(description, Safelist.none()) - return Parser.unescapeEntities(cleanDescription, false) - } }