From 1870638cfdb98635ad0e1445c19a0639b17dcf05 Mon Sep 17 00:00:00 2001 From: Jo Seonggyu Date: Thu, 15 Feb 2024 23:04:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20staff=EC=97=90=20language,=20migration?= =?UTF-8?q?=20=EB=B0=A9=EB=B2=95=20=EC=B6=94=EA=B0=80=20(#183)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: staffEntity에 language 추가 * feat: branch 이름 변경 * fix: branch origin 이름 변경 * feat: staff 읽기, 수정에서 language 속성 추가 * feat: migrateStaffImage 추가 * fix: StaffServiceTest 수정 --- .../core/member/api/StaffController.kt | 14 ++++++++-- .../core/member/database/StaffEntity.kt | 12 ++++---- .../core/member/database/StaffRepository.kt | 5 +++- .../csereal/core/member/dto/StaffDto.kt | 3 ++ .../core/member/service/StaffService.kt | 28 +++++++++++++++---- .../core/member/service/StaffServiceTest.kt | 3 ++ 6 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/api/StaffController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/api/StaffController.kt index eed5164c..6f298f94 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/api/StaffController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/api/StaffController.kt @@ -29,8 +29,10 @@ class StaffController( } @GetMapping - fun getAllStaff(): ResponseEntity> { - return ResponseEntity.ok(staffService.getAllStaff()) + fun getAllStaff( + @RequestParam(required = false, defaultValue = "ko") language: String + ): ResponseEntity> { + return ResponseEntity.ok(staffService.getAllStaff(language)) } @AuthenticatedStaff @@ -55,4 +57,12 @@ class StaffController( ): ResponseEntity> { return ResponseEntity.ok(staffService.migrateStaff(requestList)) } + + @PatchMapping("/migrateImage/{staffId}") + fun migrateStaffImage( + @PathVariable staffId: Long, + @RequestPart("mainImage") mainImage: MultipartFile + ): ResponseEntity { + return ResponseEntity.ok(staffService.migrateStaffImage(staffId, mainImage)) + } } diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt index c9b704f6..60fc24b6 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffEntity.kt @@ -2,15 +2,16 @@ package com.wafflestudio.csereal.core.member.database import com.wafflestudio.csereal.common.config.BaseTimeEntity import com.wafflestudio.csereal.common.controller.MainImageContentEntityType +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.member.dto.StaffDto import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity -import jakarta.persistence.CascadeType -import jakarta.persistence.Entity -import jakarta.persistence.OneToMany -import jakarta.persistence.OneToOne +import jakarta.persistence.* @Entity(name = "staff") class StaffEntity( + @Enumerated(EnumType.STRING) + var language: LanguageType, + var name: String, var role: String, @@ -30,8 +31,9 @@ class StaffEntity( override fun bringMainImage(): MainImageEntity? = mainImage companion object { - fun of(staffDto: StaffDto): StaffEntity { + fun of(languageType: LanguageType, staffDto: StaffDto): StaffEntity { return StaffEntity( + language = languageType, name = staffDto.name, role = staffDto.role, office = staffDto.office, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffRepository.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffRepository.kt index a293b642..6ce765aa 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffRepository.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffRepository.kt @@ -1,5 +1,8 @@ package com.wafflestudio.csereal.core.member.database +import com.wafflestudio.csereal.common.properties.LanguageType import org.springframework.data.jpa.repository.JpaRepository -interface StaffRepository : JpaRepository +interface StaffRepository : JpaRepository { + fun findAllByLanguage(languageType: LanguageType): List +} diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/dto/StaffDto.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/dto/StaffDto.kt index bf75f902..1c16482a 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/dto/StaffDto.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/dto/StaffDto.kt @@ -1,11 +1,13 @@ package com.wafflestudio.csereal.core.member.dto import com.fasterxml.jackson.annotation.JsonInclude +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.member.database.StaffEntity data class StaffDto( @JsonInclude(JsonInclude.Include.NON_NULL) var id: Long? = null, + val language: String, val name: String, val role: String, val office: String, @@ -19,6 +21,7 @@ data class StaffDto( fun of(staffEntity: StaffEntity, imageURL: String?): StaffDto { return StaffDto( id = staffEntity.id, + language = LanguageType.makeLowercase(staffEntity.language), name = staffEntity.name, role = staffEntity.role, office = staffEntity.office, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/member/service/StaffService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/member/service/StaffService.kt index 90a527c9..32d5f9a4 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/member/service/StaffService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/member/service/StaffService.kt @@ -1,6 +1,7 @@ package com.wafflestudio.csereal.core.member.service import com.wafflestudio.csereal.common.CserealException +import com.wafflestudio.csereal.common.properties.LanguageType import com.wafflestudio.csereal.core.member.database.MemberSearchEntity import com.wafflestudio.csereal.core.member.database.StaffEntity import com.wafflestudio.csereal.core.member.database.StaffRepository @@ -16,10 +17,11 @@ import org.springframework.web.multipart.MultipartFile interface StaffService { fun createStaff(createStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto fun getStaff(staffId: Long): StaffDto - fun getAllStaff(): List + fun getAllStaff(language: String): List fun updateStaff(staffId: Long, updateStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto fun deleteStaff(staffId: Long) fun migrateStaff(requestList: List): List + fun migrateStaffImage(staffId: Long, mainImage: MultipartFile): StaffDto } @Service @@ -29,7 +31,8 @@ class StaffServiceImpl( private val mainImageService: MainImageService ) : StaffService { override fun createStaff(createStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto { - val staff = StaffEntity.of(createStaffRequest) + val enumLanguageType = LanguageType.makeStringToLanguageType(createStaffRequest.language) + val staff = StaffEntity.of(enumLanguageType, createStaffRequest) for (task in createStaffRequest.tasks) { TaskEntity.create(task, staff) @@ -59,8 +62,10 @@ class StaffServiceImpl( } @Transactional(readOnly = true) - override fun getAllStaff(): List { - return staffRepository.findAll().map { + override fun getAllStaff(language: String): List { + val enumLanguageType = LanguageType.makeStringToLanguageType(language) + + return staffRepository.findAllByLanguage(enumLanguageType).map { val imageURL = mainImageService.createImageURL(it.mainImage) SimpleStaffDto.of(it, imageURL) }.sortedBy { it.name } @@ -107,7 +112,8 @@ class StaffServiceImpl( val list = mutableListOf() for (request in requestList) { - val staff = StaffEntity.of(request) + val enumLanguageType = LanguageType.makeStringToLanguageType(request.language) + val staff = StaffEntity.of(enumLanguageType, request) for (task in request.tasks) { TaskEntity.create(task, staff) @@ -122,4 +128,16 @@ class StaffServiceImpl( return list } + + @Transactional + override fun migrateStaffImage(staffId: Long, mainImage: MultipartFile): StaffDto { + val staff = staffRepository.findByIdOrNull(staffId) + ?: throw CserealException.Csereal404("해당 행정직원을 찾을 수 없습니다. staffId: $staffId") + + mainImageService.uploadMainImage(staff, mainImage) + + val imageURL = mainImageService.createImageURL(staff.mainImage) + + return StaffDto.of(staff, imageURL) + } } diff --git a/src/test/kotlin/com/wafflestudio/csereal/core/member/service/StaffServiceTest.kt b/src/test/kotlin/com/wafflestudio/csereal/core/member/service/StaffServiceTest.kt index c0d61496..37043fad 100644 --- a/src/test/kotlin/com/wafflestudio/csereal/core/member/service/StaffServiceTest.kt +++ b/src/test/kotlin/com/wafflestudio/csereal/core/member/service/StaffServiceTest.kt @@ -27,6 +27,7 @@ class StaffServiceTest( Given("이미지 없는 행정직원을 생성하려고 할 떄") { val staffDto = StaffDto( + language = "ko", name = "name", role = "role", office = "office", @@ -75,6 +76,7 @@ class StaffServiceTest( Given("이미지 없는 행정직원을 수정할 때") { val staffDto = StaffDto( + language = "ko", name = "name", role = "role", office = "office", @@ -87,6 +89,7 @@ class StaffServiceTest( When("행정직원을 수정하면") { val updateStaffDto = StaffDto( + language = "ko", name = "name2", role = "role2", office = "office2",