Skip to content

Commit

Permalink
feat: update to bit 8.7.0 #39 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Jan 9, 2024
1 parent 8c082b7 commit 142a85d
Show file tree
Hide file tree
Showing 28 changed files with 316 additions and 292 deletions.
17 changes: 1 addition & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,13 @@
}
},
"portsAttributes": {
"4030": {
"label": "Application",
"onAutoForward": "openPreview"
},
"4031": {
"label": "Application",
"onAutoForward": "openPreview"
},
"5030": {
"label": "Api",
"onAutoForward": "openPreview"
},
"5031": {
"label": "Api",
"onAutoForward": "openPreview"
}
},
"forwardPorts": [
4030,
4031,
5030,
5031
5030
],
"remoteEnv": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Bit Foundation
Copyright (c) 2024 Bit Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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.5.0" />
<PackageReference Include="Bit.CodeAnalyzers" Version="8.6.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="8.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="8.6.0">
<PackageReference Include="Bit.SourceGenerators" Version="8.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 1 addition & 6 deletions src/Bit.TemplatePlayground.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@
@if (AppRenderMode.PwaEnabled)
{
<Script src="_framework/blazor.web.js" autostart="false"></Script>
<Script src="_content/Bit.Bswup/bit-bswup.js"
scope="/"
log="none"
sw="service-worker.js"
handler="bitBswupHandler"
blazorScript="_framework/blazor.web.js"></Script>
<Script src="_content/Bit.Bswup/bit-bswup.js"></Script>
<Script src="_content/Bit.Bswup/bit-bswup.progress.js"></Script>
<AppBswupProgressBar />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ public async Task<PagedResult<CategoryDto>> GetCategories(ODataQueryOptions<Cate
[HttpGet("{id}")]
public async Task<CategoryDto> Get(int id, CancellationToken cancellationToken)
{
var category = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
var dto = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

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

return category;
return dto;
}

[HttpPost]
public async Task<CategoryDto> Create(CategoryDto dto, CancellationToken cancellationToken)
{
var categoryToAdd = dto.Map();
var entityToAdd = dto.Map();

await DbContext.Categories.AddAsync(categoryToAdd, cancellationToken);
await DbContext.Categories.AddAsync(entityToAdd, cancellationToken);

await DbContext.SaveChangesAsync(cancellationToken);

return categoryToAdd.Map();
return entityToAdd.Map();
}

[HttpPut]
public async Task<CategoryDto> Update(CategoryDto dto, CancellationToken cancellationToken)
{
var categoryToUpdate = await DbContext.Categories.FirstOrDefaultAsync(t => t.Id == dto.Id, cancellationToken);
var entityToUpdate = await DbContext.Categories.FirstOrDefaultAsync(t => t.Id == dto.Id, cancellationToken);

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

dto.Patch(categoryToUpdate);
dto.Patch(entityToUpdate);

await DbContext.SaveChangesAsync(cancellationToken);

return categoryToUpdate.Map();
return entityToUpdate.Map();
}

[HttpDelete("{id}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ public async Task<PagedResult<ProductDto>> GetProducts(ODataQueryOptions<Product
[HttpGet("{id}")]
public async Task<ProductDto> Get(int id, CancellationToken cancellationToken)
{
var product = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
var dto = await Get().FirstOrDefaultAsync(t => t.Id == id, cancellationToken);

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

return product;
return dto;
}

[HttpPost]
public async Task<ProductDto> Create(ProductDto dto, CancellationToken cancellationToken)
{
var productToAdd = dto.Map();
var entityToAdd = dto.Map();

await DbContext.Products.AddAsync(productToAdd, cancellationToken);
await DbContext.Products.AddAsync(entityToAdd, cancellationToken);

await DbContext.SaveChangesAsync(cancellationToken);

return productToAdd.Map();
return entityToAdd.Map();
}

[HttpPut]
public async Task<ProductDto> Update(ProductDto dto, CancellationToken cancellationToken)
{
var productToUpdate = await DbContext.Products.FirstOrDefaultAsync(t => t.Id == dto.Id, cancellationToken);
var entityToUpdate = await DbContext.Products.FirstOrDefaultAsync(t => t.Id == dto.Id, cancellationToken);

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

dto.Patch(productToUpdate);
dto.Patch(entityToUpdate);

await DbContext.SaveChangesAsync(cancellationToken);

return productToUpdate.Map();
return entityToUpdate.Map();
}

[HttpDelete("{id}")]
Expand Down
8 changes: 3 additions & 5 deletions src/Bit.TemplatePlayground.Server/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ public override int SaveChanges(bool acceptAllChangesOnSuccess)

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
if (Database.ProviderName!.EndsWith("Sqlite", StringComparison.InvariantCulture))
{
configurationBuilder.Properties<DateTimeOffset>().HaveConversion<DateTimeOffsetToBinaryConverter>();
configurationBuilder.Properties<DateTimeOffset?>().HaveConversion<DateTimeOffsetToBinaryConverter>();
}
// SQLite does not support expressions of type 'DateTimeOffset' in ORDER BY clauses. Convert the values to a supported type:
configurationBuilder.Properties<DateTimeOffset>().HaveConversion<DateTimeOffsetToBinaryConverter>();
configurationBuilder.Properties<DateTimeOffset?>().HaveConversion<DateTimeOffsetToBinaryConverter>();
}

private void ConfigIdentityTables(ModelBuilder builder)
Expand Down
2 changes: 2 additions & 0 deletions src/Bit.TemplatePlayground.Server/Mappers/CategoriesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Bit.TemplatePlayground.Server.Mappers;
public static partial class CategoriesMapper
{
public static partial IQueryable<CategoryDto> Project(this IQueryable<Category> query);

[MapProperty(nameof(@Category.Products.Count), nameof(@CategoryDto.ProductsCount))]
public static partial CategoryDto Map(this Category source);
public static partial Category Map(this CategoryDto source);
public static partial void Patch(this CategoryDto source, Category destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public class Category

public string? Color { get; set; }

public IList<Product>? Products { get; set; }
public IList<Product> Products { get; set; } = [];
}
13 changes: 8 additions & 5 deletions src/Bit.TemplatePlayground.Server/Startup/Middlewares.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration
{
OnPrepareResponse = ctx =>
{
// https://bitplatform.dev/templates/cache-mechanism
ctx.Context.Response.GetTypedHeaders().CacheControl = new()
if (env.IsDevelopment() is false)
{
MaxAge = TimeSpan.FromDays(7),
Public = true
};
// https://bitplatform.dev/templates/cache-mechanism
ctx.Context.Response.GetTypedHeaders().CacheControl = new()
{
MaxAge = TimeSpan.FromDays(7),
Public = true
};
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bit.CodeAnalyzers" Version="8.6.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="8.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="8.6.0">
<PackageReference Include="Bit.SourceGenerators" Version="8.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class CategoryDto

[Display(Name = nameof(AppStrings.Color))]
public string? Color { get; set; } = "#FFFFFF";

public int ProductsCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Bit.TemplatePlayground.Shared.Exceptions;
public class ServerConnectionException : UnknownException
public class ServerConnectionException : KnownException
{
public ServerConnectionException()
: base(nameof(AppStrings.ServerConnectionException))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,7 @@
<data name="Update" xml:space="preserve">
<value>Mise à jour</value>
</data>
<data name="ProductsCount" xml:space="preserve">
<value>Les produits comptent</value>
</data>
</root>
Loading

0 comments on commit 142a85d

Please sign in to comment.