mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
device apis and models
This commit is contained in:
36
src/Api/Models/Request/DeviceRequestModel.cs
Normal file
36
src/Api/Models/Request/DeviceRequestModel.cs
Normal file
@ -0,0 +1,36 @@
|
||||
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; }
|
||||
[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.PushToken = PushToken;
|
||||
existingDevice.Type = Type.Value;
|
||||
|
||||
return existingDevice;
|
||||
}
|
||||
}
|
||||
}
|
28
src/Api/Models/Response/DeviceResponseModel.cs
Normal file
28
src/Api/Models/Response/DeviceResponseModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class DeviceResponseModel : ResponseModel
|
||||
{
|
||||
public DeviceResponseModel(Device device)
|
||||
: base("device")
|
||||
{
|
||||
if(device == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(device));
|
||||
}
|
||||
|
||||
Id = device.Id.ToString();
|
||||
Name = device.Name;
|
||||
Type = device.Type;
|
||||
CreationDate = device.CreationDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DeviceType Type { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user