From 1711b9fa57277243e45b03704721d88261312bf4 Mon Sep 17 00:00:00 2001 From: genteure Date: Thu, 7 Apr 2022 16:58:20 +0800 Subject: [PATCH] Web: Change behaviour of add room api --- BililiveRecorder.Web/Api/RoomController.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BililiveRecorder.Web/Api/RoomController.cs b/BililiveRecorder.Web/Api/RoomController.cs index 3deaea2..b7ba1df 100644 --- a/BililiveRecorder.Web/Api/RoomController.cs +++ b/BililiveRecorder.Web/Api/RoomController.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using AutoMapper; using BililiveRecorder.Core; @@ -22,8 +23,10 @@ namespace BililiveRecorder.Web.Api this.recorder = recorder ?? throw new ArgumentNullException(nameof(recorder)); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private IRoom? FetchRoom(int roomId) => this.recorder.Rooms.FirstOrDefault(x => x.ShortId == roomId || x.RoomConfig.RoomId == roomId); + [MethodImpl(MethodImplOptions.AggressiveInlining)] private IRoom? FetchRoom(Guid objectId) => this.recorder.Rooms.FirstOrDefault(x => x.ObjectId == objectId); /// @@ -51,9 +54,14 @@ namespace BililiveRecorder.Web.Api var room = this.FetchRoom(createRoom.RoomId); if (room is not null) - return this.BadRequest(new RestApiError { Code = RestApiErrorCode.RoomExist, Message = "Can not add the same room multiple times." }); - - room = this.recorder.AddRoom(createRoom.RoomId, createRoom.AutoRecord); + { + if (room.RoomConfig.AutoRecord != createRoom.AutoRecord) + room.RoomConfig.AutoRecord = createRoom.AutoRecord; + } + else + { + room = this.recorder.AddRoom(createRoom.RoomId, createRoom.AutoRecord); + } return this.mapper.Map(room); }