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

Commit 4c6e8c8

Browse files
authored
[Back | DB] SeedRealData (#65)
* Update Product model and Auth component * Refactor data seeding in Program.cs and DataSeeder.cs
1 parent 070839d commit 4c6e8c8

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

TSystems.LoveOTC/Helpers/DataSeeder.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace TSystems.LoveOTC.Helpers;
1010
* </remarks>
1111
*/
1212
internal static class DataSeeder {
13-
public static async Task SeedData(this IApplicationBuilder host) {
13+
public static async Task SeedData(IApplicationBuilder host) {
1414
await using var scope = host.ApplicationServices.CreateAsyncScope();
1515
await using var context = scope.ServiceProvider.GetRequiredService<ShopContext>();
1616

@@ -174,7 +174,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
174174

175175
var mShirtSComb = context.Combos.Add(new() {
176176
Stock = 25,
177-
Product = jacketProd,
177+
Product = mShirtProd,
178178
Types = [mShirtSType]
179179
}).Entity;
180180

@@ -185,7 +185,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
185185

186186
var mShirtMComb = context.Combos.Add(new() {
187187
Stock = 105,
188-
Product = jacketProd,
188+
Product = mShirtProd,
189189
Types = [mShirtMType]
190190
}).Entity;
191191

@@ -196,7 +196,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
196196

197197
var mShirtLComb = context.Combos.Add(new() {
198198
Stock = 115,
199-
Product = jacketProd,
199+
Product = mShirtProd,
200200
Types = [mShirtLType]
201201
}).Entity;
202202

@@ -207,7 +207,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
207207

208208
var mShirt1XLComb = context.Combos.Add(new() {
209209
Stock = 115,
210-
Product = jacketProd,
210+
Product = mShirtProd,
211211
Types = [mShirt1XLType]
212212
}).Entity;
213213

@@ -218,7 +218,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
218218

219219
var mShirt2XLComb = context.Combos.Add(new() {
220220
Stock = 85,
221-
Product = jacketProd,
221+
Product = mShirtProd,
222222
Types = [mShirt2XLType]
223223
}).Entity;
224224

@@ -229,7 +229,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
229229

230230
var mShirt3XLComb = context.Combos.Add(new() {
231231
Stock = 27,
232-
Product = jacketProd,
232+
Product = mShirtProd,
233233
Types = [mShirt3XLType]
234234
}).Entity;
235235

@@ -240,7 +240,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
240240

241241
var mShirt4XLComb = context.Combos.Add(new() {
242242
Stock = 15,
243-
Product = jacketProd,
243+
Product = mShirtProd,
244244
Types = [mShirt4XLType]
245245
}).Entity;
246246

@@ -278,7 +278,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
278278

279279
var fShirtSComb = context.Combos.Add(new() {
280280
Stock = 28,
281-
Product = jacketProd,
281+
Product = fShirtProd,
282282
Types = [fShirtSType]
283283
}).Entity;
284284

@@ -289,7 +289,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
289289

290290
var fShirtMComb = context.Combos.Add(new() {
291291
Stock = 50,
292-
Product = jacketProd,
292+
Product = fShirtProd,
293293
Types = [fShirtMType]
294294
}).Entity;
295295

@@ -300,7 +300,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
300300

301301
var fShirtLComb = context.Combos.Add(new() {
302302
Stock = 55,
303-
Product = jacketProd,
303+
Product = fShirtProd,
304304
Types = [fShirtLType]
305305
}).Entity;
306306

@@ -311,7 +311,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
311311

312312
var fShirt1XLComb = context.Combos.Add(new() {
313313
Stock = 20,
314-
Product = jacketProd,
314+
Product = fShirtProd,
315315
Types = [fShirt1XLType]
316316
}).Entity;
317317

@@ -322,7 +322,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
322322

323323
var fShirt2XLComb = context.Combos.Add(new() {
324324
Stock = 6,
325-
Product = jacketProd,
325+
Product = fShirtProd,
326326
Types = [fShirt2XLType]
327327
}).Entity;
328328

@@ -333,7 +333,7 @@ public static async Task SeedData(this IApplicationBuilder host) {
333333

334334
var fShirt3XLComb = context.Combos.Add(new() {
335335
Stock = 4,
336-
Product = jacketProd,
336+
Product = fShirtProd,
337337
Types = [fShirt3XLType]
338338
}).Entity;
339339

TSystems.LoveOTC/Migrations/20231223165449_Init.Designer.cs renamed to TSystems.LoveOTC/Migrations/20231223181315_Init.Designer.cs

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TSystems.LoveOTC/Migrations/20231223165449_Init.cs renamed to TSystems.LoveOTC/Migrations/20231223181315_Init.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Text.Json;
32
using Microsoft.EntityFrameworkCore.Migrations;
43

54
#nullable disable
@@ -67,7 +66,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
6766
ProductId = table.Column<long>(type: "bigint", nullable: false),
6867
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
6968
CategoryId = table.Column<long>(type: "bigint", nullable: true),
70-
Description = table.Column<JsonElement>(type: "jsonb", nullable: true),
69+
Description = table.Column<string>(type: "jsonb", nullable: true),
7170
IsArchived = table.Column<bool>(type: "boolean", nullable: true),
7271
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
7372
},

TSystems.LoveOTC/Migrations/ShopContextModelSnapshot.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// <auto-generated />
22
using System;
3-
using System.Text.Json;
43
using Microsoft.EntityFrameworkCore;
54
using Microsoft.EntityFrameworkCore.Infrastructure;
65
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -254,7 +253,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
254253
b.Property<long?>("CategoryId")
255254
.HasColumnType("bigint");
256255

257-
b.Property<JsonElement?>("Description")
256+
b.Property<string>("Description")
258257
.HasColumnType("jsonb");
259258

260259
b.Property<bool?>("IsArchived")

TSystems.LoveOTC/Models/Product.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace TSystems.LoveOTC.Models;
44

55
using System.ComponentModel.DataAnnotations;
6-
using System.Text.Json;
6+
using System.ComponentModel.DataAnnotations.Schema;
77
using Entities;
88
using Microsoft.EntityFrameworkCore;
99

1010
/**
1111
* <remarks>
1212
* @author Aloento
1313
* @since 0.1.0
14-
* @version 0.1.0
14+
* @version 0.1.1
1515
* </remarks>
1616
*/
1717
[Index(nameof(Name), IsUnique = true)]
@@ -27,7 +27,8 @@ public class Product : Concurrency, IArchive {
2727

2828
public virtual ICollection<Photo> Photos { get; init; }
2929

30-
public JsonElement? Description { get; set; }
30+
[Column(TypeName = "jsonb")]
31+
public string? Description { get; set; }
3132

3233
public bool? IsArchived { get; set; }
3334

TSystems.LoveOTC/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
app.UseMigrationsEndPoint();
6060

6161
#if false
62-
await app.SeedData();
62+
await TSystems.LoveOTC.Helpers.DataSeeder.SeedData(app);
6363
#endif
6464
}
6565

src/Components/Auth/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMount } from "ahooks";
33
import { WebStorageStateStore } from "oidc-client-ts";
44
import { ReactNode, useEffect } from "react";
55
import { AuthProvider, hasAuthParams, useAuth } from "react-oidc-context";
6+
import { Logger } from "~/Helpers/Logger";
67
import { useErrorToast } from "~/Helpers/useToast";
78
import { Common } from "~/ShopNet/Database";
89
import { useRouter } from "../Router";
@@ -39,6 +40,8 @@ export function OIDCProvider({ children }: { children: ReactNode }): ReactNode {
3940
);
4041
}
4142

43+
const log = new Logger("Auth");
44+
4245
/**
4346
* @author Aloento
4447
* @since 1.0.0
@@ -47,7 +50,7 @@ export function OIDCProvider({ children }: { children: ReactNode }): ReactNode {
4750
function AuthHandler() {
4851
const auth = Common.AuthSlot = useAuth();
4952
const { Paths, Rep } = useRouter();
50-
const { dispatch } = useErrorToast();
53+
const { dispatch } = useErrorToast(log);
5154

5255
useMount(() => {
5356
if (Paths.at(0) === "Logout") {

0 commit comments

Comments
 (0)