Skip to content

Commit

Permalink
imporved bson support as well as the documentation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fokklz committed Jan 14, 2024
1 parent 5de1b62 commit aef2c05
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 6 deletions.
8 changes: 8 additions & 0 deletions SkiServiceModels/Models/BSON/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ public class Order : OrderBase, IGenericBSONModel
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }


[BsonElement("priority_id")]
public string PriorityId { get; set; }

[BsonElement("service_id")]
public string ServiceId { get; set; }

[BsonElement("state_id")]
public string StateId { get; set; }

[BsonElement("user_id")]
public string? UserId { get; set; } = null;

[BsonIgnore]
Expand Down
9 changes: 8 additions & 1 deletion SkiServiceModels/Models/Base/OrderBase.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
using SkiServiceModels.Interfaces;
using MongoDB.Bson.Serialization.Attributes;
using SkiServiceModels.Interfaces;
using System.ComponentModel.DataAnnotations;

namespace SkiServiceModels.Models.Base
{
public class OrderBase : IGenericModel
{
[StringLength(50)]
[BsonElement("name")]
public required string Name { get; set; }

[StringLength(100)]
[BsonElement("email")]
public required string Email { get; set; }

[StringLength(20)]
[BsonElement("phone")]
public required string Phone { get; set; }

[StringLength(1000)]
[BsonElement("note")]
public string? Note { get; set; } = null;

[BsonElement("created")]
public DateTime Created { get; set; } = DateTime.Now;

[BsonElement("is_deleted")]
public bool IsDeleted { get; set; } = false;

}
Expand Down
6 changes: 5 additions & 1 deletion SkiServiceModels/Models/Base/PriorityBase.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using SkiServiceModels.Interfaces;
using MongoDB.Bson.Serialization.Attributes;
using SkiServiceModels.Interfaces;
using System.ComponentModel.DataAnnotations;

namespace SkiServiceModels.Models.Base
{
public class PriorityBase : IGenericModel
{
[StringLength(20)]
[BsonElement("name")]
public required string Name { get; set; }

[BsonElement("days")]
public int Days { get; set; }

[BsonElement("is_deleted")]
public bool IsDeleted { get; set; } = false;

}
Expand Down
7 changes: 6 additions & 1 deletion SkiServiceModels/Models/Base/ServiceBase.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using SkiServiceModels.Interfaces;
using MongoDB.Bson.Serialization.Attributes;
using SkiServiceModels.Interfaces;
using System.ComponentModel.DataAnnotations;

namespace SkiServiceModels.Models.Base
{
public class ServiceBase : IGenericModel
{
[StringLength(50)]
[BsonElement("name")]
public required string Name { get; set; }

[StringLength(1000)]
[BsonElement("description")]
public required string Description { get; set; }

[BsonElement("price")]
public int Price { get; set; }

[BsonElement("is_deleted")]
public bool IsDeleted { get; set; } = false;

}
Expand Down
5 changes: 4 additions & 1 deletion SkiServiceModels/Models/Base/StateBase.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using SkiServiceModels.Interfaces;
using MongoDB.Bson.Serialization.Attributes;
using SkiServiceModels.Interfaces;
using System.ComponentModel.DataAnnotations;

namespace SkiServiceModels.Models.Base
{
public class StateBase : IGenericModel
{
[StringLength(20)]
[BsonElement("name")]
public required string Name { get; set; }

[BsonElement("is_deleted")]
public bool IsDeleted { get; set; } = false;

}
Expand Down
9 changes: 9 additions & 0 deletions SkiServiceModels/Models/Base/UserBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using MongoDB.Bson.Serialization.Attributes;
using SkiServiceModels.Enums;
using SkiServiceModels.Interfaces;

Expand All @@ -7,20 +8,28 @@ namespace SkiServiceModels.Models.Base
public class UserBase : IGenericModel
{
[StringLength(50)]
[BsonElement("username")]
public required string Username { get; set; }

[BsonElement("password_hash")]
public byte[] PasswordHash { get; set; }

Check warning on line 15 in SkiServiceModels/Models/Base/UserBase.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Non-nullable property 'PasswordHash' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[BsonElement("password_salt")]
public byte[] PasswordSalt { get; set; }

Check warning on line 18 in SkiServiceModels/Models/Base/UserBase.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Non-nullable property 'PasswordSalt' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[BsonElement("locked")]
public bool Locked { get; set; } = false;

[BsonElement("role")]
public RoleNames Role { get; set; } = RoleNames.User;

[BsonElement("login_attempts")]
public int LoginAttempts { get; set; } = 0;

[BsonElement("refresh_token")]
public string RefreshToken { get; set; } = null;

Check warning on line 30 in SkiServiceModels/Models/Base/UserBase.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Cannot convert null literal to non-nullable reference type.

[BsonElement("is_deleted")]
public bool IsDeleted { get; set; } = false;

}
Expand Down
Binary file modified SkiServiceModels/README.md
Binary file not shown.
10 changes: 10 additions & 0 deletions SkiServiceModels/RawREADME.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,45 @@
## EF Models

### Service Model
<<MODEL::ServiceBase>>
<<EFMODEL::Service>>

### Priority Model
<<MODEL::PriorityBase>>
<<EFMODEL::Priority>>

### State Model
<<MODEL::StateBase>>
<<EFMODEL::State>>

### User Model
<<MODEL::UserBase>>
<<EFMODEL::User>>

### Order Model
<<MODEL::OrderBase>>
<<EFMODEL::Order>>

## BSON Models

### Service Model
<<MODEL::ServiceBase>>
<<BSONMODEL::Service>>

### Priority Model
<<MODEL::PriorityBase>>
<<BSONMODEL::Priority>>

### State Model
<<MODEL::StateBase>>
<<BSONMODEL::State>>

### User Model
<<MODEL::UserBase>>
<<BSONMODEL::User>>

### Order Model
<<MODEL::OrderBase>>
<<BSONMODEL::Order>>

## DTOs
Expand Down
9 changes: 7 additions & 2 deletions SkiServiceModels/prepublish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $inputFile = Join-Path $workingDirectory "RawREADME.md"
$outputFile = Join-Path $workingDirectory "README.md"

$directories = @{
"MODEL" = "Models"
"MODEL" = "Models\Base"
"EFMODEL" = "Models\EF"
"BSONMODEL" = "Models\BSON"
"DTO" = "DTOs"
Expand Down Expand Up @@ -93,7 +93,12 @@ function Extract-ClassDefinition {
$codeBlockStart = '```csharp'
$codeBlockEnd = '```'
$codeBlockInner = $classContent -join "`r`n"
return "[back up](#contents)`r`n$codeBlockStart`r`n$codeBlockInner`r`n$codeBlockEnd`r`n"

if($Type -eq 'EFMODEL' -or $Type -eq 'BSONMODEL' ){
return "$codeBlockStart`r`n$codeBlockInner`r`n$codeBlockEnd`r`n"
}else{
return "[back up](#contents)`r`n$codeBlockStart`r`n$codeBlockInner`r`n$codeBlockEnd`r`n"
}
}

$content = Get-Content $inputFile
Expand Down

0 comments on commit aef2c05

Please sign in to comment.