Skip to content

Commit

Permalink
Develope -> Main (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
huGgW authored Mar 16, 2024
1 parent e3fc9d4 commit 1a75aca
Show file tree
Hide file tree
Showing 42 changed files with 390 additions and 193 deletions.
27 changes: 22 additions & 5 deletions src/main/kotlin/com/wafflestudio/csereal/common/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.wafflestudio.csereal.common.utils

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.mockauth.CustomPrincipal
import org.jsoup.Jsoup
import org.jsoup.parser.Parser
import org.jsoup.safety.Safelist
import org.springframework.security.core.Authentication
import org.springframework.security.oauth2.core.oidc.user.OidcUser
import kotlin.math.ceil

fun cleanTextFromHtml(description: String): String {
val cleanDescription = Jsoup.clean(description, Safelist.none())
Expand All @@ -27,15 +32,27 @@ fun substringAroundKeyword(keyword: String, content: String, amount: Int): Pair<
}
}

fun exchangePageNum(pageSize: Int, pageNum: Int, total: Long): Int {
fun exchangeValidPageNum(pageSize: Int, pageNum: Int, total: Long): Int {
// Validate
if (!(pageSize > 0 && pageNum > 0 && total >= 0)) {
throw RuntimeException()
}

return if ((pageNum - 1) * pageSize < total) {
pageNum
} else {
Math.ceil(total.toDouble() / pageSize).toInt()
return when {
total == 0L -> 1
(pageNum - 1) * pageSize < total -> pageNum
else -> ceil(total.toDouble() / pageSize).toInt()
}
}

fun getUsername(authentication: Authentication?): String? {
val principal = authentication?.principal

return principal?.let {
when (principal) {
is OidcUser -> principal.idToken.getClaim("username")
is CustomPrincipal -> principal.userEntity.username
else -> throw CserealException.Csereal401("Unsupported principal type")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AboutController(
@GetMapping("/student-clubs")
fun readAllClubs(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<AboutDto>> {
): ResponseEntity<List<StudentClubDto>> {
return ResponseEntity.ok(aboutService.readAllClubs(language))
}

Expand All @@ -67,8 +67,10 @@ class AboutController(
}

@GetMapping("/future-careers")
fun readFutureCareers(): ResponseEntity<FutureCareersPage> {
return ResponseEntity.ok(aboutService.readFutureCareers())
fun readFutureCareers(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<FutureCareersPage> {
return ResponseEntity.ok(aboutService.readFutureCareers(language))
}

@GetMapping("/search/top")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.querydsl.jpa.impl.JPAQuery
import com.querydsl.jpa.impl.JPAQueryFactory
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.common.repository.CommonRepository
import com.wafflestudio.csereal.common.utils.exchangePageNum
import com.wafflestudio.csereal.common.utils.exchangeValidPageNum
import com.wafflestudio.csereal.core.about.database.QAboutEntity.aboutEntity
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -41,10 +41,8 @@ class AboutCustomRepositoryImpl(
pageNum: Int
): Pair<List<AboutEntity>, Long> {
val total = searchCount(keyword, language)
val validPageNum = exchangePageNum(pageSize, pageNum, total)
val validOffset = (
if (validPageNum >= 1) validPageNum - 1 else 0
) * pageSize.toLong()
val validPageNum = exchangeValidPageNum(pageSize, pageNum, total)
val validOffset = (validPageNum - 1) * pageSize.toLong()

val queryResult = searchQueryExpr(keyword, language)
.offset(validOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,43 @@ package com.wafflestudio.csereal.core.about.dto
import com.fasterxml.jackson.annotation.JsonInclude
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.core.about.database.AboutEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse
import java.time.LocalDateTime

data class StudentClubDto(
@JsonInclude(JsonInclude.Include.NON_NULL)
val id: Long? = null,
val language: String,
val name: String,
val description: String
val engName: String,
val description: String,
val year: Int?,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val locations: List<String>?,
val imageURL: String?,
val attachments: List<AttachmentResponse>?
) {
companion object {
fun of(entity: AboutEntity): StudentClubDto = entity.run {
fun of(
entity: AboutEntity,
name: String,
engName: String,
imageURL: String?,
attachmentResponses: List<AttachmentResponse>
): StudentClubDto = entity.run {
StudentClubDto(
id = this.id,
language = LanguageType.makeLowercase(this.language),
name = this.name!!,
description = this.description
name = name,
engName = engName,
description = this.description,
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
locations = this.locations,
imageURL = imageURL,
attachments = attachmentResponses
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ interface AboutService {
): AboutDto

fun readAbout(language: String, postType: String): AboutDto
fun readAllClubs(language: String): List<AboutDto>
fun readAllClubs(language: String): List<StudentClubDto>
fun readAllFacilities(language: String): List<AboutDto>
fun readAllDirections(language: String): List<AboutDto>
fun readFutureCareers(): FutureCareersPage
fun readFutureCareers(language: String): FutureCareersPage

fun searchTopAbout(
keyword: String,
Expand Down Expand Up @@ -104,17 +104,19 @@ class AboutServiceImpl(
}

@Transactional(readOnly = true)
override fun readAllClubs(language: String): List<AboutDto> {
override fun readAllClubs(language: String): List<StudentClubDto> {
val languageType = LanguageType.makeStringToLanguageType(language)
val clubs =
aboutRepository.findAllByLanguageAndPostTypeOrderByName(
languageType,
AboutPostType.STUDENT_CLUBS
).map {
val name = it.name!!.split("(")[0]
val engName = it.name!!.split("(")[1].replaceFirst(")", "")
val imageURL = mainImageService.createImageURL(it.mainImage)
val attachmentResponses =
attachmentService.createAttachmentResponses(it.attachments)
AboutDto.of(it, imageURL, attachmentResponses)
StudentClubDto.of(it, name, engName, imageURL, attachmentResponses)
}

return clubs
Expand Down Expand Up @@ -154,17 +156,13 @@ class AboutServiceImpl(
}

@Transactional
override fun readFutureCareers(): FutureCareersPage {
val description = "컴퓨터공학을 전공함으로써 벤처기업을 창업할 수 있을 뿐 " +
"아니라 시스템엔지니어, 보안전문가, 소프트웨어개발자, 데이터베이스관리자 등 " +
"많은 IT 전문 분야로의 진출이 가능하다. 또한 컴퓨터공학은 바이오, 전자전기, " +
"로봇, 기계, 의료 등 이공계 영역뿐만 아니라 정치, 경제, 사회, 문화의 다양한 분야와 " +
"결합되어 미래 지식정보사회에 대한 새로운 가능성을 제시하고 있고 새로운 학문적 과제가 " +
"지속적으로 생산되기 때문에 많은 전문연구인력이 필요하다.\n" +
"\n" +
"서울대학교 컴퓨터공학부의 경우 학부 졸업생 절반 이상이 대학원에 진학하고 있다. " +
"대학원에 진학하면 여러 전공분야 중 하나를 선택하여 보다 깊이 있는 지식의 습득과 연구과정을 거치게 되며 " +
"그 이후로는 국내외 관련 산업계, 학계에 주로 진출하고 있고, 새로운 아이디어로 벤처기업을 창업하기도 한다."
override fun readFutureCareers(language: String): FutureCareersPage {
val languageType = LanguageType.makeStringToLanguageType(language)
val description =
aboutRepository.findByLanguageAndPostType(
languageType,
AboutPostType.FUTURE_CAREERS
).description

val statList = mutableListOf<FutureCareersStatDto>()
for (i: Int in 2021 downTo 2011) {
Expand Down Expand Up @@ -342,7 +340,8 @@ class AboutServiceImpl(

for (request in requestList) {
val language = request.language
val name = request.name
val name = request.name.split("(")[0]
val engName = request.name.split("(")[1].replaceFirst(")", "")

val aboutDto = AboutDto(
id = null,
Expand All @@ -363,7 +362,7 @@ class AboutServiceImpl(
syncSearchOfAbout(newAbout)
newAbout = aboutRepository.save(newAbout)

list.add(StudentClubDto.of(newAbout))
list.add(StudentClubDto.of(newAbout, name, engName, null, listOf()))
}
return list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class AcademicsController(
return ResponseEntity.ok(academicsService.readGuide(language, studentType))
}

@GetMapping("/undergraduate/general-studies-requirements")
fun readGeneralStudiesRequirements(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<GeneralStudiesRequirementsPageResponse> {
return ResponseEntity.ok(academicsService.readGeneralStudiesRequirements(language))
}

@GetMapping("/{studentType}/{postType}")
fun readAcademicsYearResponses(
@RequestParam(required = false, defaultValue = "ko") language: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package com.wafflestudio.csereal.core.academics.api.res
import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.common.utils.substringAroundKeyword
import com.wafflestudio.csereal.core.academics.database.AcademicsPostType
import com.wafflestudio.csereal.core.academics.database.AcademicsSearchEntity
import com.wafflestudio.csereal.core.academics.database.AcademicsSearchType
import com.wafflestudio.csereal.core.academics.database.AcademicsStudentType

data class AcademicsSearchResElement(
val id: Long,
val language: String,
val name: String,
val academicsType: AcademicsSearchType,
val postType: AcademicsSearchType,
val studentType: AcademicsStudentType? = null,
val academicType: AcademicsPostType? = null,
val partialDescription: String,
val boldStartIndex: Int,
val boldEndIndex: Int
Expand All @@ -30,17 +34,21 @@ data class AcademicsSearchResElement(
academicsSearch.content,
amount
)
AcademicsSearchResElement(
id = academicsSearch.academics!!.id,
name = academicsSearch.academics!!.name,
language = academicsSearch.academics!!.language.let {
LanguageType.makeLowercase(it)
},
academicsType = AcademicsSearchType.ACADEMICS,
partialDescription = partialDescription.replace("\n", " "),
boldStartIndex = startIdx ?: 0,
boldEndIndex = startIdx?.plus(keyword.length) ?: 0
)
academicsSearch.academics!!.let {
AcademicsSearchResElement(
id = it.id,
name = it.name,
language = it.language.let { lan ->
LanguageType.makeLowercase(lan)
},
postType = AcademicsSearchType.ACADEMICS,
academicType = it.postType,
studentType = it.studentType,
partialDescription = partialDescription.replace("\n", " "),
boldStartIndex = startIdx ?: 0,
boldEndIndex = startIdx?.plus(keyword.length) ?: 0
)
}
}

academicsSearch.academics == null &&
Expand All @@ -57,7 +65,7 @@ data class AcademicsSearchResElement(
language = academicsSearch.course!!.language.let {
LanguageType.makeLowercase(it)
},
academicsType = AcademicsSearchType.COURSE,
postType = AcademicsSearchType.COURSE,
partialDescription = partialDescription.replace("\n", " "),
boldStartIndex = startIdx ?: 0,
boldEndIndex = startIdx?.plus(keyword.length) ?: 0
Expand All @@ -78,7 +86,7 @@ data class AcademicsSearchResElement(
language = academicsSearch.scholarship!!.language.let {
LanguageType.makeLowercase(it)
},
academicsType = AcademicsSearchType.SCHOLARSHIP,
postType = AcademicsSearchType.SCHOLARSHIP,
partialDescription = partialDescription.replace("\n", " "),
boldStartIndex = startIdx ?: 0,
boldEndIndex = startIdx?.plus(keyword.length) ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ package com.wafflestudio.csereal.core.academics.database
enum class AcademicsPostType {
GUIDE, GENERAL_STUDIES_REQUIREMENTS, GENERAL_STUDIES_REQUIREMENTS_SUBJECT_CHANGES,
CURRICULUM, DEGREE_REQUIREMENTS, DEGREE_REQUIREMENTS_YEAR_LIST, COURSE_CHANGES, SCHOLARSHIP;

// GUIDE: 학부 안내
// GENERAL_STUDIES_REQUIREMENTS: 필수 교양 과목
// CURRICULUM: 전공 이수 표준 형태
// DEGREE_REQUIREMENTS: 졸업 규정
// COURSE_CHANGES: 교과목 변경 내역
// SCHOLARSHIP: 장학 제도
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ interface AcademicsRepository : JpaRepository<AcademicsEntity, Long> {
studentType: AcademicsStudentType,
postType: AcademicsPostType
): AcademicsEntity
fun findByLanguageAndStudentTypeAndPostTypeAndYear(
languageType: LanguageType,
studentType: AcademicsStudentType,
postType: AcademicsPostType,
year: Int?
): AcademicsEntity
fun findAllByLanguageAndStudentTypeAndPostTypeOrderByYearDesc(
languageType: LanguageType,
studentType: AcademicsStudentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.querydsl.jpa.impl.JPAQuery
import com.querydsl.jpa.impl.JPAQueryFactory
import com.wafflestudio.csereal.common.properties.LanguageType
import com.wafflestudio.csereal.common.repository.CommonRepository
import com.wafflestudio.csereal.common.utils.exchangePageNum
import com.wafflestudio.csereal.common.utils.exchangeValidPageNum
import com.wafflestudio.csereal.core.academics.database.QAcademicsEntity.academicsEntity
import com.wafflestudio.csereal.core.academics.database.QAcademicsSearchEntity.academicsSearchEntity
import com.wafflestudio.csereal.core.academics.database.QCourseEntity.courseEntity
Expand Down Expand Up @@ -37,8 +37,8 @@ class AcademicsSearchCustomRepositoryImpl(
val query = searchQuery(keyword, language)
val total = getSearchCount(keyword, language)

val validPageNum = exchangePageNum(pageSize, pageNum, total)
val validOffset = (if (validPageNum >= 1) validPageNum - 1 else 0) * pageSize.toLong()
val validPageNum = exchangeValidPageNum(pageSize, pageNum, total)
val validOffset = (validPageNum - 1) * pageSize.toLong()

val queryResult = query.offset(validOffset)
.limit(pageSize.toLong())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.wafflestudio.csereal.core.academics.dto

import com.wafflestudio.csereal.core.academics.database.AcademicsEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse

class DegreeRequirementsDto(
val year: Int,
val description: String
val attachments: List<AttachmentResponse>

) {
companion object {
fun of(entity: AcademicsEntity) = entity.run {
fun of(entity: AcademicsEntity, attachments: List<AttachmentResponse>) = entity.run {
DegreeRequirementsDto(
year = this.year!!,
description = this.description
attachments = attachments
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class DegreeRequirementsPageResponse(
val yearList: List<DegreeRequirementsDto>
) {
companion object {
fun of(entity: AcademicsEntity, yearList: List<AcademicsEntity>) = entity.run {
fun of(entity: AcademicsEntity, yearList: List<DegreeRequirementsDto>) = entity.run {
DegreeRequirementsPageResponse(
description = this.description,
yearList = yearList.map { DegreeRequirementsDto.of(it) }
yearList = yearList
)
}
}
Expand Down
Loading

0 comments on commit 1a75aca

Please sign in to comment.