Add dto for device options

pull/6201/head
Patrick Barron 3 years ago
parent 06d682c296
commit 60ce0c9fa9

@ -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();
}

@ -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; }
}
}

@ -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 />

@ -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);
}

Loading…
Cancel
Save