初始化
Some checks failed
Some checks failed
This commit is contained in:
@@ -68,87 +68,32 @@ public class TestController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("categories")]
|
||||
public async Task<IActionResult> GetCategories()
|
||||
{
|
||||
try
|
||||
public async Task<IActionResult> GetCategories()
|
||||
{
|
||||
var categories = new List<object>();
|
||||
|
||||
using var connection = new MySql.Data.MySqlClient.MySqlConnection(
|
||||
"Server=localhost;Database=HardwarePerformance;User=root;Password=123456;");
|
||||
await connection.OpenAsync();
|
||||
|
||||
using var cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM Categories", connection);
|
||||
using var reader = await cmd.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
try
|
||||
{
|
||||
categories.Add(new
|
||||
{
|
||||
Id = reader.GetInt32("Id"),
|
||||
Name = reader.GetString("Name"),
|
||||
Description = reader.IsDBNull("Description") ? null : reader.GetString("Description"),
|
||||
CreatedAt = reader.GetDateTime("CreatedAt")
|
||||
});
|
||||
var categories = await _context.GetCategoriesAsync();
|
||||
return Ok(new { success = true, data = categories });
|
||||
}
|
||||
|
||||
return Ok(categories);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取类别列表时发生错误");
|
||||
return StatusCode(500, new
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"获取类别列表时发生错误: {ex.Message}",
|
||||
Timestamp = DateTime.Now
|
||||
});
|
||||
_logger.LogError(ex, "获取类别列表时发生错误");
|
||||
return StatusCode(500, new { success = false, message = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("products")]
|
||||
public async Task<IActionResult> GetProducts()
|
||||
{
|
||||
try
|
||||
public async Task<IActionResult> GetProducts([FromQuery] int categoryId = 0, [FromQuery] int page = 1, [FromQuery] int pageSize = 10)
|
||||
{
|
||||
var products = new List<object>();
|
||||
|
||||
using var connection = new MySql.Data.MySqlClient.MySqlConnection(
|
||||
"Server=localhost;Database=HardwarePerformance;User=root;Password=123456;");
|
||||
await connection.OpenAsync();
|
||||
|
||||
using var cmd = new MySql.Data.MySqlClient.MySqlCommand(
|
||||
@"SELECT p.*, c.Name as CategoryName
|
||||
FROM Products p
|
||||
LEFT JOIN Categories c ON p.CategoryId = c.Id", connection);
|
||||
using var reader = await cmd.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
try
|
||||
{
|
||||
products.Add(new
|
||||
{
|
||||
Id = reader.GetInt32("Id"),
|
||||
Name = reader.GetString("Name"),
|
||||
Model = reader.IsDBNull("Model") ? null : reader.GetString("Model"),
|
||||
Manufacturer = reader.IsDBNull("Manufacturer") ? null : reader.GetString("Manufacturer"),
|
||||
ImageUrl = reader.IsDBNull("ImageUrl") ? null : reader.GetString("ImageUrl"),
|
||||
ReleaseDate = reader.IsDBNull("ReleaseDate") ? (DateTime?)null : reader.GetDateTime("ReleaseDate"),
|
||||
CategoryId = reader.IsDBNull("CategoryId") ? (int?)null : reader.GetInt32("CategoryId"),
|
||||
CategoryName = reader.IsDBNull("CategoryName") ? null : reader.GetString("CategoryName"),
|
||||
CurrentRank = reader.IsDBNull("CurrentRank") ? (int?)null : reader.GetInt32("CurrentRank"),
|
||||
CreatedAt = reader.GetDateTime("CreatedAt")
|
||||
});
|
||||
var products = await _context.GetProductsAsync(categoryId, page, pageSize);
|
||||
return Ok(new { success = true, data = products });
|
||||
}
|
||||
|
||||
return Ok(products);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取产品列表时发生错误");
|
||||
return StatusCode(500, new
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"获取产品列表时发生错误: {ex.Message}",
|
||||
Timestamp = DateTime.Now
|
||||
});
|
||||
_logger.LogError(ex, "获取产品列表时发生错误");
|
||||
return StatusCode(500, new { success = false, message = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.7.10" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.7.27" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.ResponseCompression;
|
||||
using StackExchange.Redis;
|
||||
using HardwarePerformance.Infrastructure.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net9.0",
|
||||
"frameworks": [
|
||||
{
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "9.0.0"
|
||||
},
|
||||
{
|
||||
"name": "Microsoft.AspNetCore.App",
|
||||
"version": "9.0.0"
|
||||
}
|
||||
],
|
||||
"configProperties": {
|
||||
"System.GC.Server": true,
|
||||
"System.Reflection.NullabilityInfoContext.IsSupported": true,
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"Version":1,"ManifestType":"Build","Endpoints":[]}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/Humanizer.dll
Normal file
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/Humanizer.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/MySql.Data.dll
Normal file
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/MySql.Data.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/ZstdSharp.dll
Normal file
BIN
backend/HardwarePerformance.API/bin/Debug/net9.0/ZstdSharp.dll
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=localhost;Database=HardwarePerformance;User=root;Password=123456;",
|
||||
"Redis": "localhost:6379"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user