Skip to content

Commit

Permalink
Merge pull request #305 from wafflestudio/develop
Browse files Browse the repository at this point in the history
Merge develop to prod
  • Loading branch information
huGgW authored Aug 11, 2024
2 parents 45ddd2c + 8ddf8c5 commit cbf5717
Show file tree
Hide file tree
Showing 42 changed files with 1,009 additions and 377 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.core.academics.api.req

data class CreateYearReq(
val year: Int,
val name: String,
val description: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wafflestudio.csereal.core.academics.api.req

data class UpdateYearReq(
val description: String
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.wafflestudio.csereal.core.academics.api
package com.wafflestudio.csereal.core.academics.api.v1

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.academics.api.req.CreateYearReq
import com.wafflestudio.csereal.core.academics.api.req.UpdateSingleReq
import com.wafflestudio.csereal.core.academics.api.req.UpdateYearReq
import com.wafflestudio.csereal.core.academics.dto.*
import com.wafflestudio.csereal.core.academics.service.AcademicsService
import com.wafflestudio.csereal.core.academics.dto.ScholarshipDto
Expand All @@ -14,25 +16,11 @@ import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RequestMapping("/api/v1/academics")
@RestController
@RestController("AcademicsControllerV1")
class AcademicsController(
private val academicsService: AcademicsService,
private val academicsSearchService: AcademicsSearchService
) {
@AuthenticatedStaff
@PostMapping("/{studentType}/{postType}")
fun createAcademics(
@PathVariable studentType: String,
@PathVariable postType: String,
@Valid
@RequestPart("request")
request: AcademicsDto,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(
academicsService.createAcademics(studentType, postType, request, attachments)
)
}

@GetMapping("/{studentType}/guide")
fun readGuide(
Expand Down Expand Up @@ -69,18 +57,35 @@ class AcademicsController(
)
}

//교과목 정보
@AuthenticatedStaff
@PostMapping("/{studentType}/course")
fun createCourse(
@PostMapping("/{studentType}/{postType}")
fun createAcademicsYearResponse(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String,
@Valid
@RequestPart("request")
request: CourseDto,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<CourseDto> {
return ResponseEntity.ok(academicsService.createCourse(studentType, request, attachments))
}
@PathVariable postType: String,
@RequestBody request: CreateYearReq
) = academicsService.createAcademicsYearResponse(language, studentType, postType, request)

@AuthenticatedStaff
@PutMapping("/{studentType}/{postType}/{year}")
fun updateAcademicsYearResponse(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String,
@PathVariable postType: String,
@PathVariable year: Int,
@RequestBody request: UpdateYearReq
) = academicsService.updateAcademicsYearResponse(language, studentType, postType, year, request)

@AuthenticatedStaff
@DeleteMapping("/{studentType}/{postType}/{year}")
fun deleteAcademicsYearResponse(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String,
@PathVariable postType: String,
@PathVariable year: Int
) = academicsService.deleteAcademicsYearResponse(language, studentType, postType, year)

//교과목 정보

@GetMapping("/{studentType}/courses")
fun readAllCourses(
Expand All @@ -90,14 +95,6 @@ class AcademicsController(
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(language, name))
}

@GetMapping("/undergraduate/degree-requirements")
fun readDegreeRequirements(
@RequestParam(required = false, defaultValue = "ko") language: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.wafflestudio.csereal.core.academics.api.v2

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.core.academics.dto.GroupedCourseDto
import com.wafflestudio.csereal.core.academics.service.AcademicsService
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*

@RequestMapping("/api/v2/academics")
@RestController
class AcademicsController(
private val academicsService: AcademicsService
) {
@AuthenticatedStaff
@PostMapping("/courses")
fun createCourse(
@Valid
@RequestBody
request: GroupedCourseDto
) = academicsService.createCourse(request)

@GetMapping("/courses")
fun readAllGroupedCourses(@RequestParam studentType: String): List<GroupedCourseDto> =
academicsService.readAllGroupedCourses(studentType)

@AuthenticatedStaff
@PutMapping("/courses")
fun updateCourse(@RequestBody updateRequest: GroupedCourseDto) = academicsService.updateCourse(updateRequest)

@AuthenticatedStaff
@DeleteMapping("/courses/{code}")
fun deleteCourse(@PathVariable code: String) = academicsService.deleteCourse(code)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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.enums.LanguageType
import com.wafflestudio.csereal.core.academics.dto.AcademicsDto
import com.wafflestudio.csereal.core.academics.api.req.CreateYearReq
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.*

Expand Down Expand Up @@ -33,19 +33,19 @@ class AcademicsEntity(
override fun bringAttachments() = attachments

companion object {
fun of(
fun createYearResponse(
studentType: AcademicsStudentType,
postType: AcademicsPostType,
languageType: LanguageType,
academicsDto: AcademicsDto
request: CreateYearReq
): AcademicsEntity {
return AcademicsEntity(
studentType = studentType,
postType = postType,
language = languageType,
name = academicsDto.name,
description = academicsDto.description,
year = academicsDto.year
name = request.name,
description = request.description,
year = request.year
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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;

// GUIDE: 학부 안내
// GUIDE: 학부/대학원 안내
// GENERAL_STUDIES_REQUIREMENTS: 필수 교양 과목
// CURRICULUM: 전공 이수 표준 형태
// DEGREE_REQUIREMENTS: 졸업 규정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ interface AcademicsRepository : JpaRepository<AcademicsEntity, Long> {
languageType: LanguageType,
studentType: AcademicsStudentType,
postType: AcademicsPostType
): AcademicsEntity
): AcademicsEntity?

fun findByLanguageAndStudentTypeAndPostTypeAndYear(
languageType: LanguageType,
studentType: AcademicsStudentType,
postType: AcademicsPostType,
year: Int?
): AcademicsEntity
): AcademicsEntity?

fun findAllByLanguageAndStudentTypeAndPostTypeOrderByYearDesc(
languageType: LanguageType,
studentType: AcademicsStudentType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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.enums.LanguageType
import com.wafflestudio.csereal.core.academics.dto.CourseDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.*

@Entity(name = "course")
class CourseEntity(
var isDeleted: Boolean = false,

@Enumerated(EnumType.STRING)
var studentType: AcademicsStudentType,

@Enumerated(EnumType.STRING)
Expand All @@ -20,30 +16,36 @@ class CourseEntity(
var code: String,
var name: String,
var credit: Int,
var grade: String,
var grade: Int,

@Column(columnDefinition = "mediumText")
var description: String?,

@OneToMany(mappedBy = "course", cascade = [CascadeType.ALL], orphanRemoval = true)
var attachments: MutableList<AttachmentEntity> = mutableListOf(),

@OneToOne(mappedBy = "course", cascade = [CascadeType.ALL], orphanRemoval = true)
var academicsSearch: AcademicsSearchEntity? = null

) : BaseTimeEntity(), AttachmentContentEntityType {
override fun bringAttachments() = attachments
) : BaseTimeEntity() {

companion object {
fun of(studentType: AcademicsStudentType, languageType: LanguageType, courseDto: CourseDto): CourseEntity {
fun of(
studentType: AcademicsStudentType,
languageType: LanguageType,
classification: String,
code: String,
name: String,
credit: Int,
grade: Int,
description: String?
): CourseEntity {
return CourseEntity(
studentType = studentType,
language = languageType,
classification = courseDto.classification,
code = courseDto.code,
name = courseDto.name,
credit = courseDto.credit,
grade = courseDto.grade,
description = courseDto.description
classification = classification,
code = code,
name = name,
credit = credit,
grade = grade,
description = description
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,49 @@ package com.wafflestudio.csereal.core.academics.database

import com.wafflestudio.csereal.common.enums.LanguageType
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface CourseRepository : JpaRepository<CourseEntity, Long> {
interface CourseProjection {
val code: String
val credit: Int
val grade: Int
val studentType: String
val koName: String
val koDescription: String
val koClassification: String
val enName: String
val enDescription: String
val enClassification: String
}

fun findAllByLanguageAndStudentTypeOrderByNameAsc(
languageType: LanguageType,
studentType: AcademicsStudentType
): List<CourseEntity>
fun findByLanguageAndName(
languageType: LanguageType,
name: String
): CourseEntity

@Query(
"""
SELECT
c.code as code,
MAX(c.credit) as credit,
MAX(c.grade) as grade,
MAX(c.studentType) as studentType,
MAX(CASE WHEN c.language = 'KO' THEN c.name ELSE '' END) as koName,
MAX(CASE WHEN c.language = 'KO' THEN c.description ELSE '' END) as koDescription,
MAX(CASE WHEN c.language = 'KO' THEN c.classification ELSE '' END) as koClassification,
MAX(CASE WHEN c.language = 'EN' THEN c.name ELSE '' END) as enName,
MAX(CASE WHEN c.language = 'EN' THEN c.description ELSE '' END) as enDescription,
MAX(CASE WHEN c.language = 'EN' THEN c.classification ELSE '' END) as enClassification
FROM course c
WHERE c.studentType = :studentType
GROUP BY c.code
"""
)
fun findGroupedCourses(@Param("studentType") studentType: AcademicsStudentType): List<CourseProjection>

fun existsByCode(code: String): Boolean
fun findByCodeAndLanguage(code: String, language: LanguageType): CourseEntity?
fun deleteAllByCode(code: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.wafflestudio.csereal.core.academics.dto

import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.academics.database.CourseEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse

data class CourseDto(
val id: Long,
Expand All @@ -11,12 +10,11 @@ data class CourseDto(
val code: String,
val name: String,
val credit: Int,
val grade: String,
val description: String?,
val attachments: List<AttachmentResponse>?
val grade: Int,
val description: String?
) {
companion object {
fun of(entity: CourseEntity, attachmentResponses: List<AttachmentResponse>): CourseDto = entity.run {
fun of(entity: CourseEntity): CourseDto = entity.run {
CourseDto(
id = this.id,
language = LanguageType.makeLowercase(this.language),
Expand All @@ -25,8 +23,7 @@ data class CourseDto(
name = this.name,
credit = this.credit,
grade = this.grade,
description = this.description,
attachments = attachmentResponses
description = this.description
)
}
}
Expand Down
Loading

0 comments on commit cbf5717

Please sign in to comment.