Skip to content

Commit

Permalink
feat: update to bit platform 8.4.0 #33 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Dec 14, 2023
1 parent 6faa810 commit 31f76e3
Show file tree
Hide file tree
Showing 87 changed files with 1,951 additions and 1,546 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18

# - name: Enable pre rendering
# run: sed -i 's/public static readonly bool PrerenderEnabled = false;/public static readonly bool PrerenderEnabled = true;/g' src/Client/Bit.TemplatePlayground.Client.Core/Services/AppRenderMode.cs

- name: Update appsettings.json api server address
uses: microsoft/variable-substitution@v1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ custom.aprof

/src/Client/Bit.TemplatePlayground.Client.Core/wwwroot/scripts/app*.js

/src/Bit.TemplatePlayground.Server/Bit.TemplatePlaygroundDb.db*
/src/Bit.TemplatePlayground.Server/*.db*
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bit.TemplatePlayground.Shared\Bit.TemplatePlayground.Shared.csproj" />
<ProjectReference Include="..\Bit.TemplatePlayground.Shared\Bit.TemplatePlayground.Shared.csproj" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions src/Bit.TemplatePlayground.Server/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class AppSettings
public HealthCheckSettings HealthCheckSettings { get; set; } = default!;

public string UserProfileImagesDir { get; set; } = default!;

public string WebServerAddress { get; set; } = default!;
}

public class HealthCheckSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.4.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="8.2.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="8.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="8.2.0">
<PackageReference Include="Bit.SourceGenerators" Version="8.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down Expand Up @@ -63,7 +63,6 @@

<ItemGroup>
<ProjectReference Include="..\Bit.TemplatePlayground.Shared\Bit.TemplatePlayground.Shared.csproj" />
<ProjectReference Include="..\Client\Bit.TemplatePlayground.Client.Core\Bit.TemplatePlayground.Client.Core.csproj" />
<ProjectReference Include="..\Client\Bit.TemplatePlayground.Client.Web\Bit.TemplatePlayground.Client.Web.csproj" />
</ItemGroup>

Expand All @@ -86,4 +85,13 @@
</None>
</ItemGroup>

<!-- https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container -->
<PropertyGroup>
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<UserSecretsId>AC87AA5B-4B37-4E52-8468-2D5DF24AF256</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Bit.TemplatePlayground.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
</head>

<body class="@BitCss.Class.Color.Background.Primary @BitCss.Class.Color.Foreground.Primary">
<body class="@BitCss.Class.Color.Background.Primary @BitCss.Class.Color.Foreground.Primary bit-blazor-web">

<Link rel="stylesheet" href="_content/Bit.BlazorUI/styles/bit.blazorui.css" />
<Link rel="stylesheet" href="_content/Bit.BlazorUI.Icons/styles/bit.blazorui.icons.css" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@code {
@using Bit.TemplatePlayground.Server.Models.Emailing
@using Bit.TemplatePlayground.Server.Resources

@code {
[Parameter] public EmailConfirmationModel Model { get; set; } = default!;
[Parameter] public HttpContext HttpContext { get; set; } = default!;
[Inject] public IStringLocalizer<EmailStrings> EmailLocalizer { get; set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@using Bit.TemplatePlayground.Server.Models.Emailing
@using Bit.TemplatePlayground.Server.Resources

@code {
[Parameter] public ResetPasswordModel Model { get; set; } = default!;
[Parameter] public HttpContext HttpContext { get; set; } = default!;
Expand Down
18 changes: 14 additions & 4 deletions src/Bit.TemplatePlayground.Server/Components/Script.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@

@code {
[Parameter] public bool AppendVersion { get; set; } = true;
[Parameter] public required string Src { get; set; } = "";
[Parameter] public string? Src { get; set; }
[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> AdditionalAttributes { get; set; } = default!;

private string src = "";
private string? src;

protected override void OnInitialized()
{
src = AppendVersion ? _fileVersionProvider.AddFileVersionToPath(_httpContextAccessor.HttpContext!.Request.PathBase, Src) : Src;
src = (Src is not null && AppendVersion) ? _fileVersionProvider.AddFileVersionToPath(_httpContextAccessor.HttpContext!.Request.PathBase, Src) : Src;
}
}

<script src="@src" @attributes="AdditionalAttributes"></script>
@if (src is not null)
{
<script src="@src" @attributes="AdditionalAttributes"></script>
}
else
{
<script @attributes="AdditionalAttributes">
@ChildContent
</script>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Bit.TemplatePlayground.Server.Models.Categories;
using Bit.TemplatePlayground.Client.Core.Controllers.Categories;
using Bit.TemplatePlayground.Server.Models.Categories;
using Bit.TemplatePlayground.Shared.Dtos.Categories;

namespace Bit.TemplatePlayground.Server.Controllers;

[Route("api/[controller]/[action]")]
[ApiController]
public partial class CategoryController : AppControllerBase
public partial class CategoryController : AppControllerBase, ICategoryController
{
[HttpGet, EnableQuery]
public IQueryable<CategoryDto> Get()
Expand All @@ -14,17 +15,6 @@ public IQueryable<CategoryDto> Get()
.Project();
}

[HttpGet("{id:int}")]
public async Task<CategoryDto> Get(int id, CancellationToken cancellationToken)
{
var category = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

if (category is null)
throw new ResourceNotFoundException(Localizer[nameof(AppStrings.CategoryCouldNotBeFound)]);

return category;
}

[HttpGet]
public async Task<PagedResult<CategoryDto>> GetCategories(ODataQueryOptions<CategoryDto> odataQuery, CancellationToken cancellationToken)
{
Expand All @@ -41,6 +31,17 @@ public async Task<PagedResult<CategoryDto>> GetCategories(ODataQueryOptions<Cate
return new PagedResult<CategoryDto>(query.AsAsyncEnumerable(), totalCount);
}

[HttpGet("{id}")]
public async Task<CategoryDto> Get(int id, CancellationToken cancellationToken)
{
var category = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

if (category is null)
throw new ResourceNotFoundException(Localizer[nameof(AppStrings.CategoryCouldNotBeFound)]);

return category;
}

[HttpPost]
public async Task<CategoryDto> Create(CategoryDto dto, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public async Task<CategoryDto> Update(CategoryDto dto, CancellationToken cancell
return categoryToUpdate.Map();
}

[HttpDelete("{id:int}")]
[HttpDelete("{id}")]
public async Task Delete(int id, CancellationToken cancellationToken)
{
if (await DbContext.Products.AnyAsync(p => p.CategoryId == id, cancellationToken))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
using Bit.TemplatePlayground.Shared.Dtos.Dashboard;
using Bit.TemplatePlayground.Client.Core.Controllers.Dashboard;

namespace Bit.TemplatePlayground.Server.Controllers;

[Route("api/[controller]/[action]")]
[ApiController]
public partial class DashboardController : AppControllerBase
public partial class DashboardController : AppControllerBase, IDashboardController
{
[HttpGet]
public async Task<OverallAnalyticsStatsDataResponseDto> GetOverallAnalyticsStatsData()
public async Task<OverallAnalyticsStatsDataResponseDto> GetOverallAnalyticsStatsData(CancellationToken cancellationToken)
{
var result = new OverallAnalyticsStatsDataResponseDto();

var last30DaysDate = DateTimeOffset.UtcNow.AddDays(-30);

result.TotalProducts = await DbContext.Products.CountAsync();
result.Last30DaysProductCount = await DbContext.Products.CountAsync(p => p.CreatedOn > last30DaysDate);
result.TotalCategories = await DbContext.Categories.CountAsync();
result.TotalProducts = await DbContext.Products.CountAsync(cancellationToken);
result.Last30DaysProductCount = await DbContext.Products.CountAsync(p => p.CreatedOn > last30DaysDate, cancellationToken);
result.TotalCategories = await DbContext.Categories.CountAsync(cancellationToken);

return result;
}

[HttpGet]
public async Task<IAsyncEnumerable<ProductsCountPerCategoryResponseDto>> GetProductsCountPerCategotyStats()
public async Task<IAsyncEnumerable<ProductsCountPerCategoryResponseDto>> GetProductsCountPerCategoryStats(CancellationToken cancellationToken)
{
return DbContext.Categories
.Select(c => new ProductsCountPerCategoryResponseDto()
Expand All @@ -33,7 +34,7 @@ public async Task<IAsyncEnumerable<ProductsCountPerCategoryResponseDto>> GetProd
}

[HttpGet]
public async Task<IAsyncEnumerable<ProductSaleStatResponseDto>> GetProductsSalesStats()
public async Task<IAsyncEnumerable<ProductSaleStatResponseDto>> GetProductsSalesStats(CancellationToken cancellationToken)
{
Random rand = new Random();
return DbContext.Products.Include(p => p.Category)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Web;
using Bit.TemplatePlayground.Client.Core.Controllers.Identity;
using Bit.TemplatePlayground.Server.Components;
using Bit.TemplatePlayground.Server.Models.Emailing;
using Bit.TemplatePlayground.Server.Models.Identity;
Expand All @@ -13,7 +14,7 @@ namespace Bit.TemplatePlayground.Server.Controllers.Identity;

[Microsoft.AspNetCore.Mvc.Route("api/[controller]/[action]")]
[ApiController, AllowAnonymous]
public partial class IdentityController : AppControllerBase
public partial class IdentityController : AppControllerBase, IIdentityController
{
[AutoInject] private UserManager<User> userManager = default!;

Expand Down Expand Up @@ -150,7 +151,7 @@ public async Task<ActionResult> ConfirmEmail(string email, string token)
return Redirect(url);
}

[HttpPost]
[HttpPost, ProducesResponseType<TokenResponseDto>(statusCode: 200)]
public async Task SignIn(SignInRequestDto signInRequest)
{
signInManager.AuthenticationScheme = IdentityConstants.BearerScheme;
Expand Down Expand Up @@ -246,7 +247,7 @@ public async Task SendResetPasswordEmail(SendResetPasswordEmailRequestDto sendRe
}

[HttpPost]
public async Task ResetPassword(ResetPasswordRequestDto resetPasswordRequest)
public async Task ResetPassword(ResetPasswordRequestDto resetPasswordRequest, CancellationToken cancellationToken)
{
var user = await userManager.FindByEmailAsync(resetPasswordRequest.Email!);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Bit.TemplatePlayground.Server.Models.Identity;
using Bit.TemplatePlayground.Client.Core.Controllers.Identity;
using Bit.TemplatePlayground.Server.Models.Identity;
using Bit.TemplatePlayground.Shared.Dtos.Identity;

namespace Bit.TemplatePlayground.Server.Controllers.Identity;

[Route("api/[controller]/[action]")]
[ApiController]
public partial class UserController : AppControllerBase
public partial class UserController : AppControllerBase, IUserController
{
[AutoInject] private UserManager<User> userManager = default!;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Bit.TemplatePlayground.Server.Models.Products;
using Bit.TemplatePlayground.Client.Core.Controllers.Product;
using Bit.TemplatePlayground.Server.Models.Products;
using Bit.TemplatePlayground.Shared.Dtos.Products;

namespace Bit.TemplatePlayground.Server.Controllers;

[Route("api/[controller]/[action]")]
[ApiController]
public partial class ProductController : AppControllerBase
public partial class ProductController : AppControllerBase, IProductController
{
[HttpGet, EnableQuery]
public IQueryable<ProductDto> Get()
Expand All @@ -14,17 +15,6 @@ public IQueryable<ProductDto> Get()
.Project();
}

[HttpGet("{id:int}")]
public async Task<ProductDto> Get(int id, CancellationToken cancellationToken)
{
var product = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

if (product is null)
throw new ResourceNotFoundException(Localizer[nameof(AppStrings.ProductCouldNotBeFound)]);

return product;
}

[HttpGet]
public async Task<PagedResult<ProductDto>> GetProducts(ODataQueryOptions<ProductDto> odataQuery, CancellationToken cancellationToken)
{
Expand All @@ -41,6 +31,17 @@ public async Task<PagedResult<ProductDto>> GetProducts(ODataQueryOptions<Product
return new PagedResult<ProductDto>(query.AsAsyncEnumerable(), totalCount);
}

[HttpGet("{id}")]
public async Task<ProductDto> Get(int id, CancellationToken cancellationToken)
{
var product = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

if (product is null)
throw new ResourceNotFoundException(Localizer[nameof(AppStrings.ProductCouldNotBeFound)]);

return product;
}

[HttpPost]
public async Task<ProductDto> Create(ProductDto dto, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public async Task<ProductDto> Update(ProductDto dto, CancellationToken cancellat
return productToUpdate.Map();
}

[HttpDelete("{id:int}")]
[HttpDelete("{id}")]
public async Task Delete(int id, CancellationToken cancellationToken)
{
DbContext.Remove(new Product { Id = id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ProductConfiguration : IEntityTypeConfiguration<Product>
{
public void Configure(EntityTypeBuilder<Product> builder)
{
DateTime baseDate = DateTime.Parse("2023-12-04");
DateTime baseDate = DateTime.Parse("2023-12-14");

builder.HasData(
new() { Id = 1, Name = "Mustang", Price = 27155, Description = "The Ford Mustang is ranked #1 in Sports Cars", CreatedOn = baseDate.AddDays(-10), CategoryId = 1 },
Expand Down
Loading

0 comments on commit 31f76e3

Please sign in to comment.