AdminLoginLog.cs 1.8 KB

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