From d664dc46131687e27dec9d0943656af575c710a9 Mon Sep 17 00:00:00 2001 From: Jo Seonggyu Date: Sun, 11 Feb 2024 15:42:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20academics=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EC=97=90=20language=20field=20=EC=B6=94=EA=B0=80=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 엔티티, dto에 language 추가 * feat: read에 language 추가 * feat: academics에 language field 추가 * fix: ktlint 수정 * feat: course 엔티티에 language field 추가 * feat: readCourse에 language parameter 추가 * fix: languageRepository 삭제, 함수 enum 클래스 이동, academicsEntity name 속성 nullable 추가 * fix: requestParam+defaultValue 추가, * fix: academics name nullable 없앰 --- .../core/about/database/AboutRepository.kt | 10 ++++-- .../core/academics/api/AcademicsController.kt | 6 ++-- .../academics/database/AcademicsEntity.kt | 5 +++ .../core/academics/database/CourseEntity.kt | 17 ++++----- .../academics/database/CourseRepository.kt | 11 ++++-- .../core/academics/dto/AcademicsDto.kt | 3 ++ .../csereal/core/academics/dto/CourseDto.kt | 3 ++ .../academics/service/AcademicsService.kt | 36 ++++++++++--------- 8 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutRepository.kt index 3790bce0..b98a26fd 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutRepository.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutRepository.kt @@ -4,6 +4,12 @@ import com.wafflestudio.csereal.common.properties.LanguageType import org.springframework.data.jpa.repository.JpaRepository interface AboutRepository : JpaRepository { - fun findAllByLanguageAndPostTypeOrderByName(languageType: LanguageType, postType: AboutPostType): List - fun findByLanguageAndPostType(languageType: LanguageType, postType: AboutPostType): AboutEntity + fun findAllByLanguageAndPostTypeOrderByName( + languageType: LanguageType, + postType: AboutPostType + ): List + fun findByLanguageAndPostType( + languageType: LanguageType, + postType: AboutPostType + ): AboutEntity } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/AcademicsController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/AcademicsController.kt index 6fe51849..55df6ce2 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/AcademicsController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/api/AcademicsController.kt @@ -59,16 +59,18 @@ class AcademicsController( @GetMapping("/{studentType}/courses") fun readAllCourses( + @RequestParam(required = false, defaultValue = "ko") language: String, @PathVariable studentType: String ): ResponseEntity> { - return ResponseEntity.ok(academicsService.readAllCourses(studentType)) + return ResponseEntity.ok(academicsService.readAllCourses(language, studentType)) } @GetMapping("/course") fun readCourse( + @RequestParam(required = false, defaultValue = "ko") language: String, @RequestParam name: String ): ResponseEntity { - return ResponseEntity.ok(academicsService.readCourse(name)) + return ResponseEntity.ok(academicsService.readCourse(language, name)) } @GetMapping("/undergraduate/general-studies-requirements") 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 f3861445..e5e55b91 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 @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.academics.database import com.wafflestudio.csereal.common.config.BaseTimeEntity import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.academics.dto.AcademicsDto import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity import jakarta.persistence.* @@ -13,6 +14,8 @@ class AcademicsEntity( @Enumerated(EnumType.STRING) var postType: AcademicsPostType, + @Enumerated(EnumType.STRING) + var language: LanguageType, var name: String, var description: String, @@ -32,11 +35,13 @@ class AcademicsEntity( fun of( studentType: AcademicsStudentType, postType: AcademicsPostType, + languageType: LanguageType, academicsDto: AcademicsDto ): AcademicsEntity { return AcademicsEntity( studentType = studentType, postType = postType, + language = languageType, name = academicsDto.name, description = academicsDto.description, year = academicsDto.year, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseEntity.kt index baa4769c..792c0507 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseEntity.kt @@ -2,12 +2,10 @@ package com.wafflestudio.csereal.core.academics.database import com.wafflestudio.csereal.common.config.BaseTimeEntity import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.academics.dto.CourseDto import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity -import jakarta.persistence.CascadeType -import jakarta.persistence.Entity -import jakarta.persistence.OneToMany -import jakarta.persistence.OneToOne +import jakarta.persistence.* @Entity(name = "course") class CourseEntity( @@ -15,16 +13,14 @@ class CourseEntity( var studentType: AcademicsStudentType, - var classification: String, + @Enumerated(EnumType.STRING) + var language: LanguageType, + var classification: String, var code: String, - var name: String, - var credit: Int, - var grade: String, - var description: String?, @OneToMany(mappedBy = "course", cascade = [CascadeType.ALL], orphanRemoval = true) @@ -36,9 +32,10 @@ class CourseEntity( ) : BaseTimeEntity(), AttachmentContentEntityType { override fun bringAttachments() = attachments companion object { - fun of(studentType: AcademicsStudentType, courseDto: CourseDto): CourseEntity { + fun of(studentType: AcademicsStudentType, languageType: LanguageType, courseDto: CourseDto): CourseEntity { return CourseEntity( studentType = studentType, + language = languageType, classification = courseDto.classification, code = courseDto.code, name = courseDto.name.replace(" ", "-"), diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseRepository.kt index 3ed6f69e..c48ec048 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseRepository.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/database/CourseRepository.kt @@ -1,8 +1,15 @@ package com.wafflestudio.csereal.core.academics.database +import com.wafflestudio.csereal.common.properties.LanguageType import org.springframework.data.jpa.repository.JpaRepository interface CourseRepository : JpaRepository { - fun findAllByStudentTypeOrderByNameAsc(studentType: AcademicsStudentType): List - fun findByName(name: String): CourseEntity + fun findAllByLanguageAndStudentTypeOrderByNameAsc( + languageType: LanguageType, + studentType: AcademicsStudentType + ): List + fun findByLanguageAndName( + languageType: LanguageType, + name: String + ): CourseEntity } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/AcademicsDto.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/AcademicsDto.kt index 448a0632..1530c621 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/AcademicsDto.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/AcademicsDto.kt @@ -1,11 +1,13 @@ package com.wafflestudio.csereal.core.academics.dto +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.academics.database.AcademicsEntity import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse import java.time.LocalDateTime data class AcademicsDto( val id: Long = -1, // TODO: Seperate to multiple DTOs or set this as nullable + val language: String, val name: String, val description: String, val year: Int? = null, @@ -18,6 +20,7 @@ data class AcademicsDto( fun of(entity: AcademicsEntity, attachmentResponses: List): AcademicsDto = entity.run { AcademicsDto( id = this.id, + language = LanguageType.makeLowercase(this.language), name = this.name, description = this.description, year = this.year, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/CourseDto.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/CourseDto.kt index dedc13f6..e1f680fc 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/CourseDto.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/dto/CourseDto.kt @@ -1,10 +1,12 @@ package com.wafflestudio.csereal.core.academics.dto +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.academics.database.CourseEntity import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse data class CourseDto( val id: Long, + val language: String, val classification: String, val code: String, val name: String, @@ -17,6 +19,7 @@ data class CourseDto( fun of(entity: CourseEntity, attachmentResponses: List): CourseDto = entity.run { CourseDto( id = this.id, + language = LanguageType.makeLowercase(this.language), classification = this.classification, code = this.code, name = this.name, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt index 7ee322cf..176d5b8b 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/academics/service/AcademicsService.kt @@ -1,6 +1,7 @@ package com.wafflestudio.csereal.core.academics.service import com.wafflestudio.csereal.common.CserealException +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.academics.database.* import com.wafflestudio.csereal.core.academics.dto.* import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService @@ -23,8 +24,8 @@ interface AcademicsService { fun readAcademicsYearResponses(studentType: String, postType: String): List fun readGeneralStudies(): GeneralStudiesPageResponse fun createCourse(studentType: String, request: CourseDto, attachments: List?): CourseDto - fun readAllCourses(studentType: String): List - fun readCourse(name: String): CourseDto + fun readAllCourses(language: String, studentType: String): List + fun readCourse(language: String, name: String): CourseDto fun createScholarshipDetail(studentType: String, request: ScholarshipDto): ScholarshipDto fun readAllScholarship(studentType: String): ScholarshipPageResponse fun readScholarship(scholarshipId: Long): ScholarshipDto @@ -50,8 +51,8 @@ class AcademicsServiceImpl( ): AcademicsDto { val enumStudentType = makeStringToAcademicsStudentType(studentType) val enumPostType = makeStringToAcademicsPostType(postType) - - var newAcademics = AcademicsEntity.of(enumStudentType, enumPostType, request) + val enumLanguageType = LanguageType.makeStringToLanguageType(request.language) + val newAcademics = AcademicsEntity.of(enumStudentType, enumPostType, enumLanguageType, request) if (attachments != null) { attachmentService.uploadAllAttachments(newAcademics, attachments) @@ -62,7 +63,7 @@ class AcademicsServiceImpl( academicsSearch = AcademicsSearchEntity.create(this) } - newAcademics = academicsRepository.save(newAcademics) + academicsRepository.save(newAcademics) val attachmentResponses = attachmentService.createAttachmentResponses(newAcademics.attachments) @@ -113,7 +114,9 @@ class AcademicsServiceImpl( @Transactional override fun createCourse(studentType: String, request: CourseDto, attachments: List?): CourseDto { val enumStudentType = makeStringToAcademicsStudentType(studentType) - var newCourse = CourseEntity.of(enumStudentType, request) + val enumLanguageType = LanguageType.makeStringToLanguageType(request.language) + + val newCourse = CourseEntity.of(enumStudentType, enumLanguageType, request) if (attachments != null) { attachmentService.uploadAllAttachments(newCourse, attachments) @@ -123,8 +126,7 @@ class AcademicsServiceImpl( newCourse.apply { academicsSearch = AcademicsSearchEntity.create(this) } - - newCourse = courseRepository.save(newCourse) + courseRepository.save(newCourse) val attachmentResponses = attachmentService.createAttachmentResponses(newCourse.attachments) @@ -132,19 +134,21 @@ class AcademicsServiceImpl( } @Transactional(readOnly = true) - override fun readAllCourses(studentType: String): List { + override fun readAllCourses(language: String, studentType: String): List { val enumStudentType = makeStringToAcademicsStudentType(studentType) - - val courseDtoList = courseRepository.findAllByStudentTypeOrderByNameAsc(enumStudentType).map { - val attachmentResponses = attachmentService.createAttachmentResponses(it.attachments) - CourseDto.of(it, attachmentResponses) - } + val enumLanguageType = LanguageType.makeStringToLanguageType(language) + val courseDtoList = + courseRepository.findAllByLanguageAndStudentTypeOrderByNameAsc(enumLanguageType, enumStudentType).map { + val attachmentResponses = attachmentService.createAttachmentResponses(it.attachments) + CourseDto.of(it, attachmentResponses) + } return courseDtoList } @Transactional(readOnly = true) - override fun readCourse(name: String): CourseDto { - val course = courseRepository.findByName(name) + override fun readCourse(language: String, name: String): CourseDto { + val enumLanguageType = LanguageType.makeStringToLanguageType(language) + val course = courseRepository.findByLanguageAndName(enumLanguageType, name) val attachmentResponses = attachmentService.createAttachmentResponses(course.attachments) return CourseDto.of(course, attachmentResponses)