Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-migration-field-staff
Browse files Browse the repository at this point in the history
  • Loading branch information
skfotakf authored Feb 15, 2024
2 parents a4fba42 + d664dc4 commit f642b5b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import com.wafflestudio.csereal.common.properties.LanguageType
import org.springframework.data.jpa.repository.JpaRepository

interface AboutRepository : JpaRepository<AboutEntity, Long> {
fun findAllByLanguageAndPostTypeOrderByName(languageType: LanguageType, postType: AboutPostType): List<AboutEntity>
fun findByLanguageAndPostType(languageType: LanguageType, postType: AboutPostType): AboutEntity
fun findAllByLanguageAndPostTypeOrderByName(
languageType: LanguageType,
postType: AboutPostType
): List<AboutEntity>
fun findByLanguageAndPostType(
languageType: LanguageType,
postType: AboutPostType
): AboutEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ class AcademicsController(

@GetMapping("/{studentType}/courses")
fun readAllCourses(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String
): ResponseEntity<List<CourseDto>> {
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<CourseDto> {
return ResponseEntity.ok(academicsService.readCourse(name))
return ResponseEntity.ok(academicsService.readCourse(language, name))
}

@GetMapping("/undergraduate/general-studies-requirements")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -13,6 +14,8 @@ class AcademicsEntity(

@Enumerated(EnumType.STRING)
var postType: AcademicsPostType,
@Enumerated(EnumType.STRING)
var language: LanguageType,

var name: String,
var description: String,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ 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(
var isDeleted: Boolean = false,

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)
Expand All @@ -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(" ", "-"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CourseEntity, Long> {
fun findAllByStudentTypeOrderByNameAsc(studentType: AcademicsStudentType): List<CourseEntity>
fun findByName(name: String): CourseEntity
fun findAllByLanguageAndStudentTypeOrderByNameAsc(
languageType: LanguageType,
studentType: AcademicsStudentType
): List<CourseEntity>
fun findByLanguageAndName(
languageType: LanguageType,
name: String
): CourseEntity
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,6 +20,7 @@ data class AcademicsDto(
fun of(entity: AcademicsEntity, attachmentResponses: List<AttachmentResponse>): AcademicsDto = entity.run {
AcademicsDto(
id = this.id,
language = LanguageType.makeLowercase(this.language),
name = this.name,
description = this.description,
year = this.year,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,6 +19,7 @@ data class CourseDto(
fun of(entity: CourseEntity, attachmentResponses: List<AttachmentResponse>): CourseDto = entity.run {
CourseDto(
id = this.id,
language = LanguageType.makeLowercase(this.language),
classification = this.classification,
code = this.code,
name = this.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,8 +24,8 @@ interface AcademicsService {
fun readAcademicsYearResponses(studentType: String, postType: String): List<AcademicsYearResponse>
fun readGeneralStudies(): GeneralStudiesPageResponse
fun createCourse(studentType: String, request: CourseDto, attachments: List<MultipartFile>?): CourseDto
fun readAllCourses(studentType: String): List<CourseDto>
fun readCourse(name: String): CourseDto
fun readAllCourses(language: String, studentType: String): List<CourseDto>
fun readCourse(language: String, name: String): CourseDto
fun createScholarshipDetail(studentType: String, request: ScholarshipDto): ScholarshipDto
fun readAllScholarship(studentType: String): ScholarshipPageResponse
fun readScholarship(scholarshipId: Long): ScholarshipDto
Expand All @@ -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)
Expand All @@ -62,7 +63,7 @@ class AcademicsServiceImpl(
academicsSearch = AcademicsSearchEntity.create(this)
}

newAcademics = academicsRepository.save(newAcademics)
academicsRepository.save(newAcademics)

val attachmentResponses = attachmentService.createAttachmentResponses(newAcademics.attachments)

Expand Down Expand Up @@ -113,7 +114,9 @@ class AcademicsServiceImpl(
@Transactional
override fun createCourse(studentType: String, request: CourseDto, attachments: List<MultipartFile>?): 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)
Expand All @@ -123,28 +126,29 @@ class AcademicsServiceImpl(
newCourse.apply {
academicsSearch = AcademicsSearchEntity.create(this)
}

newCourse = courseRepository.save(newCourse)
courseRepository.save(newCourse)

val attachmentResponses = attachmentService.createAttachmentResponses(newCourse.attachments)

return CourseDto.of(newCourse, attachmentResponses)
}

@Transactional(readOnly = true)
override fun readAllCourses(studentType: String): List<CourseDto> {
override fun readAllCourses(language: String, studentType: String): List<CourseDto> {
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)
Expand Down

0 comments on commit f642b5b

Please sign in to comment.