test user name
This commit is contained in:
@@ -152,13 +152,13 @@ using (var scope = app.Services.CreateScope())
|
||||
}
|
||||
|
||||
// Erstelle einen initialen Admin-Benutzer
|
||||
var adminUser = await userManager.FindByEmailAsync("user@example.com"); // << ANPASSEN >>
|
||||
var adminUser = await userManager.FindByEmailAsync("admin-user@example.com"); // << ANPASSEN >>
|
||||
if (adminUser == null)
|
||||
{
|
||||
adminUser = new IdentityUser
|
||||
{
|
||||
UserName = "user@example.com", // << ANPASSEN >>
|
||||
Email = "user@example.com", // << ANPASSEN >>
|
||||
UserName = "admin-user@example.com", // << ANPASSEN >>
|
||||
Email = "admin-user@example.com", // << ANPASSEN >>
|
||||
EmailConfirmed = true
|
||||
};
|
||||
var createAdmin = await userManager.CreateAsync(adminUser, "string"); // << ANPASSEN >>
|
||||
|
||||
96
Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs
Normal file
96
Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
// src/Webshop.Api/SwaggerFilters/AddExampleSchemaFilter.cs
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Microsoft.OpenApi.Any; // Wichtig für OpenApiString, OpenApiDouble etc.
|
||||
using Webshop.Application.DTOs; // Ihre DTOs
|
||||
using Webshop.Application.DTOs.Auth;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
|
||||
namespace Webshop.Api.SwaggerFilters
|
||||
{
|
||||
public class AddExampleSchemaFilter : ISchemaFilter
|
||||
{
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
{
|
||||
// Überprüfe den Typ des DTOs und setze ein Beispiel
|
||||
if (context.Type == typeof(AdminProductDto))
|
||||
{
|
||||
// Beispiel für AdminProductDto (beachten Sie die realistischen Werte)
|
||||
schema.Example = new OpenApiObject
|
||||
{
|
||||
// Bei POST-Requests wird die ID von der API generiert, daher hier eine Null-GUID oder weglassen.
|
||||
["id"] = new OpenApiString(Guid.Empty.ToString()),
|
||||
["name"] = new OpenApiString("Admin Testprodukt XYZ"),
|
||||
["description"] = new OpenApiString("Vollständige Beschreibung des Admin Testprodukts mit allen Details."),
|
||||
["sku"] = new OpenApiString("ADM-XYZ-001"), // Muss einzigartig sein!
|
||||
["price"] = new OpenApiDouble(199.99),
|
||||
["oldPrice"] = new OpenApiNull(),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["isInStock"] = new OpenApiBoolean(true),
|
||||
["stockQuantity"] = new OpenApiInteger(50),
|
||||
["weight"] = new OpenApiDouble(2.5),
|
||||
["imageUrl"] = new OpenApiString("https://example.com/images/admin_test_xyz.jpg"),
|
||||
["slug"] = new OpenApiString("admin-testprodukt-xyz"), // Muss einzigartig sein!
|
||||
["createdDate"] = new OpenApiString(DateTimeOffset.UtcNow.ToString("o")),
|
||||
["lastModifiedDate"] = new OpenApiNull(),
|
||||
// Wichtig: supplierId auf null setzen, wenn noch keine Lieferanten in DB sind.
|
||||
// Ansonsten eine echte, existierende Lieferanten-ID hier eintragen.
|
||||
["supplierId"] = new OpenApiNull(), // Oder new OpenApiString("HIER-EINE-ECHTE-SUPPLIER-ID-EINFUEGEN")
|
||||
["purchasePrice"] = new OpenApiDouble(120.00)
|
||||
};
|
||||
}
|
||||
else if (context.Type == typeof(ProductDto))
|
||||
{
|
||||
// Beispiel für Public ProductDto
|
||||
schema.Example = new OpenApiObject
|
||||
{
|
||||
["id"] = new OpenApiString(Guid.Empty.ToString()),
|
||||
["name"] = new OpenApiString("Öffentliches Beispielprodukt"),
|
||||
["description"] = new OpenApiString("Eine kurze Beschreibung des Produkts für den Webshop."),
|
||||
["sku"] = new OpenApiString("PUB-ABC-001"),
|
||||
["price"] = new OpenApiDouble(49.99),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["isInStock"] = new OpenApiBoolean(true),
|
||||
["stockQuantity"] = new OpenApiInteger(100),
|
||||
["imageUrl"] = new OpenApiString("https://example.com/images/public_abc.jpg")
|
||||
};
|
||||
}
|
||||
else if (context.Type == typeof(SupplierDto))
|
||||
{
|
||||
// Beispiel für SupplierDto
|
||||
schema.Example = new OpenApiObject
|
||||
{
|
||||
["id"] = new OpenApiString(Guid.Empty.ToString()),
|
||||
["name"] = new OpenApiString("Lieferant A GmbH"),
|
||||
["contactPerson"] = new OpenApiString("Max Mustermann"),
|
||||
["email"] = new OpenApiString("kontakt@lieferant-a.com"),
|
||||
["phoneNumber"] = new OpenApiString("+49170123456"),
|
||||
["addressId"] = new OpenApiNull(),
|
||||
["notes"] = new OpenApiString("Hauptlieferant für Hardware.")
|
||||
};
|
||||
}
|
||||
else if (context.Type == typeof(LoginRequestDto))
|
||||
{
|
||||
// Beispiel für LoginRequestDto
|
||||
schema.Example = new OpenApiObject
|
||||
{
|
||||
["email"] = new OpenApiString("admin@yourwebshop.com"), // Oder customer@yourwebshop.com
|
||||
["password"] = new OpenApiString("SecureAdminPass123!") // Oder SecureCustomerPass123!
|
||||
};
|
||||
}
|
||||
else if (context.Type == typeof(RegisterRequestDto))
|
||||
{
|
||||
// Beispiel für RegisterRequestDto
|
||||
schema.Example = new OpenApiObject
|
||||
{
|
||||
["email"] = new OpenApiString("neuer.kunde@example.com"),
|
||||
["password"] = new OpenApiString("NeuesPasswort123!"),
|
||||
["confirmPassword"] = new OpenApiString("NeuesPasswort123!"),
|
||||
["firstName"] = new OpenApiString("Erika"),
|
||||
["lastName"] = new OpenApiString("Musterfrau")
|
||||
};
|
||||
}
|
||||
// Fügen Sie hier weitere else if Blöcke für andere DTOs hinzu, die Beispielwerte benötigen
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user