Skip to content

Commit

Permalink
feat: staff에 language, migration 방법 추가 (#183)
Browse files Browse the repository at this point in the history
* feat: staffEntity에 language 추가

* feat: branch 이름 변경

* fix: branch origin 이름 변경

* feat: staff 읽기, 수정에서 language 속성 추가

* feat: migrateStaffImage 추가

* fix: StaffServiceTest 수정
  • Loading branch information
skfotakf authored Feb 15, 2024
1 parent d664dc4 commit 1870638
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class StaffController(
}

@GetMapping
fun getAllStaff(): ResponseEntity<List<SimpleStaffDto>> {
return ResponseEntity.ok(staffService.getAllStaff())
fun getAllStaff(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<SimpleStaffDto>> {
return ResponseEntity.ok(staffService.getAllStaff(language))
}

@AuthenticatedStaff
Expand All @@ -55,4 +57,12 @@ class StaffController(
): ResponseEntity<List<StaffDto>> {
return ResponseEntity.ok(staffService.migrateStaff(requestList))
}

@PatchMapping("/migrateImage/{staffId}")
fun migrateStaffImage(
@PathVariable staffId: Long,
@RequestPart("mainImage") mainImage: MultipartFile
): ResponseEntity<StaffDto> {
return ResponseEntity.ok(staffService.migrateStaffImage(staffId, mainImage))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StaffEntity, Long>
interface StaffRepository : JpaRepository<StaffEntity, Long> {
fun findAllByLanguage(languageType: LanguageType): List<StaffEntity>
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<SimpleStaffDto>
fun getAllStaff(language: String): List<SimpleStaffDto>
fun updateStaff(staffId: Long, updateStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto
fun deleteStaff(staffId: Long)
fun migrateStaff(requestList: List<StaffDto>): List<StaffDto>
fun migrateStaffImage(staffId: Long, mainImage: MultipartFile): StaffDto
}

@Service
Expand All @@ -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)
Expand Down Expand Up @@ -59,8 +62,10 @@ class StaffServiceImpl(
}

@Transactional(readOnly = true)
override fun getAllStaff(): List<SimpleStaffDto> {
return staffRepository.findAll().map {
override fun getAllStaff(language: String): List<SimpleStaffDto> {
val enumLanguageType = LanguageType.makeStringToLanguageType(language)

return staffRepository.findAllByLanguage(enumLanguageType).map {
val imageURL = mainImageService.createImageURL(it.mainImage)
SimpleStaffDto.of(it, imageURL)
}.sortedBy { it.name }
Expand Down Expand Up @@ -107,7 +112,8 @@ class StaffServiceImpl(
val list = mutableListOf<StaffDto>()

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)
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class StaffServiceTest(

Given("이미지 없는 행정직원을 생성하려고 할 떄") {
val staffDto = StaffDto(
language = "ko",
name = "name",
role = "role",
office = "office",
Expand Down Expand Up @@ -75,6 +76,7 @@ class StaffServiceTest(

Given("이미지 없는 행정직원을 수정할 때") {
val staffDto = StaffDto(
language = "ko",
name = "name",
role = "role",
office = "office",
Expand All @@ -87,6 +89,7 @@ class StaffServiceTest(

When("행정직원을 수정하면") {
val updateStaffDto = StaffDto(
language = "ko",
name = "name2",
role = "role2",
office = "office2",
Expand Down

0 comments on commit 1870638

Please sign in to comment.