:drunk: AI trying to fix bugs

This commit is contained in:
2025-07-06 21:15:30 +08:00
parent 3391c08c04
commit 7d1f096e87
70 changed files with 681 additions and 66945 deletions

View File

@ -1,6 +1,8 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using System.Text.Json.Serialization;
using NodaTime;
namespace DysonNetwork.Common.Models;
@ -8,15 +10,8 @@ namespace DysonNetwork.Common.Models;
/// <summary>
/// Represents a connection between an account and an authentication provider
/// </summary>
public class AccountConnection
public class AccountConnection : ModelBase
{
/// <summary>
/// Unique identifier for the connection
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; } = null!;
/// <summary>
/// The account ID this connection is associated with
/// </summary>
@ -36,6 +31,16 @@ public class AccountConnection
[MaxLength(256)]
public string ProvidedIdentifier { get; set; } = null!;
/// <summary>
/// Alias for ProvidedIdentifier for backward compatibility
/// </summary>
[NotMapped]
public string ProviderId
{
get => ProvidedIdentifier;
set => ProvidedIdentifier = value;
}
/// <summary>
/// Display name for the connection
/// </summary>
@ -57,6 +62,27 @@ public class AccountConnection
/// </summary>
public Instant? ExpiresAt { get; set; }
/// <summary>
/// Raw profile data from the provider
/// </summary>
[Column(TypeName = "jsonb")]
public JsonDocument? ProfileData { get; set; }
/// <summary>
/// When the connection was first established
/// </summary>
public Instant ConnectedAt { get; set; } = SystemClock.Instance.GetCurrentInstant();
/// <summary>
/// Additional metadata about the connection
/// </summary>
[Column(TypeName = "jsonb")]
public JsonDocument? Metadata { get; set; }
/// <summary>
/// Gets a value indicating whether the connection is currently active
/// </summary>
[NotMapped]
/// <summary>
/// When the connection was first established
/// </summary>
@ -67,15 +93,33 @@ public class AccountConnection
/// </summary>
public Instant? LastUsedAt { get; set; }
/// <summary>
/// Additional metadata about the connection
/// </summary>
[Column(TypeName = "jsonb")]
public Dictionary<string, object>? Meta { get; set; }
/// <summary>
/// Navigation property for the associated account
/// </summary>
[ForeignKey(nameof(AccountId))]
[JsonIgnore]
public virtual Account? Account { get; set; }
/// <summary>
/// Updates the connection's tokens and related metadata
/// </summary>
/// <param name="accessToken">The new access token</param>
/// <param name="refreshToken">The new refresh token, if any</param>
/// <param name="expiresAt">When the access token expires, if any</param>
public void UpdateTokens(string? accessToken, string? refreshToken, Instant? expiresAt)
{
AccessToken = accessToken;
if (!string.IsNullOrEmpty(refreshToken))
{
RefreshToken = refreshToken;
}
if (expiresAt.HasValue)
{
ExpiresAt = expiresAt;
}
LastUsedAt = SystemClock.Instance.GetCurrentInstant();
}
}