-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Staff 두 언어 묶어서 동작하는 V2 API 정의 (#301)
- Loading branch information
Showing
16 changed files
with
331 additions
and
97 deletions.
There are no files selected for viewing
66 changes: 0 additions & 66 deletions
66
src/main/kotlin/com/wafflestudio/csereal/core/member/api/StaffController.kt
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/wafflestudio/csereal/core/member/api/req/CreateStaffLanguagesReqBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.wafflestudio.csereal.core.member.api.req | ||
|
||
data class CreateStaffLanguagesReqBody( | ||
val ko: CreateStaffReqBody, | ||
val en: CreateStaffReqBody | ||
) |
1 change: 0 additions & 1 deletion
1
src/main/kotlin/com/wafflestudio/csereal/core/member/api/req/CreateStaffReqBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/wafflestudio/csereal/core/member/api/req/ModifyStaffLanguagesReqBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.wafflestudio.csereal.core.member.api.req | ||
|
||
data class ModifyStaffLanguagesReqBody( | ||
val ko: ModifyStaffReqBody, | ||
val en: ModifyStaffReqBody | ||
) |
1 change: 0 additions & 1 deletion
1
src/main/kotlin/com/wafflestudio/csereal/core/member/api/req/ModifyStaffReqBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/wafflestudio/csereal/core/member/api/v1/StaffController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.wafflestudio.csereal.core.member.api.v1 | ||
|
||
import com.wafflestudio.csereal.core.member.dto.SimpleStaffDto | ||
import com.wafflestudio.csereal.core.member.dto.StaffDto | ||
import com.wafflestudio.csereal.core.member.service.StaffService | ||
import jakarta.validation.constraints.Positive | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Deprecated(message = "Use v2 API") | ||
@RequestMapping("/api/v1/staff") | ||
@RestController("StaffControllerV1") | ||
class StaffController( | ||
private val staffService: StaffService | ||
) { | ||
@GetMapping("/{staffId}") | ||
fun getStaff( | ||
@PathVariable @Positive | ||
staffId: Long | ||
): ResponseEntity<StaffDto> { | ||
return ResponseEntity.ok(staffService.getStaff(staffId)) | ||
} | ||
|
||
@GetMapping | ||
fun getAllStaff( | ||
@RequestParam(required = false, defaultValue = "ko") language: String | ||
): ResponseEntity<List<SimpleStaffDto>> { | ||
return ResponseEntity.ok(staffService.getAllStaff(language)) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/kotlin/com/wafflestudio/csereal/core/member/api/v2/StaffController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.wafflestudio.csereal.core.member.api.v2 | ||
|
||
import com.wafflestudio.csereal.common.aop.AuthenticatedStaff | ||
import com.wafflestudio.csereal.core.member.api.req.CreateStaffLanguagesReqBody | ||
import com.wafflestudio.csereal.core.member.api.req.ModifyStaffLanguagesReqBody | ||
import com.wafflestudio.csereal.core.member.dto.SimpleStaffDto | ||
import com.wafflestudio.csereal.core.member.dto.StaffLanguagesDto | ||
import com.wafflestudio.csereal.core.member.service.StaffService | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import jakarta.validation.constraints.Positive | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RequestPart | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
@RequestMapping("/api/v2/staff") | ||
@RestController | ||
class StaffController( | ||
private val staffService: StaffService | ||
) { | ||
@GetMapping("/{staffId}") | ||
fun getStaff( | ||
@PathVariable @Positive | ||
staffId: Long | ||
): StaffLanguagesDto = staffService.getStaffLanguages(staffId) | ||
|
||
@GetMapping | ||
fun getAllStaff( | ||
@RequestParam(required = false, defaultValue = "ko") language: String | ||
): ResponseEntity<List<SimpleStaffDto>> { | ||
return ResponseEntity.ok(staffService.getAllStaff(language)) | ||
} | ||
|
||
@AuthenticatedStaff | ||
@PostMapping(consumes = ["multipart/form-data"]) | ||
fun createStaff( | ||
@RequestPart("request") createStaffLanguagesReqBody: CreateStaffLanguagesReqBody, | ||
@RequestPart("image") image: MultipartFile? | ||
): StaffLanguagesDto = staffService.createStaffLanguages(createStaffLanguagesReqBody, image) | ||
|
||
@AuthenticatedStaff | ||
@PutMapping("/{koStaffId}/{enStaffId}", consumes = ["multipart/form-data"]) | ||
fun updateStaff( | ||
@PathVariable @Positive | ||
koStaffId: Long, | ||
@PathVariable @Positive | ||
enStaffId: Long, | ||
@RequestPart("request") modifyStaffLanguageReq: ModifyStaffLanguagesReqBody, | ||
|
||
@Parameter(description = "image 교체할 경우 업로드. Request Body의 removeImage 관계없이 변경됨.") | ||
@RequestPart("newImage") | ||
newImage: MultipartFile? | ||
): StaffLanguagesDto = | ||
staffService.updateStaffLanguages(koStaffId, enStaffId, modifyStaffLanguageReq, newImage) | ||
|
||
@AuthenticatedStaff | ||
@DeleteMapping("/{koStaffId}/{enStaffId}") | ||
fun deleteStaff( | ||
@PathVariable @Positive | ||
koStaffId: Long, | ||
|
||
@PathVariable @Positive | ||
enStaffId: Long | ||
) { | ||
staffService.deleteStaffLanguages(koStaffId, enStaffId) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/wafflestudio/csereal/core/member/database/MemberLanguageEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.wafflestudio.csereal.core.member.database | ||
|
||
import com.wafflestudio.csereal.common.config.BaseTimeEntity | ||
import com.wafflestudio.csereal.core.member.type.MemberType | ||
import jakarta.persistence.* | ||
|
||
@Entity(name = "member_language") | ||
class MemberLanguageEntity( | ||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
val type: MemberType, | ||
|
||
@Column(nullable = false) | ||
val koreanId: Long, | ||
|
||
@Column(nullable = false) | ||
val englishId: Long | ||
) : BaseTimeEntity() { | ||
companion object { | ||
fun of( | ||
type: MemberType, | ||
koreanId: Long, | ||
englishId: Long | ||
) = MemberLanguageEntity(type, koreanId, englishId) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/wafflestudio/csereal/core/member/database/MemberLanguageRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.wafflestudio.csereal.core.member.database | ||
|
||
import com.wafflestudio.csereal.core.member.type.MemberType | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface MemberLanguageRepository : JpaRepository<MemberLanguageEntity, Long> { | ||
fun existsByKoreanIdAndEnglishIdAndType( | ||
koreanId: Long, | ||
englishId: Long, | ||
type: MemberType | ||
): Boolean | ||
|
||
fun findByKoreanIdAndEnglishIdAndType( | ||
koreanId: Long, | ||
englishId: Long, | ||
type: MemberType | ||
): MemberLanguageEntity? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 40 additions & 1 deletion
41
src/main/kotlin/com/wafflestudio/csereal/core/member/database/StaffRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,47 @@ | ||
package com.wafflestudio.csereal.core.member.database | ||
|
||
import com.querydsl.core.types.dsl.Expressions | ||
import com.querydsl.jpa.JPAExpressions | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import com.wafflestudio.csereal.common.enums.LanguageType | ||
import com.wafflestudio.csereal.core.member.database.QMemberLanguageEntity.memberLanguageEntity | ||
import com.wafflestudio.csereal.core.member.database.QStaffEntity.staffEntity | ||
import com.wafflestudio.csereal.core.member.type.MemberType | ||
import com.wafflestudio.csereal.core.resource.mainImage.database.QMainImageEntity.mainImageEntity | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
interface StaffRepository : JpaRepository<StaffEntity, Long> { | ||
interface StaffRepository : JpaRepository<StaffEntity, Long>, StaffRepositoryCustom { | ||
fun findAllByLanguage(languageType: LanguageType): List<StaffEntity> | ||
} | ||
|
||
interface StaffRepositoryCustom { | ||
fun findStaffAllLanguages(id: Long): Map<LanguageType, List<StaffEntity>> | ||
} | ||
|
||
@Repository | ||
class StaffRepositoryCustomImpl( | ||
private val queryFactory: JPAQueryFactory | ||
) : StaffRepositoryCustom { | ||
override fun findStaffAllLanguages(id: Long): Map<LanguageType, List<StaffEntity>> { | ||
val staffs = queryFactory.selectFrom(staffEntity) | ||
.where( | ||
staffEntity.id.`in`( | ||
JPAExpressions.select( | ||
memberLanguageEntity.koreanId | ||
).from(memberLanguageEntity) | ||
.where(memberLanguageEntity.englishId.eq(id), memberLanguageEntity.type.eq(MemberType.STAFF)), | ||
JPAExpressions.select( | ||
memberLanguageEntity.englishId | ||
).from(memberLanguageEntity) | ||
.where(memberLanguageEntity.koreanId.eq(id), memberLanguageEntity.type.eq(MemberType.STAFF)), | ||
Expressions.constant(id) | ||
) | ||
).leftJoin(mainImageEntity).on(mainImageEntity.id.eq(staffEntity.id)) | ||
.fetch() | ||
|
||
return staffs.groupBy { | ||
it.language | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/wafflestudio/csereal/core/member/dto/StaffLanguagesDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.wafflestudio.csereal.core.member.dto | ||
|
||
data class StaffLanguagesDto( | ||
val ko: StaffDto?, | ||
val en: StaffDto? | ||
) |
Oops, something went wrong.