1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 05:28:15 -05:00
bitwarden/src/Api/Models/Request/DeviceRequestModels.cs

53 lines
1.3 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Domains;
using Bit.Core.Enums;
using Newtonsoft.Json;
namespace Bit.Api.Models
{
public class DeviceRequestModel
{
[Required]
public DeviceType? Type { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
[Required]
[StringLength(50)]
public string Identifier { get; set; }
[StringLength(255)]
public string PushToken { get; set; }
public Device ToDevice(string userId = null)
{
return ToDevice(new Device
{
UserId = new Guid(userId)
});
}
public Device ToDevice(Device existingDevice)
{
existingDevice.Name = Name;
existingDevice.Identifier = Identifier;
existingDevice.PushToken = PushToken;
existingDevice.Type = Type.Value;
return existingDevice;
}
}
public class DeviceTokenRequestModel
{
[StringLength(255)]
public string PushToken { get; set; }
public Device ToDevice(Device existingDevice)
{
existingDevice.PushToken = PushToken;
return existingDevice;
}
}
}