Major changes:
• Remove BTCPay Server integration in favor of SilverPAY manual verification
• Add test data cleanup mechanisms (API endpoints and shell scripts)
• Fix compilation errors in TestController (IdentityReference vs CustomerIdentity)
• Add deployment automation scripts for Hostinger VPS
• Enhance integration testing with comprehensive E2E validation
• Add Blazor components and mobile-responsive CSS for admin interface
• Create production environment configuration scripts
Key Features Added:
• Manual payment verification through Admin panel Order Details
• Bulk test data cleanup with proper cascade handling
• Deployment automation with systemd service configuration
• Comprehensive E2E testing suite with SilverPAY integration validation
• Mobile-first admin interface improvements
Security & Production:
• Environment variable configuration for production secrets
• Proper JWT and VAPID key management
• SilverPAY API integration with live credentials
• Database cleanup and maintenance tools
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
254 lines
8.9 KiB
C#
254 lines
8.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using LittleShop.Services;
|
|
using LittleShop.DTOs;
|
|
using LittleShop.Data;
|
|
|
|
namespace LittleShop.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class TestController : ControllerBase
|
|
{
|
|
private readonly ICategoryService _categoryService;
|
|
private readonly IProductService _productService;
|
|
private readonly LittleShopContext _context;
|
|
|
|
public TestController(ICategoryService categoryService, IProductService productService, LittleShopContext context)
|
|
{
|
|
_categoryService = categoryService;
|
|
_productService = productService;
|
|
_context = context;
|
|
}
|
|
|
|
[HttpPost("create-product")]
|
|
public async Task<IActionResult> CreateTestProduct()
|
|
{
|
|
try
|
|
{
|
|
// Get the first category
|
|
var categories = await _categoryService.GetAllCategoriesAsync();
|
|
var firstCategory = categories.FirstOrDefault();
|
|
|
|
if (firstCategory == null)
|
|
{
|
|
return BadRequest("No categories found. Create a category first.");
|
|
}
|
|
|
|
var product = await _productService.CreateProductAsync(new CreateProductDto
|
|
{
|
|
Name = "Test Product via API",
|
|
Description = "This product was created via the test API endpoint 🚀",
|
|
Price = 49.99m,
|
|
Weight = 0.5m,
|
|
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
|
|
CategoryId = firstCategory.Id
|
|
});
|
|
|
|
return Ok(new {
|
|
message = "Product created successfully",
|
|
product = product
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("setup-test-data")]
|
|
public async Task<IActionResult> SetupTestData()
|
|
{
|
|
try
|
|
{
|
|
// Create test category
|
|
var category = await _categoryService.CreateCategoryAsync(new CreateCategoryDto
|
|
{
|
|
Name = "Electronics",
|
|
Description = "Electronic devices and gadgets"
|
|
});
|
|
|
|
// Create test product
|
|
var product = await _productService.CreateProductAsync(new CreateProductDto
|
|
{
|
|
Name = "Sample Product",
|
|
Description = "This is a test product with emoji support 📱💻",
|
|
Price = 99.99m,
|
|
Weight = 1.5m,
|
|
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
|
|
CategoryId = category.Id
|
|
});
|
|
|
|
return Ok(new {
|
|
message = "Test data created successfully",
|
|
category = category,
|
|
product = product
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("cleanup-bots")]
|
|
public async Task<IActionResult> CleanupBots()
|
|
{
|
|
try
|
|
{
|
|
// Get count before cleanup
|
|
var totalBots = await _context.Bots.CountAsync();
|
|
|
|
// Keep only the most recent active bot per platform
|
|
var keepBots = await _context.Bots
|
|
.Where(b => b.IsActive && b.Status == Enums.BotStatus.Active)
|
|
.GroupBy(b => b.PlatformId)
|
|
.Select(g => g.OrderByDescending(b => b.LastSeenAt ?? b.CreatedAt).First())
|
|
.ToListAsync();
|
|
|
|
var keepBotIds = keepBots.Select(b => b.Id).ToList();
|
|
|
|
// Delete old/inactive bots and related data
|
|
var botsToDelete = await _context.Bots
|
|
.Where(b => !keepBotIds.Contains(b.Id))
|
|
.ToListAsync();
|
|
|
|
_context.Bots.RemoveRange(botsToDelete);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var deletedCount = botsToDelete.Count;
|
|
var remainingCount = keepBots.Count;
|
|
|
|
return Ok(new {
|
|
message = "Bot cleanup completed",
|
|
totalBots = totalBots,
|
|
deletedBots = deletedCount,
|
|
remainingBots = remainingCount,
|
|
keptBots = keepBots.Select(b => new {
|
|
id = b.Id,
|
|
name = b.Name,
|
|
platformUsername = b.PlatformUsername,
|
|
lastSeen = b.LastSeenAt,
|
|
created = b.CreatedAt
|
|
})
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("cleanup-test-data")]
|
|
public async Task<IActionResult> CleanupTestData()
|
|
{
|
|
try
|
|
{
|
|
// Get counts before cleanup
|
|
var totalOrders = await _context.Orders.CountAsync();
|
|
var totalCryptoPayments = await _context.CryptoPayments.CountAsync();
|
|
var totalOrderItems = await _context.OrderItems.CountAsync();
|
|
|
|
// Find test orders (identity references starting with "test-")
|
|
var testOrders = await _context.Orders
|
|
.Where(o => o.IdentityReference != null && o.IdentityReference.StartsWith("test-"))
|
|
.ToListAsync();
|
|
|
|
var testOrderIds = testOrders.Select(o => o.Id).ToList();
|
|
|
|
// Remove crypto payments for test orders
|
|
var cryptoPaymentsToDelete = await _context.CryptoPayments
|
|
.Where(cp => testOrderIds.Contains(cp.OrderId))
|
|
.ToListAsync();
|
|
|
|
// Remove order items for test orders
|
|
var orderItemsToDelete = await _context.OrderItems
|
|
.Where(oi => testOrderIds.Contains(oi.OrderId))
|
|
.ToListAsync();
|
|
|
|
// Delete all related data
|
|
_context.CryptoPayments.RemoveRange(cryptoPaymentsToDelete);
|
|
_context.OrderItems.RemoveRange(orderItemsToDelete);
|
|
_context.Orders.RemoveRange(testOrders);
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
// Get counts after cleanup
|
|
var remainingOrders = await _context.Orders.CountAsync();
|
|
var remainingCryptoPayments = await _context.CryptoPayments.CountAsync();
|
|
var remainingOrderItems = await _context.OrderItems.CountAsync();
|
|
|
|
return Ok(new {
|
|
message = "Test data cleanup completed",
|
|
before = new {
|
|
orders = totalOrders,
|
|
cryptoPayments = totalCryptoPayments,
|
|
orderItems = totalOrderItems
|
|
},
|
|
after = new {
|
|
orders = remainingOrders,
|
|
cryptoPayments = remainingCryptoPayments,
|
|
orderItems = remainingOrderItems
|
|
},
|
|
deleted = new {
|
|
orders = testOrders.Count,
|
|
cryptoPayments = cryptoPaymentsToDelete.Count,
|
|
orderItems = orderItemsToDelete.Count
|
|
},
|
|
testOrdersFound = testOrders.Select(o => new {
|
|
id = o.Id,
|
|
identityReference = o.IdentityReference,
|
|
createdAt = o.CreatedAt,
|
|
total = o.Total
|
|
})
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpGet("database")]
|
|
public async Task<IActionResult> DatabaseHealthCheck()
|
|
{
|
|
try
|
|
{
|
|
// Test database connectivity by executing a simple query
|
|
var canConnect = await _context.Database.CanConnectAsync();
|
|
|
|
if (!canConnect)
|
|
{
|
|
return StatusCode(503, new {
|
|
status = "unhealthy",
|
|
message = "Cannot connect to database",
|
|
timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
|
|
// Test actual query execution
|
|
var categoryCount = await _context.Categories.CountAsync();
|
|
var productCount = await _context.Products.CountAsync();
|
|
var orderCount = await _context.Orders.CountAsync();
|
|
|
|
return Ok(new {
|
|
status = "healthy",
|
|
message = "Database connection successful",
|
|
stats = new {
|
|
categories = categoryCount,
|
|
products = productCount,
|
|
orders = orderCount
|
|
},
|
|
timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(503, new {
|
|
status = "unhealthy",
|
|
error = ex.Message,
|
|
timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
}
|
|
} |