메시지 API
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
package kr.co.vividnext.sodalive.message
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
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.RequestBody
|
||||
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
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/message")
|
||||
class MessageController(private val service: MessageService) {
|
||||
@PostMapping("/send/text")
|
||||
fun sendTextMessage(
|
||||
@RequestBody request: SendTextMessageRequest,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.sendTextMessage(request, member))
|
||||
}
|
||||
|
||||
@GetMapping("/sent/text")
|
||||
fun getSentTextMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getSentTextMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@GetMapping("/received/text")
|
||||
fun getReceivedTextMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getReceivedTextMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@GetMapping("/keep/text")
|
||||
fun getKeepTextMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getKeepTextMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@PutMapping("/keep/text/{id}")
|
||||
fun keepTextMessage(
|
||||
@PathVariable id: Long,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
ApiResponse.ok(service.keepTextMessage(id, member))
|
||||
}
|
||||
|
||||
@PostMapping("/send/voice")
|
||||
fun sendVoiceMessage(
|
||||
@RequestPart("voiceMessageFile") voiceMessageFile: MultipartFile,
|
||||
@RequestPart("request") requestString: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.sendVoiceMessage(voiceMessageFile, requestString, member))
|
||||
}
|
||||
|
||||
@GetMapping("/sent/voice")
|
||||
fun getSentVoiceMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
ApiResponse.ok(service.getSentVoiceMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@GetMapping("/received/voice")
|
||||
fun getReceivedVoiceMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getReceivedVoiceMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@GetMapping("/keep/voice")
|
||||
fun getKeepVoiceMessages(
|
||||
@RequestParam("timezone") timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.getKeepVoiceMessages(member, pageable, timezone))
|
||||
}
|
||||
|
||||
@PutMapping("/keep/voice/{id}")
|
||||
fun keepVoiceMessage(
|
||||
@PathVariable id: Long,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
ApiResponse.ok(service.keepVoiceMessage(id, member))
|
||||
}
|
||||
|
||||
@DeleteMapping("/{messageId}")
|
||||
fun deleteMessage(
|
||||
@PathVariable messageId: Long,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.deleteMessage(messageId, member))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user