| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using Domain.Entities.Developers.ValueObject;
- using Domain.Entities.Members;
- namespace Domain.Entities.Developers;
- /// <summary>
- /// 개발자가 등록한 외부 API 앱.
- /// OAuth2 Client Credentials 발급 단위 (ApiCredential)
- /// </summary>
- public class ApiApplication
- {
- [ForeignKey(nameof(OwnerMemberID))]
- public virtual Member? Owner { get; private set; }
- public virtual ICollection<ApiCredential> Credentials { get; private set; } = new List<ApiCredential>();
- public virtual ICollection<ApiApplicationScope> Scopes { get; private set; } = new List<ApiApplicationScope>();
- [Key]
- public int ID { get; private set; }
- public int OwnerMemberID { get; private set; }
- public string Name { get; private set; } = default!;
- public string? Description { get; private set; }
- public string? HomepageUrl { get; private set; }
- public string? LogoPath { get; private set; }
- public ApplicationStatus Status { get; private set; } = ApplicationStatus.Pending;
- public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
- public DateTime? UpdatedAt { get; private set; }
- public DateTime? ApprovedAt { get; private set; }
- public DateTime? SuspendedAt { get; private set; }
- private ApiApplication() { }
- public static ApiApplication Create(int ownerMemberID, string name, string? description, string? homepageUrl)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new ArgumentException("Name is required.", nameof(name));
- }
- if (name.Length > 100)
- {
- throw new ArgumentOutOfRangeException(nameof(name));
- }
- return new ApiApplication
- {
- OwnerMemberID = ownerMemberID,
- Name = name,
- Description = description,
- HomepageUrl = homepageUrl
- };
- }
- public void UpdateInfo(string name, string? description, string? homepageUrl)
- {
- Name = name;
- Description = description;
- HomepageUrl = homepageUrl;
- UpdatedAt = DateTime.UtcNow;
- }
- public void SetLogo(string? logoPath)
- {
- LogoPath = logoPath;
- UpdatedAt = DateTime.UtcNow;
- }
- public void Approve()
- {
- Status = ApplicationStatus.Active;
- ApprovedAt = DateTime.UtcNow;
- UpdatedAt = DateTime.UtcNow;
- }
- public void Reject()
- {
- Status = ApplicationStatus.Rejected;
- UpdatedAt = DateTime.UtcNow;
- }
- public void Suspend()
- {
- Status = ApplicationStatus.Suspended;
- SuspendedAt = DateTime.UtcNow;
- UpdatedAt = DateTime.UtcNow;
- }
- public void Reactivate()
- {
- Status = ApplicationStatus.Active;
- SuspendedAt = null;
- UpdatedAt = DateTime.UtcNow;
- }
- }
|