Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
[Back] ProductDetachCategory | ProductPostPhoto | PhotoEntity - [Fron…
Browse files Browse the repository at this point in the history
…t] AdminProductPhotoEdit | AdminProductPhoto - [Front] Split AdminProductPhotoEdit | Banner (#76)

* Update package version and fix code formatting

Add missing property to Photo type

Update version number in Entity.cs

Update usePhoto method signature

Update version number in Post.cs

Update usePhoto method signature

* Add Banner component to Gallery page

* Update banner text
  • Loading branch information
Aloento authored Jan 25, 2024
1 parent 5b7a9df commit 28dc523
Show file tree
Hide file tree
Showing 18 changed files with 346 additions and 211 deletions.
18 changes: 10 additions & 8 deletions TSystems.LoveOTC/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public async Task<bool> ProductDeletePhoto(uint photoId) {
* <summary>
* Include Types -> Combos
* </summary>
*
* <remarks>
* @author Aloento
* @since 0.5.0
Expand Down Expand Up @@ -71,7 +70,6 @@ await this.Db.Variants
* <summary>
* Include Combos
* </summary>
*
* <remarks>
* @author Aloento
* @since 0.5.0
Expand Down Expand Up @@ -185,24 +183,28 @@ public async Task<bool> ProductDeleteProduct(uint prodId) {
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public async Task<bool> ProductDetachCategory(uint prodId) {
var prod = await this.Db.Products
.SingleAsync(x => x.ProductId == prodId);

if (prod.CategoryId is null)
var cate = prod.CategoryId;

if (cate is null)
return false;

prod.CategoryId = null;

var res = await this.Db.SaveChangesAsync();

await this.Db.Categories
.Where(x =>
x.CategoryId == prod.CategoryId &&
x.CategoryId == cate &&
x.Products.Count == 0)
.ExecuteDeleteAsync();

prod.CategoryId = null;

return await this.Db.SaveChangesAsync() > 0;
return res > 0;
}
}
3 changes: 2 additions & 1 deletion TSystems.LoveOTC/AdminHub/Product/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public async Task<bool> ProductPatchCaption(uint photoId, string caption) {

var row = await this.Db.Photos
.Where(x => x.PhotoId == photoId)
.ExecuteUpdateAsync(x => x.SetProperty(p => p.Caption, caption));
.ExecuteUpdateAsync(x =>
x.SetProperty(p => p.Caption, caption));

return row > 0;
}
Expand Down
8 changes: 4 additions & 4 deletions TSystems.LoveOTC/AdminHub/Product/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public async Task<bool> ProductPostMovePhoto(uint photoId, bool up) {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public async Task<bool> ProductPostPhoto(uint prodId, IAsyncEnumerable<byte[]> input) {
public async Task<uint> ProductPostPhoto(uint prodId, IAsyncEnumerable<byte[]> input) {
var exist = await this.Db.Products.AnyAsync(x => x.ProductId == prodId);
if (!exist)
throw new HubException($"Product {prodId} not found");
Expand All @@ -95,14 +95,14 @@ public async Task<bool> ProductPostPhoto(uint prodId, IAsyncEnumerable<byte[]> i

var next = (byte)(await this.Db.Photos.CountAsync(x => x.ProductId == prodId) + 1);

await this.Db.Photos.AddAsync(new() {
var photo = await this.Db.Photos.AddAsync(new() {
ProductId = prodId,
Object = obj.Entity,
Order = next
});

await this.Db.SaveChangesAsync();
return true;
return photo.Entity.PhotoId;
}

/**
Expand Down
9 changes: 1 addition & 8 deletions TSystems.LoveOTC/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public async Task<dynamic?> PhotoEntity(uint key, uint? version) {
Expand All @@ -69,13 +69,6 @@ internal partial class ShopHub {

return await this.Db.Photos
.Where(x => x.PhotoId == key)
.Select(x => new {
x.Cover,
x.Caption,
x.Order,
x.ObjectId,
x.Version
})
.SingleOrDefaultAsync();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "loveotc",
"private": true,
"version": "1.3.0",
"version": "1.3.5",
"type": "module",
"author": {
"name": "Aloento",
Expand Down
86 changes: 43 additions & 43 deletions pnpm-lock.yaml

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

Binary file added public/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 28dc523

Please sign in to comment.