From f813d8eae42a60b19885d62df66c1bba0b4de4e5 Mon Sep 17 00:00:00 2001
From: Klaus <klaus@vividnext.co.kr>
Date: Tue, 8 Oct 2024 15:10:24 +0900
Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EB=A9=94?=
 =?UTF-8?q?=EB=89=B4=20-=20=EC=83=9D=EC=84=B1=20or=20=EC=88=98=EC=A0=95=20?=
 =?UTF-8?q?API=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../live/room/menu/LiveRoomMenuController.kt  | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuController.kt
index 11e3aa8..fdd9dd3 100644
--- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuController.kt
+++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuController.kt
@@ -6,15 +6,16 @@ import kr.co.vividnext.sodalive.member.Member
 import org.springframework.security.access.prepost.PreAuthorize
 import org.springframework.security.core.annotation.AuthenticationPrincipal
 import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RequestParam
 import org.springframework.web.bind.annotation.RestController
 
 @RestController
+@PreAuthorize("hasRole('CREATOR')")
 @RequestMapping("/live/room/menu")
 class LiveRoomMenuController(private val service: LiveRoomMenuService) {
     @GetMapping("/all")
-    @PreAuthorize("hasRole('CREATOR')")
     fun getAllLiveMenu(
         @RequestParam creatorId: Long,
         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
@@ -23,4 +24,23 @@ class LiveRoomMenuController(private val service: LiveRoomMenuService) {
 
         ApiResponse.ok(service.getAllLiveMenu(creatorId = creatorId, memberId = member.id!!))
     }
+
+    @PostMapping
+    fun createOrUpdateLiveMenu(
+        @RequestParam request: UpdateLiveMenuRequest,
+        @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
+    ) = run {
+        if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
+
+        ApiResponse.ok(
+            if (request.id > 0) {
+                service.updateLiveMenu(memberId = member.id!!, request = request)
+            } else {
+                service.createLiveMenu(
+                    memberId = member.id!!,
+                    request = CreateLiveMenuRequest(menu = request.menu, isActive = false)
+                )
+            }
+        )
+    }
 }