瀏覽代碼

Add dto for device options

Patrick Barron 3 年之前
父節點
當前提交
60ce0c9fa9

+ 3 - 2
Jellyfin.Api/Controllers/DevicesController.cs

@@ -2,6 +2,7 @@ using System;
 using System.ComponentModel.DataAnnotations;
 using System.Threading.Tasks;
 using Jellyfin.Api.Constants;
+using Jellyfin.Data.Dtos;
 using Jellyfin.Data.Entities.Security;
 using Jellyfin.Data.Queries;
 using MediaBrowser.Controller.Devices;
@@ -105,9 +106,9 @@ namespace Jellyfin.Api.Controllers
         [ProducesResponseType(StatusCodes.Status404NotFound)]
         public async Task<ActionResult> UpdateDeviceOptions(
             [FromQuery, Required] string id,
-            [FromBody, Required] DeviceOptions deviceOptions)
+            [FromBody, Required] DeviceOptionsDto deviceOptions)
         {
-            await _deviceManager.UpdateDeviceOptions(id, deviceOptions).ConfigureAwait(false);
+            await _deviceManager.UpdateDeviceOptions(id, deviceOptions.CustomName).ConfigureAwait(false);
             return NoContent();
         }
 

+ 23 - 0
Jellyfin.Data/Dtos/DeviceOptionsDto.cs

@@ -0,0 +1,23 @@
+namespace Jellyfin.Data.Dtos
+{
+    /// <summary>
+    /// A dto representing custom options for a device.
+    /// </summary>
+    public class DeviceOptionsDto
+    {
+        /// <summary>
+        /// Gets or sets the id.
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// Gets or sets the device id.
+        /// </summary>
+        public string? DeviceId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the custom name.
+        /// </summary>
+        public string? CustomName { get; set; }
+    }
+}

+ 3 - 3
Jellyfin.Server.Implementations/Devices/DeviceManager.cs

@@ -46,7 +46,7 @@ namespace Jellyfin.Server.Implementations.Devices
         }
 
         /// <inheritdoc />
-        public async Task UpdateDeviceOptions(string deviceId, DeviceOptions options)
+        public async Task UpdateDeviceOptions(string deviceId, string deviceName)
         {
             await using var dbContext = _dbProvider.CreateContext();
             var deviceOptions = await dbContext.DeviceOptions.AsQueryable().FirstOrDefaultAsync(dev => dev.DeviceId == deviceId).ConfigureAwait(false);
@@ -56,10 +56,10 @@ namespace Jellyfin.Server.Implementations.Devices
                 dbContext.DeviceOptions.Add(deviceOptions);
             }
 
-            deviceOptions.CustomName = options.CustomName;
+            deviceOptions.CustomName = deviceName;
             await dbContext.SaveChangesAsync().ConfigureAwait(false);
 
-            DeviceOptionsUpdated?.Invoke(this, new GenericEventArgs<Tuple<string, DeviceOptions>>(new Tuple<string, DeviceOptions>(deviceId, options)));
+            DeviceOptionsUpdated?.Invoke(this, new GenericEventArgs<Tuple<string, DeviceOptions>>(new Tuple<string, DeviceOptions>(deviceId, deviceOptions)));
         }
 
         /// <inheritdoc />

+ 1 - 1
MediaBrowser.Controller/Devices/IDeviceManager.cs

@@ -70,7 +70,7 @@ namespace MediaBrowser.Controller.Devices
         /// </summary>
         bool CanAccessDevice(User user, string deviceId);
 
-        Task UpdateDeviceOptions(string deviceId, DeviceOptions options);
+        Task UpdateDeviceOptions(string deviceId, string deviceName);
 
         Task<DeviceOptions> GetDeviceOptions(string deviceId);
     }