Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions API/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,17 @@ public async Task<IActionResult> OrderCategories(IList<int> ids)
await productService.OrderCategories(ids);
return Ok();
}

/// <summary>
/// Re-order products, requires all products to be part of the same category
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[HttpPost("order")]
[Authorize(Policy = PolicyConstants.ManageProducts)]
public async Task<IActionResult> OrderProducts(IList<int> ids)
{
await productService.OrderProducts(ids);
return Ok();
}
}
15 changes: 15 additions & 0 deletions API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,20 @@ public async Task<ActionResult<IList<UserDto>>> Search([FromQuery] string query)

return Ok(await unitOfWork.UsersRepository.Search(query));
}

/// <summary>
/// Update non OIDC synced attributes of a user
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult<UserDto>> UpdateUser(UserDto user)
{
var updated = await userService.Update(User, user);

var dto = mapper.Map<UserDto>(updated);
dto.Roles = HttpContext.User.GetRoles();
return Ok(dto);
}

}
1 change: 1 addition & 0 deletions API/DTOs/ProductDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public sealed record ProductDto
public string Name { get; set; }
public string Description { get; set; } = string.Empty;
public int CategoryId { get; set; }
public int SortValue { get; set; }
public ProductType Type { get; set; }
public bool IsTracked { get; set; }
public bool Enabled { get; set; }
Expand Down
1 change: 1 addition & 0 deletions API/DTOs/UserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class UserDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Language { get; set; }
public IList<string> Roles { get; set; } = [];
}
8 changes: 8 additions & 0 deletions API/Data/Repositories/ProductRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IProductRepository
Task<IList<ProductCategory>> GetAllCategories(bool onlyEnabled = false);
Task<IList<ProductCategoryDto>> GetAllCategoriesDtos(bool onlyEnabled = false);
Task<IList<Product>> GetByCategory(ProductCategory category);
Task<int> GetHighestSortValue(ProductCategory category);
void Add(Product product);
void Add(ProductCategory category);
void Update(Product product);
Expand Down Expand Up @@ -107,6 +108,13 @@ public async Task<IList<Product>> GetByCategory(ProductCategory category)
.ToListAsync();
}

public async Task<int> GetHighestSortValue(ProductCategory category)
{
return await ctx.Products
.Where(p => p.CategoryId == category.Id)
.MaxAsync(p => p.SortValue);
}

public void Add(Product product)
{
ctx.Products.Add(product).State = EntityState.Added;
Expand Down
4 changes: 4 additions & 0 deletions API/Entities/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class Product

public int CategoryId { get; set; }
public ProductCategory Category { get; set; }
/// <summary>
/// This value is valid inside a category, not between
/// </summary>
public int SortValue { get; set; }
public ProductType Type { get; set; }

public bool IsTracked { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions API/I18N/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"client-update-company-number-note": "Het bedrijfsnummer van deze klant is bijgewerkt sinds deze levering werd gestart. Van: {0} naar {1}.",
"client-update-address-note": "Het adres van deze klant is bijgewerkt sinds deze levering werd gestart. Van {0} naar {1}.",
"client-update-invoice-email": "Het factuur e-mailadres van deze klant is bijgewerkt sinds deze levering werd gestart. Van {0} naar {1}.",
"stock-bulk-stocks-not-found": "Kon geen voorraad vinden voor product-id's: {0}",
"stock-bulk-insufficient-stock": "{0} heeft niet genoeg items op voorraad. Heeft {1}, nodig: {2}"

}
49 changes: 49 additions & 0 deletions API/ManualMigrations/ManualMigrationAddProductSortValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using API.Data;
using API.Entities;
using API.Helpers;
using Microsoft.EntityFrameworkCore;

namespace API.ManualMigrations;

public static class ManualMigrationAddProductSortValues
{

public static async Task Migrate(DataContext ctx, ILogger<Program> logger)
{
if (await ctx.ManualMigrations.AnyAsync(mm => mm.Name.Equals("ManualMigrationAddProductSortValues")))
{
return;
}

logger.LogCritical("Running ManualMigrationAddProductSortValues migration - Please be patient, this may take some time. This is not an error");


var products = await ctx.Products.ToListAsync();
var productsByCategory = products.GroupBy(p => p.CategoryId);

foreach (var grouping in productsByCategory)
{
var idx = 0;
using var iter = grouping.OrderBy(p => p.NormalizedName).GetEnumerator();
while (iter.MoveNext())
{
var product = iter.Current;
product.SortValue = idx++;
}
}

await ctx.SaveChangesAsync();

await ctx.ManualMigrations.AddAsync(new ManualMigration
{
Name = "ManualMigrationAddProductSortValues",
ProductVersion = BuildInfo.Version.ToString(),
RanAt = DateTime.UtcNow
});
await ctx.SaveChangesAsync();

logger.LogCritical("Running ManualMigrationAddProductSortValues migration - Completed. This is not an error");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace API.ManualMigrations;

public class ManualMigrationAddStockForExistingProducts
public static class ManualMigrationAddStockForExistingProducts
{
public static async Task Migrate(DataContext ctx, ILogger<Program> logger)
{
Expand Down
Loading