Skip to content

Commit

Permalink
Refactor: HTML로부터 텍스트 추출 함수 Utils로 이동 (#73)
Browse files Browse the repository at this point in the history
* Feat: Add cleanTextFromHtml.

* Refactor: Remove private clean method, replace to Utils.cleanTextFromHtml.

* Refactor: Remove unused imports.
  • Loading branch information
huGgW authored Sep 6, 2023
1 parent a3e803f commit a3514fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/com/wafflestudio/csereal/common/Utils.kt
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}

0 comments on commit a3514fb

Please sign in to comment.