클라이언트 메시지 다국어 처리
공개 API 변경 없음.
This commit is contained in:
@@ -2,6 +2,8 @@ package kr.co.vividnext.sodalive.report
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
@@ -11,13 +13,18 @@ import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/report")
|
||||
class ReportController(private val service: ReportService) {
|
||||
class ReportController(
|
||||
private val service: ReportService,
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext
|
||||
) {
|
||||
@PostMapping
|
||||
fun report(
|
||||
@RequestBody request: ReportRequest,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
ApiResponse.ok(service.save(member, request), "신고가 접수되었습니다.")
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
val message = messageSource.getMessage("report.received", langContext.lang)
|
||||
ApiResponse.ok(service.save(member, request), message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,26 +20,26 @@ class ReportService(
|
||||
@Transactional
|
||||
fun save(member: Member, request: ReportRequest) {
|
||||
if (conditionAllIsNull(request, isNull = true) || conditionAllIsNull(request, isNull = false)) {
|
||||
throw SodaException("신고가 접수되었습니다.")
|
||||
throw SodaException(messageKey = "report.received")
|
||||
}
|
||||
|
||||
val reportedAccount = if (request.reportedMemberId != null) {
|
||||
memberRepository.findByIdOrNull(request.reportedMemberId)
|
||||
?: throw SodaException("신고가 접수되었습니다.")
|
||||
?: throw SodaException(messageKey = "report.received")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val cheers = if (request.cheersId != null) {
|
||||
cheersRepository.findByIdOrNull(request.cheersId)
|
||||
?: throw SodaException("신고가 접수되었습니다.")
|
||||
?: throw SodaException(messageKey = "report.received")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val communityPost = if (request.communityPostId != null) {
|
||||
creatorCommunityRepository.findByIdOrNull(request.communityPostId)
|
||||
?: throw SodaException("신고가 접수되었습니다.")
|
||||
?: throw SodaException(messageKey = "report.received")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user