Skip to content

Commit

Permalink
Merge pull request #325 from wafflestudio/develop
Browse files Browse the repository at this point in the history
prod deploy
  • Loading branch information
huGgW authored Oct 30, 2024
2 parents facc71f + b95d057 commit ee71b91
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.wafflestudio.csereal.core.about.api.req

data class CreateFacReq(
val ko: FacDto,
val en: FacDto
)
import com.wafflestudio.csereal.core.about.dto.FacReq

data class FacDto(
val name: String,
val description: String,
val locations: MutableList<String>
data class CreateFacReq(
val ko: FacReq,
val en: FacReq
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wafflestudio.csereal.core.about.api.req

data class CreateStatReq(
val year: Int,
val statList: List<StatDto>
)

data class StatDto(
val career: Career,
val bachelor: Int,
val master: Int,
val doctor: Int
)

enum class Career(val krName: String) {
SAMSUNG("삼성"), LG("LG"), LARGE("기타 대기업"),
SMALL("중소기업"), GRADUATE("진학"), OTHER("기타")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.wafflestudio.csereal.core.about.api.req

import com.wafflestudio.csereal.core.about.dto.FacReq

data class UpdateFacReq(
val ko: FacDto,
val en: FacDto,
val ko: FacReq,
val en: FacReq,
val removeImage: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class AboutController(
return ResponseEntity.ok(aboutService.readAllClubs(language))
}

@Deprecated("Use V2 API")
@GetMapping("/facilities")
fun readAllFacilities(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<AboutDto>> {
return ResponseEntity.ok(aboutService.readAllFacilities(language))
}

@Deprecated("Use V2 API")
@GetMapping("/directions")
fun readAllDirections(
@RequestParam(required = false, defaultValue = "ko") language: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class AboutController(
fun createFacilities(@RequestPart request: CreateFacReq, @RequestPart mainImage: MultipartFile?) =
aboutService.createFacilities(request, mainImage)

@GetMapping("/facilities")
fun readAllGroupedFacilities() = aboutService.readAllGroupedFacilities()

@AuthenticatedStaff
@PutMapping("/facilities/{id}")
fun updateFacility(
Expand All @@ -59,11 +62,22 @@ class AboutController(
@DeleteMapping("/facilities/{id}")
fun deleteFacility(@PathVariable id: Long) = aboutService.deleteFacility(id)

@GetMapping("/directions")
fun readAllGroupedDirections() = aboutService.readAllGroupedDirections()

@AuthenticatedStaff
@PutMapping("/directions/{id}")
fun updateDirection(@PathVariable id: Long, @RequestBody request: UpdateDescriptionReq) =
aboutService.updateDirection(id, request)

@AuthenticatedStaff
@PostMapping("/future-careers/stats")
fun createStats(@RequestBody request: CreateStatReq) = aboutService.createFutureCareersStat(request)

@AuthenticatedStaff
@PutMapping("/future-careers/stats")
fun updateStats(@RequestBody request: CreateStatReq) = aboutService.updateFutureCareersStat(request)

@AuthenticatedStaff
@PutMapping("/future-careers")
fun updateFutureCareersPage(@RequestBody request: UpdateDescriptionReq) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository
interface AboutLanguageRepository : JpaRepository<AboutLanguageEntity, Long> {
fun findByKoAbout(koAboutEntity: AboutEntity): AboutLanguageEntity?
fun findByEnAbout(enAboutEntity: AboutEntity): AboutLanguageEntity?
fun findAllByKoAboutPostType(postType: AboutPostType): List<AboutLanguageEntity>
}
34 changes: 34 additions & 0 deletions src/main/kotlin/com/wafflestudio/csereal/core/about/dto/FacReq.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.wafflestudio.csereal.core.about.dto

import com.wafflestudio.csereal.core.about.database.AboutEntity

data class FacReq(
val name: String,
val description: String,
val locations: MutableList<String>
)

data class FacDto(
val id: Long,
val name: String,
val description: String,
val locations: MutableList<String>,
val imageURL: String?
) {
companion object {
fun of(aboutEntity: AboutEntity, imageURL: String?): FacDto {
return FacDto(
id = aboutEntity.id,
name = aboutEntity.name!!,
description = aboutEntity.description,
locations = aboutEntity.locations,
imageURL = imageURL
)
}
}
}

data class GroupedFacDto(
val ko: FacDto,
val en: FacDto
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wafflestudio.csereal.core.about.dto

import com.wafflestudio.csereal.core.about.database.AboutEntity

data class GroupedDirectionDto(
val ko: DirDto,
val en: DirDto
)

data class DirDto(
val id: Long,
val name: String,
val description: String
) {
companion object {
fun of(aboutEntity: AboutEntity): DirDto {
return DirDto(
id = aboutEntity.id,
name = aboutEntity.name!!,
description = aboutEntity.description
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ interface AboutService {
fun updateFacility(id: Long, request: UpdateFacReq, newMainImage: MultipartFile?)
fun deleteFacility(id: Long)
fun readAllFacilities(language: String): List<AboutDto>
fun readAllGroupedFacilities(): List<GroupedFacDto>
fun readAllDirections(language: String): List<AboutDto>
fun readAllGroupedDirections(): List<GroupedDirectionDto>
fun updateDirection(id: Long, request: UpdateDescriptionReq)
fun updateFutureCareersPage(request: UpdateDescriptionReq)
fun createFutureCareersStat(request: CreateStatReq)
fun updateFutureCareersStat(request: CreateStatReq)
fun readFutureCareers(language: String): FutureCareersPage
fun createCompany(request: CreateCompanyReq)
fun updateCompany(id: Long, request: CreateCompanyReq)
Expand Down Expand Up @@ -214,7 +218,7 @@ class AboutServiceImpl(

@Transactional(readOnly = true)
override fun readAllGroupedClubs(): List<GroupedClubDto> {
val clubs = aboutLanguageRepository.findAll().filter { it.koAbout.postType == AboutPostType.STUDENT_CLUBS }
val clubs = aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.STUDENT_CLUBS)
.sortedBy { it.koAbout.name }
return clubs.map {
val imageURL = mainImageService.createImageURL(it.koAbout.mainImage)
Expand Down Expand Up @@ -285,10 +289,10 @@ class AboutServiceImpl(
}
}

private fun updateFacility(facility: AboutEntity, facDto: FacDto) {
facility.name = facDto.name
facility.description = facDto.description
facility.locations = facDto.locations
private fun updateFacility(facility: AboutEntity, facReq: FacReq) {
facility.name = facReq.name
facility.description = facReq.description
facility.locations = facReq.locations
}

@Transactional
Expand Down Expand Up @@ -326,6 +330,17 @@ class AboutServiceImpl(
return facilities
}

@Transactional(readOnly = true)
override fun readAllGroupedFacilities(): List<GroupedFacDto> {
val facilities =
aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.FACILITIES).sortedBy { it.koAbout.name }
return facilities.map {
val koImageURL = mainImageService.createImageURL(it.koAbout.mainImage)
val enImageURL = mainImageService.createImageURL(it.enAbout.mainImage)
GroupedFacDto(ko = FacDto.of(it.koAbout, koImageURL), en = FacDto.of(it.enAbout, enImageURL))
}
}

@Transactional(readOnly = true)
override fun readAllDirections(language: String): List<AboutDto> {
val languageType = LanguageType.makeStringToLanguageType(language)
Expand All @@ -342,6 +357,15 @@ class AboutServiceImpl(
return directions
}

@Transactional(readOnly = true)
override fun readAllGroupedDirections(): List<GroupedDirectionDto> {
val directions =
aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.DIRECTIONS).sortedBy { it.koAbout.name }
return directions.map {
GroupedDirectionDto(ko = DirDto.of(it.koAbout), en = DirDto.of(it.enAbout))
}
}

@Transactional
override fun updateDirection(id: Long, request: UpdateDescriptionReq) {
val direction = aboutRepository.findByIdOrNull(id) ?: throw CserealException.Csereal404("direction not found")
Expand Down Expand Up @@ -379,6 +403,37 @@ class AboutServiceImpl(
en.syncSearchContent()
}

@Transactional
override fun createFutureCareersStat(request: CreateStatReq) {
if (statRepository.findAllByYear(request.year).isNotEmpty()) {
throw CserealException.Csereal409("year already exist")
}
if (request.statList.size != 6) {
throw CserealException.Csereal400("모든 row data 필요")
}
for (stat in request.statList) {
statRepository.save(StatEntity(request.year, Degree.BACHELOR, stat.career.krName, stat.bachelor))
statRepository.save(StatEntity(request.year, Degree.MASTER, stat.career.krName, stat.master))
statRepository.save(StatEntity(request.year, Degree.DOCTOR, stat.career.krName, stat.doctor))
}
}

@Transactional
override fun updateFutureCareersStat(request: CreateStatReq) {
val stats = statRepository.findAllByYear(request.year)
val statsMap = stats.associateBy { it.name to it.degree }

request.statList.forEach { update ->
listOf(
Degree.BACHELOR to update.bachelor,
Degree.MASTER to update.master,
Degree.DOCTOR to update.doctor
).forEach { (degree, count) ->
statsMap[update.career.krName to degree]?.count = count
}
}
}

@Transactional
override fun readFutureCareers(language: String): FutureCareersPage {
val languageType = LanguageType.makeStringToLanguageType(language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.wafflestudio.csereal.core.research.dto

import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.research.database.LabEntity
import com.wafflestudio.csereal.core.research.database.ResearchEntity
import com.wafflestudio.csereal.core.research.type.ResearchType
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse

data class LabDto(
Expand All @@ -14,7 +16,7 @@ data class LabDto(
val acronym: String?,
val pdf: AttachmentResponse?,
val youtube: String?,
val group: String?,
val group: LabGroupDto?,
val description: String?,
val websiteURL: String?
) {
Expand All @@ -30,10 +32,25 @@ data class LabDto(
acronym = this.acronym,
pdf = pdf,
youtube = this.youtube,
group = this.research?.name,
group = this.research?.let { LabGroupDto.of(it) },
description = this.description,
websiteURL = this.websiteURL
)
}
}
}

data class LabGroupDto(
val id: Long,
val name: String
) {
companion object {
fun of(entity: ResearchEntity): LabGroupDto {
if (entity.postType != ResearchType.GROUPS) {
throw IllegalArgumentException("ResearchEntity is not a group")
}

return LabGroupDto(entity.id, entity.name)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.wafflestudio.csereal.core.reservation.database

import jakarta.persistence.LockModeType
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Lock
import org.springframework.data.jpa.repository.Query
import java.time.LocalDateTime
import java.util.UUID

interface ReservationRepository : JpaRepository<ReservationEntity, Long> {

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query(
"SELECT r FROM reservation r " +
"WHERE r.room.id = :roomId " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.wafflestudio.csereal.core.reservation.database

import jakarta.persistence.LockModeType
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Lock

interface RoomRepository : JpaRepository<RoomEntity, Long>
interface RoomRepository : JpaRepository<RoomEntity, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
fun findRoomById(id: Long): RoomEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ReservationServiceImpl(
}

val room =
roomRepository.findByIdOrNull(reserveRequest.roomId) ?: throw CserealException.Csereal404("Room Not Found")
roomRepository.findRoomById(reserveRequest.roomId) ?: throw CserealException.Csereal404("Room Not Found")

if (room.type == RoomType.LECTURE && user.role != Role.ROLE_STAFF) {
throw CserealException.Csereal403("교수회의실 예약 행정실 문의 바람")
Expand Down

0 comments on commit ee71b91

Please sign in to comment.