AdminLoginLog.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Director
  3. {
  4. /// <summary>
  5. /// 관리자 로그인 기록
  6. /// </summary>
  7. public class AdminLoginLog
  8. {
  9. [Key]
  10. public int ID { get; private set; }
  11. public bool Success { get; private set; } = false;
  12. public string Account { get; private set; } = default!;
  13. public string? Reason { get; private set; }
  14. public string? IpAddress { get; private set; }
  15. public string? UserAgent { get; private set; }
  16. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  17. private AdminLoginLog() { }
  18. private AdminLoginLog(bool success, string account, string? reason, string? ipAddress, string? userAgent)
  19. {
  20. if (string.IsNullOrWhiteSpace(account))
  21. {
  22. throw new ArgumentException("Account is required.", nameof(account));
  23. }
  24. if (account.Length > 120)
  25. {
  26. throw new ArgumentOutOfRangeException(nameof(account));
  27. }
  28. if (reason is not null && reason.Length > 225)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(reason));
  31. }
  32. if (ipAddress is not null && ipAddress.Length > 45)
  33. {
  34. throw new ArgumentOutOfRangeException(nameof(ipAddress));
  35. }
  36. if (userAgent is not null && userAgent.Length > 512)
  37. {
  38. throw new ArgumentOutOfRangeException(nameof(userAgent));
  39. }
  40. Success = success;
  41. Account = account;
  42. Reason = reason;
  43. IpAddress = ipAddress;
  44. UserAgent = userAgent;
  45. CreatedAt = DateTime.UtcNow;
  46. }
  47. public static AdminLoginLog Create(bool success, string account, string? reason = null, string? ipAddress = null, string? userAgent = null)
  48. {
  49. return new(success, account, reason, ipAddress, userAgent);
  50. }
  51. }
  52. }