Device.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace Jellyfin.Data.Entities.Security
  5. {
  6. /// <summary>
  7. /// An entity representing a device.
  8. /// </summary>
  9. public class Device
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="Device"/> class.
  13. /// </summary>
  14. /// <param name="userId">The user id.</param>
  15. /// <param name="accessToken">The access token.</param>
  16. /// <param name="appName">The app name.</param>
  17. /// <param name="appVersion">The app version.</param>
  18. /// <param name="deviceName">The device name.</param>
  19. /// <param name="deviceId">The device id.</param>
  20. public Device(Guid userId, string accessToken, string appName, string appVersion, string deviceName, string deviceId)
  21. {
  22. UserId = userId;
  23. AccessToken = accessToken;
  24. AppName = appName;
  25. AppVersion = appVersion;
  26. DeviceName = deviceName;
  27. DeviceId = deviceId;
  28. DateCreated = DateTime.UtcNow;
  29. DateLastActivity = DateCreated;
  30. // Non-nullable for EF Core, as this is a required relationship.
  31. User = null!;
  32. }
  33. /// <summary>
  34. /// Gets the id.
  35. /// </summary>
  36. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  37. public int Id { get; private set; }
  38. /// <summary>
  39. /// Gets the user id.
  40. /// </summary>
  41. public Guid UserId { get; private set; }
  42. /// <summary>
  43. /// Gets or sets the access token.
  44. /// </summary>
  45. public string AccessToken { get; set; }
  46. /// <summary>
  47. /// Gets or sets the app name.
  48. /// </summary>
  49. [MaxLength(64)]
  50. [StringLength(64)]
  51. public string AppName { get; set; }
  52. /// <summary>
  53. /// Gets or sets the app version.
  54. /// </summary>
  55. [MaxLength(32)]
  56. [StringLength(32)]
  57. public string AppVersion { get; set; }
  58. /// <summary>
  59. /// Gets or sets the device name.
  60. /// </summary>
  61. [MaxLength(64)]
  62. [StringLength(64)]
  63. public string DeviceName { get; set; }
  64. /// <summary>
  65. /// Gets or sets the device id.
  66. /// </summary>
  67. [MaxLength(256)]
  68. [StringLength(256)]
  69. public string DeviceId { get; set; }
  70. /// <summary>
  71. /// Gets or sets a value indicating whether this device is active.
  72. /// </summary>
  73. public bool IsActive { get; set; }
  74. /// <summary>
  75. /// Gets the date this device was created.
  76. /// </summary>
  77. public DateTime DateCreated { get; private set; }
  78. /// <summary>
  79. /// Gets or sets the date of last activity.
  80. /// </summary>
  81. public DateTime DateLastActivity { get; set; }
  82. /// <summary>
  83. /// Gets the user.
  84. /// </summary>
  85. public User User { get; private set; }
  86. }
  87. }