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

Commit

Permalink
[Back] Use TypeId | ProductGetTypes | ProductGetVariants | ProductPat…
Browse files Browse the repository at this point in the history
…chType | GuestVisit - [Front] AdminProductComboDetail | AdminProductNewCombo | useVariants | useTypes | useTypeList | useVariantName | useType | useVariant
  • Loading branch information
Aloento committed Mar 2, 2024
1 parent 85fb050 commit 62d4860
Show file tree
Hide file tree
Showing 27 changed files with 882 additions and 813 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## LoveOTC

An online shop for OTC members to order merchandise.

## Basic Requirements

- .NET 8
- Node.js 17+
- Visual Studio 2022 Preview
- Visual Studio Code
6 changes: 3 additions & 3 deletions TSystems.LoveOTC/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ private async Task deleteType(Type type) {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* @version 0.3.0
* </remarks>
*/
public async Task<bool> ProductDeleteType(uint variantId, string reqType) {
public async Task<bool> ProductDeleteType(uint typeId) {
await this.deleteType(
await this.Db.Types
.Where(x => x.VariantId == variantId && x.Name == reqType)
.Where(x => x.TypeId == typeId)
.IncludeOptimized(x => x.Combos)
.SingleAsync()
);
Expand Down
24 changes: 17 additions & 7 deletions TSystems.LoveOTC/AdminHub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ await this.Db.Products
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<dynamic[]> ProductGetVariants(uint prodId) =>
await this.Db.Variants
public Task<uint[]> ProductGetVariants(uint prodId) =>
this.Db.Variants
.Where(x => x.ProductId == prodId)
.Select(x => new {
x.VariantId,
Types = x.Types.Select(t => t.TypeId).ToArray()
})
.Select(x => x.VariantId)
.ToArrayAsync();

/**
* <remarks>
* @author Aloento
* @since 1.3.0
* @version 0.1.0
* </remarks>
*/
public Task<uint[]> ProductGetTypes(uint variantId) =>
this.Db.Types
.Where(x => x.VariantId == variantId)
.Select(x => x.TypeId)
.ToArrayAsync();
}
6 changes: 3 additions & 3 deletions TSystems.LoveOTC/AdminHub/Product/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ private async Task<List<Combo>> archiveCombos(ICollection<Combo> oldCombos) {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<bool> ProductPatchType(uint variantId, string oldName, string newName) {
public async Task<bool> ProductPatchType(uint typeId, string newName) {
var valid = typeof(Type)
.GetProperty(nameof(Type.Name))!
.GetCustomAttribute<StringLengthAttribute>()!;
Expand All @@ -240,7 +240,7 @@ public async Task<bool> ProductPatchType(uint variantId, string oldName, string
throw new HubException(valid.FormatErrorMessage("Name"));

var type = this.Db.Types
.Where(x => x.VariantId == variantId && x.Name == oldName);
.Where(x => x.TypeId == typeId);

var any = await type
.SelectMany(x => x.Combos)
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 @@ -110,7 +110,7 @@ public async Task<uint> ProductPostPhoto(uint prodId, IAsyncEnumerable<byte[]> i
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public async Task<uint> ProductPostVariant(uint prodId, string name) {
Expand Down Expand Up @@ -138,14 +138,14 @@ public async Task<uint> ProductPostVariant(uint prodId, string name) {
});

await this.Db.SaveChangesAsync();
return temp.Entity.ProductId;
return temp.Entity.VariantId;
}

/**
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public async Task<uint> ProductPostType(uint variantId, string name) {
Expand Down Expand Up @@ -173,7 +173,7 @@ public async Task<uint> ProductPostType(uint variantId, string name) {
});

await this.Db.SaveChangesAsync();
return temp.Entity.VariantId;
return temp.Entity.TypeId;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions TSystems.LoveOTC/Helpers/DataSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static async Task SeedData(IApplicationBuilder host) {
Category = jacketCate,
Photos = [
new() {
Cover = true,
Order = 1,
Object = new() { Data = jacket1 }
},
Expand Down Expand Up @@ -157,7 +156,6 @@ public static async Task SeedData(IApplicationBuilder host) {
Category = shirtCate,
Photos = [
new() {
Cover = true,
Order = 1,
Object = new() { Data = tMale1 }
},
Expand Down Expand Up @@ -270,7 +268,6 @@ public static async Task SeedData(IApplicationBuilder host) {
Category = shirtCate,
Photos = [
new() {
Cover = true,
Order = 1,
Object = new() { Data = tFemale1 }
},
Expand Down
12 changes: 11 additions & 1 deletion TSystems.LoveOTC/Helpers/LoggerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ namespace TSystems.LoveOTC.Helpers;
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.2.0
* </remarks>
*/
internal static partial class LoggerExtension {
[LoggerMessage(
EventId = 1001,
Level = LogLevel.Debug,
Message = "Guest : Visit from [{ip}]"
)]
private static partial void guestVisit(ILogger logger, string? ip);

public static void GuestVisit(this ILogger logger, HubCallerContext ctx) =>
guestVisit(logger, ctx.GetHttpContext()?.Connection.RemoteIpAddress?.ToString());

[LoggerMessage(
EventId = 2001,
Level = LogLevel.Information,
Message = "User {name} : [{uid}] Logged from [{ip}]"
)]
private static partial void userLogin(ILogger logger, string? name, string? uid, string? ip);
Expand Down
5 changes: 3 additions & 2 deletions TSystems.LoveOTC/Hub/ShopHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal partial class ShopHub(ShopContext db, ILogger<ShopHub> logger) : CraftH
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.1.1
* </remarks>
*/
public override async Task OnConnectedAsync() {
Expand All @@ -34,7 +34,8 @@ public override async Task OnConnectedAsync() {
await this.Clients.Caller.OnNewUser();
this.Context.Items.TryAdd("NewUser", true);
}
}
} else
this.Logger.GuestVisit(this.Context);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "loveotc",
"private": true,
"version": "1.4.0",
"version": "1.4.5",
"type": "module",
"author": {
"name": "Aloento",
Expand All @@ -15,7 +15,7 @@
"update": "npx npm-check-updates -u"
},
"dependencies": {
"@fluentui/react-components": "^9.46.6",
"@fluentui/react-components": "^9.46.7",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.230",
"@griffel/react": "^1.5.20",
Expand Down Expand Up @@ -52,7 +52,7 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.2.60",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react-swc": "^3.6.0",
"typescript": "^5.3.3",
Expand Down
Loading

0 comments on commit 62d4860

Please sign in to comment.