Skip to content

Commit ee71b91

Browse files
authored
Merge pull request #325 from wafflestudio/develop
prod deploy
2 parents facc71f + b95d057 commit ee71b91

File tree

13 files changed

+187
-22
lines changed

13 files changed

+187
-22
lines changed
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package com.wafflestudio.csereal.core.about.api.req
22

3-
data class CreateFacReq(
4-
val ko: FacDto,
5-
val en: FacDto
6-
)
3+
import com.wafflestudio.csereal.core.about.dto.FacReq
74

8-
data class FacDto(
9-
val name: String,
10-
val description: String,
11-
val locations: MutableList<String>
5+
data class CreateFacReq(
6+
val ko: FacReq,
7+
val en: FacReq
128
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.wafflestudio.csereal.core.about.api.req
2+
3+
data class CreateStatReq(
4+
val year: Int,
5+
val statList: List<StatDto>
6+
)
7+
8+
data class StatDto(
9+
val career: Career,
10+
val bachelor: Int,
11+
val master: Int,
12+
val doctor: Int
13+
)
14+
15+
enum class Career(val krName: String) {
16+
SAMSUNG("삼성"), LG("LG"), LARGE("기타 대기업"),
17+
SMALL("중소기업"), GRADUATE("진학"), OTHER("기타")
18+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.wafflestudio.csereal.core.about.api.req
22

3+
import com.wafflestudio.csereal.core.about.dto.FacReq
4+
35
data class UpdateFacReq(
4-
val ko: FacDto,
5-
val en: FacDto,
6+
val ko: FacReq,
7+
val en: FacReq,
68
val removeImage: Boolean
79
)

src/main/kotlin/com/wafflestudio/csereal/core/about/api/v1/AboutController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class AboutController(
3838
return ResponseEntity.ok(aboutService.readAllClubs(language))
3939
}
4040

41+
@Deprecated("Use V2 API")
4142
@GetMapping("/facilities")
4243
fun readAllFacilities(
4344
@RequestParam(required = false, defaultValue = "ko") language: String
4445
): ResponseEntity<List<AboutDto>> {
4546
return ResponseEntity.ok(aboutService.readAllFacilities(language))
4647
}
4748

49+
@Deprecated("Use V2 API")
4850
@GetMapping("/directions")
4951
fun readAllDirections(
5052
@RequestParam(required = false, defaultValue = "ko") language: String

src/main/kotlin/com/wafflestudio/csereal/core/about/api/v2/AboutController.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class AboutController(
4747
fun createFacilities(@RequestPart request: CreateFacReq, @RequestPart mainImage: MultipartFile?) =
4848
aboutService.createFacilities(request, mainImage)
4949

50+
@GetMapping("/facilities")
51+
fun readAllGroupedFacilities() = aboutService.readAllGroupedFacilities()
52+
5053
@AuthenticatedStaff
5154
@PutMapping("/facilities/{id}")
5255
fun updateFacility(
@@ -59,11 +62,22 @@ class AboutController(
5962
@DeleteMapping("/facilities/{id}")
6063
fun deleteFacility(@PathVariable id: Long) = aboutService.deleteFacility(id)
6164

65+
@GetMapping("/directions")
66+
fun readAllGroupedDirections() = aboutService.readAllGroupedDirections()
67+
6268
@AuthenticatedStaff
6369
@PutMapping("/directions/{id}")
6470
fun updateDirection(@PathVariable id: Long, @RequestBody request: UpdateDescriptionReq) =
6571
aboutService.updateDirection(id, request)
6672

73+
@AuthenticatedStaff
74+
@PostMapping("/future-careers/stats")
75+
fun createStats(@RequestBody request: CreateStatReq) = aboutService.createFutureCareersStat(request)
76+
77+
@AuthenticatedStaff
78+
@PutMapping("/future-careers/stats")
79+
fun updateStats(@RequestBody request: CreateStatReq) = aboutService.updateFutureCareersStat(request)
80+
6781
@AuthenticatedStaff
6882
@PutMapping("/future-careers")
6983
fun updateFutureCareersPage(@RequestBody request: UpdateDescriptionReq) =

src/main/kotlin/com/wafflestudio/csereal/core/about/database/AboutLanguageRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository
55
interface AboutLanguageRepository : JpaRepository<AboutLanguageEntity, Long> {
66
fun findByKoAbout(koAboutEntity: AboutEntity): AboutLanguageEntity?
77
fun findByEnAbout(enAboutEntity: AboutEntity): AboutLanguageEntity?
8+
fun findAllByKoAboutPostType(postType: AboutPostType): List<AboutLanguageEntity>
89
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.wafflestudio.csereal.core.about.dto
2+
3+
import com.wafflestudio.csereal.core.about.database.AboutEntity
4+
5+
data class FacReq(
6+
val name: String,
7+
val description: String,
8+
val locations: MutableList<String>
9+
)
10+
11+
data class FacDto(
12+
val id: Long,
13+
val name: String,
14+
val description: String,
15+
val locations: MutableList<String>,
16+
val imageURL: String?
17+
) {
18+
companion object {
19+
fun of(aboutEntity: AboutEntity, imageURL: String?): FacDto {
20+
return FacDto(
21+
id = aboutEntity.id,
22+
name = aboutEntity.name!!,
23+
description = aboutEntity.description,
24+
locations = aboutEntity.locations,
25+
imageURL = imageURL
26+
)
27+
}
28+
}
29+
}
30+
31+
data class GroupedFacDto(
32+
val ko: FacDto,
33+
val en: FacDto
34+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.wafflestudio.csereal.core.about.dto
2+
3+
import com.wafflestudio.csereal.core.about.database.AboutEntity
4+
5+
data class GroupedDirectionDto(
6+
val ko: DirDto,
7+
val en: DirDto
8+
)
9+
10+
data class DirDto(
11+
val id: Long,
12+
val name: String,
13+
val description: String
14+
) {
15+
companion object {
16+
fun of(aboutEntity: AboutEntity): DirDto {
17+
return DirDto(
18+
id = aboutEntity.id,
19+
name = aboutEntity.name!!,
20+
description = aboutEntity.description
21+
)
22+
}
23+
}
24+
}

src/main/kotlin/com/wafflestudio/csereal/core/about/service/AboutService.kt

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ interface AboutService {
3636
fun updateFacility(id: Long, request: UpdateFacReq, newMainImage: MultipartFile?)
3737
fun deleteFacility(id: Long)
3838
fun readAllFacilities(language: String): List<AboutDto>
39+
fun readAllGroupedFacilities(): List<GroupedFacDto>
3940
fun readAllDirections(language: String): List<AboutDto>
41+
fun readAllGroupedDirections(): List<GroupedDirectionDto>
4042
fun updateDirection(id: Long, request: UpdateDescriptionReq)
4143
fun updateFutureCareersPage(request: UpdateDescriptionReq)
44+
fun createFutureCareersStat(request: CreateStatReq)
45+
fun updateFutureCareersStat(request: CreateStatReq)
4246
fun readFutureCareers(language: String): FutureCareersPage
4347
fun createCompany(request: CreateCompanyReq)
4448
fun updateCompany(id: Long, request: CreateCompanyReq)
@@ -214,7 +218,7 @@ class AboutServiceImpl(
214218

215219
@Transactional(readOnly = true)
216220
override fun readAllGroupedClubs(): List<GroupedClubDto> {
217-
val clubs = aboutLanguageRepository.findAll().filter { it.koAbout.postType == AboutPostType.STUDENT_CLUBS }
221+
val clubs = aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.STUDENT_CLUBS)
218222
.sortedBy { it.koAbout.name }
219223
return clubs.map {
220224
val imageURL = mainImageService.createImageURL(it.koAbout.mainImage)
@@ -285,10 +289,10 @@ class AboutServiceImpl(
285289
}
286290
}
287291

288-
private fun updateFacility(facility: AboutEntity, facDto: FacDto) {
289-
facility.name = facDto.name
290-
facility.description = facDto.description
291-
facility.locations = facDto.locations
292+
private fun updateFacility(facility: AboutEntity, facReq: FacReq) {
293+
facility.name = facReq.name
294+
facility.description = facReq.description
295+
facility.locations = facReq.locations
292296
}
293297

294298
@Transactional
@@ -326,6 +330,17 @@ class AboutServiceImpl(
326330
return facilities
327331
}
328332

333+
@Transactional(readOnly = true)
334+
override fun readAllGroupedFacilities(): List<GroupedFacDto> {
335+
val facilities =
336+
aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.FACILITIES).sortedBy { it.koAbout.name }
337+
return facilities.map {
338+
val koImageURL = mainImageService.createImageURL(it.koAbout.mainImage)
339+
val enImageURL = mainImageService.createImageURL(it.enAbout.mainImage)
340+
GroupedFacDto(ko = FacDto.of(it.koAbout, koImageURL), en = FacDto.of(it.enAbout, enImageURL))
341+
}
342+
}
343+
329344
@Transactional(readOnly = true)
330345
override fun readAllDirections(language: String): List<AboutDto> {
331346
val languageType = LanguageType.makeStringToLanguageType(language)
@@ -342,6 +357,15 @@ class AboutServiceImpl(
342357
return directions
343358
}
344359

360+
@Transactional(readOnly = true)
361+
override fun readAllGroupedDirections(): List<GroupedDirectionDto> {
362+
val directions =
363+
aboutLanguageRepository.findAllByKoAboutPostType(AboutPostType.DIRECTIONS).sortedBy { it.koAbout.name }
364+
return directions.map {
365+
GroupedDirectionDto(ko = DirDto.of(it.koAbout), en = DirDto.of(it.enAbout))
366+
}
367+
}
368+
345369
@Transactional
346370
override fun updateDirection(id: Long, request: UpdateDescriptionReq) {
347371
val direction = aboutRepository.findByIdOrNull(id) ?: throw CserealException.Csereal404("direction not found")
@@ -379,6 +403,37 @@ class AboutServiceImpl(
379403
en.syncSearchContent()
380404
}
381405

406+
@Transactional
407+
override fun createFutureCareersStat(request: CreateStatReq) {
408+
if (statRepository.findAllByYear(request.year).isNotEmpty()) {
409+
throw CserealException.Csereal409("year already exist")
410+
}
411+
if (request.statList.size != 6) {
412+
throw CserealException.Csereal400("모든 row data 필요")
413+
}
414+
for (stat in request.statList) {
415+
statRepository.save(StatEntity(request.year, Degree.BACHELOR, stat.career.krName, stat.bachelor))
416+
statRepository.save(StatEntity(request.year, Degree.MASTER, stat.career.krName, stat.master))
417+
statRepository.save(StatEntity(request.year, Degree.DOCTOR, stat.career.krName, stat.doctor))
418+
}
419+
}
420+
421+
@Transactional
422+
override fun updateFutureCareersStat(request: CreateStatReq) {
423+
val stats = statRepository.findAllByYear(request.year)
424+
val statsMap = stats.associateBy { it.name to it.degree }
425+
426+
request.statList.forEach { update ->
427+
listOf(
428+
Degree.BACHELOR to update.bachelor,
429+
Degree.MASTER to update.master,
430+
Degree.DOCTOR to update.doctor
431+
).forEach { (degree, count) ->
432+
statsMap[update.career.krName to degree]?.count = count
433+
}
434+
}
435+
}
436+
382437
@Transactional
383438
override fun readFutureCareers(language: String): FutureCareersPage {
384439
val languageType = LanguageType.makeStringToLanguageType(language)

src/main/kotlin/com/wafflestudio/csereal/core/research/dto/LabDto.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.wafflestudio.csereal.core.research.dto
22

33
import com.wafflestudio.csereal.common.enums.LanguageType
44
import com.wafflestudio.csereal.core.research.database.LabEntity
5+
import com.wafflestudio.csereal.core.research.database.ResearchEntity
6+
import com.wafflestudio.csereal.core.research.type.ResearchType
57
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse
68

79
data class LabDto(
@@ -14,7 +16,7 @@ data class LabDto(
1416
val acronym: String?,
1517
val pdf: AttachmentResponse?,
1618
val youtube: String?,
17-
val group: String?,
19+
val group: LabGroupDto?,
1820
val description: String?,
1921
val websiteURL: String?
2022
) {
@@ -30,10 +32,25 @@ data class LabDto(
3032
acronym = this.acronym,
3133
pdf = pdf,
3234
youtube = this.youtube,
33-
group = this.research?.name,
35+
group = this.research?.let { LabGroupDto.of(it) },
3436
description = this.description,
3537
websiteURL = this.websiteURL
3638
)
3739
}
3840
}
3941
}
42+
43+
data class LabGroupDto(
44+
val id: Long,
45+
val name: String
46+
) {
47+
companion object {
48+
fun of(entity: ResearchEntity): LabGroupDto {
49+
if (entity.postType != ResearchType.GROUPS) {
50+
throw IllegalArgumentException("ResearchEntity is not a group")
51+
}
52+
53+
return LabGroupDto(entity.id, entity.name)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)