Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: staff에 language, migration 방법 추가 #183

Merged
merged 9 commits into from
Feb 15, 2024
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)
}
}
Loading