Skip to content

Commit

Permalink
(#421) identity: update infrastructure extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 22, 2024
1 parent a735c82 commit e5b62ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public static User AsEntity(this UserDocument document)
TwoFactorSecret = document.TwoFactorSecret
};

// Setting the online status and IP address
user.SetOnlineStatus(document.IsOnline, document.DeviceType);
user.UpdateLastActive();
user.UpdateLastActive();

return user;
}

// Convert User Entity to UserDocument
public static UserDocument AsDocument(this User entity)
=> new UserDocument
{
Expand All @@ -44,7 +46,9 @@ public static UserDocument AsDocument(this User entity)
TwoFactorSecret = entity.TwoFactorSecret,
IsOnline = entity.IsOnline,
DeviceType = entity.DeviceType,
LastActive = entity.LastActive
LastActive = entity.LastActive,

IpAddress = entity.IpAddress
};

public static UserDto AsDto(this UserDocument document)
Expand All @@ -62,12 +66,16 @@ public static UserDto AsDto(this UserDocument document)
TwoFactorSecret = document.TwoFactorSecret,
IsOnline = document.IsOnline,
DeviceType = document.DeviceType,
LastActive = document.LastActive
LastActive = document.LastActive,

IpAddress = document.IpAddress
};

// Convert RefreshTokenDocument to RefreshToken Entity
public static RefreshToken AsEntity(this RefreshTokenDocument document)
=> new RefreshToken(document.Id, document.UserId, document.Token, document.CreatedAt, document.RevokedAt);

// Convert RefreshToken Entity to RefreshTokenDocument
public static RefreshTokenDocument AsDocument(this RefreshToken entity)
=> new RefreshTokenDocument
{
Expand All @@ -78,6 +86,7 @@ public static RefreshTokenDocument AsDocument(this RefreshToken entity)
RevokedAt = entity.RevokedAt
};

// Convert UserResetToken Entity to UserResetTokenDto
public static UserResetTokenDto AsDto(this UserResetToken userResetToken)
=> new UserResetTokenDto
{
Expand All @@ -86,14 +95,16 @@ public static UserResetTokenDto AsDto(this UserResetToken userResetToken)
ResetTokenExpires = userResetToken.ResetTokenExpires
};

public static UserResetToken AsEntity(this UserResetTokenDocument document)
// Convert UserResetTokenDocument to UserResetToken Entity
public static UserResetToken AsEntity(this UserResetTokenDocument document)
=> new UserResetToken(
document.UserId,
document.ResetToken,
document.ResetTokenExpires ?? DateTime.MinValue
);

public static UserResetTokenDocument AsDocument(this UserResetToken userResetToken)
// Convert UserResetToken Entity to UserResetTokenDocument
public static UserResetTokenDocument AsDocument(this UserResetToken userResetToken)
{
if (userResetToken == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ internal sealed class UserDocument : IIdentifiable<Guid>
public bool IsOnline { get; set; }
public string DeviceType { get; set; }
public DateTime? LastActive { get; set; }
public string IpAddress { get; set; }
}
}

0 comments on commit e5b62ff

Please sign in to comment.