Files
Sergio Matias Urquin 83fc1878c4 Add project files.
2025-04-29 18:42:29 -06:00

81 lines
2.8 KiB
C#

using Core.Blueprint.Mongo;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
public class Document : IDocument
{
/// <summary>
/// Gets or sets the MongoDB ObjectId for the document.
/// This property is automatically generated if not provided.
/// It is used as the primary key for the document in MongoDB.
/// </summary>
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
[JsonPropertyName("_id")]
public string _Id { get; init; }
/// <summary>
/// Gets or sets a unique identifier for the document, represented as a string (GUID).
/// This value is automatically generated if not provided and can be used as a secondary key.
/// </summary>
[BsonElement("id")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("id")]
public string Id { get; init; }
/// <summary>
/// Gets or sets the timestamp of when the document was created.
/// This value is automatically set to the current UTC time when the document is created.
/// </summary>
[BsonElement("createdAt")]
[BsonRepresentation(BsonType.DateTime)]
[JsonPropertyName("createdAt")]
public DateTime CreatedAt { get; init; }
/// <summary>
/// Gets or sets the user or system who created the document.
/// This field can be used for audit purposes.
/// </summary>
[BsonElement("createdBy")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("createdBy")]
public string? CreatedBy { get; set; }
/// <summary>
/// Gets or sets the timestamp of when the document was last updated.
/// This value is nullable and will be set to null if the document has never been updated.
/// </summary>
[BsonElement("updatedAt")]
[BsonRepresentation(BsonType.DateTime)]
[JsonPropertyName("updatedAt")]
public DateTime? UpdatedAt { get; set; } = null;
/// <summary>
/// Gets or sets the user or system who last updated the document.
/// This field can be used for audit purposes.
/// </summary>
[BsonElement("updatedBy")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("updatedBy")]
public string? UpdatedBy { get; set; } = null;
/// <summary>
/// Gets or sets the status of the document.
/// The status is represented by an enum and defaults to <see cref="StatusEnum.Active"/>.
/// </summary>
[BsonElement("status")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("status")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public StatusEnum? Status { get; set; }
public Document()
{
_Id = ObjectId.GenerateNewId().ToString();
Id = Guid.NewGuid().ToString();
CreatedAt = DateTime.UtcNow;
Status = StatusEnum.Active;
}
}