All API endpoints now use Arrays instead of Lists

This commit is contained in:
2025-06-25 18:38:37 -07:00
parent f151a48f0a
commit cf90241944
9 changed files with 34 additions and 33 deletions
@@ -29,8 +29,8 @@ namespace MistoxWebsite.Server.Controllers {
string OrderNumber = Guid.NewGuid().ToString().Substring(0,10); string OrderNumber = Guid.NewGuid().ToString().Substring(0,10);
Account? acc = await _databaseService.GetAccount(userID); Account? acc = await _databaseService.GetAccount(userID);
if (acc != null) { if (acc != null) {
List<Cart> cart = await _databaseService.GetCart(acc); Cart[] carts = await _databaseService.GetCart(acc);
(bool, string) PaymentResponse = await _paymentService.TryGetCheckoutToken(OrderNumber, acc, cart); (bool, string) PaymentResponse = await _paymentService.TryGetCheckoutToken(OrderNumber, acc, carts);
if (PaymentResponse.Item1) { if (PaymentResponse.Item1) {
// Returns client secret // Returns client secret
return PaymentResponse.Item2; return PaymentResponse.Item2;
@@ -7,7 +7,7 @@ namespace MistoxWebsite.Server.Controllers.Payment {
public static PaymentType _PaymentType; public static PaymentType _PaymentType;
public static string _EndpointSecret = ""; public static string _EndpointSecret = "";
public Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, List<Cart> cart); public Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, Cart[] cart);
public Task ValidatePurchase(string WebHookData, string Headers); public Task ValidatePurchase(string WebHookData, string Headers);
} }
@@ -12,7 +12,7 @@ namespace MistoxWebsite.Server.Controllers {
_databaseService = databaseService; _databaseService = databaseService;
} }
public async Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, List<Cart> cart) { public async Task<(bool, string)> TryGetCheckoutToken(string OrderNumber, Account user, Cart[] cart) {
try { try {
// build Recipt and calculate Tax // build Recipt and calculate Tax
var options = new Stripe.Tax.CalculationCreateOptions { var options = new Stripe.Tax.CalculationCreateOptions {
@@ -17,12 +17,11 @@ namespace MistoxWebsite.Server.Controllers {
[Route( "api/cart/get" )] [Route( "api/cart/get" )]
[HttpPost] [HttpPost]
public async Task<List<Cart>> GetCart( [FromBody] Account acc ) { public async Task<Cart[]> GetCart( [FromBody] Account acc ) {
try { try {
List<Cart> cart = await _databaseService.GetCart( acc ); return await _databaseService.GetCart( acc );
return cart;
} catch { } catch {
return new List<Cart>(); return new Cart[0];
} }
} }
@@ -98,17 +97,17 @@ namespace MistoxWebsite.Server.Controllers {
[Route( "api/product/getall" )] [Route( "api/product/getall" )]
[HttpPost] [HttpPost]
public ActionResult<List<Product>> GetAllProducts() { public ActionResult<Product[]> GetAllProducts() {
try { try {
return CatalogItems; return CatalogItems.ToArray();
} catch { } catch {
return new List<Product>(); return new Product[0];
} }
} }
[Route( "api/product/getowned" )] [Route( "api/product/getowned" )]
[HttpPost] [HttpPost]
public async Task<ActionResult<List<Receipt>>> GetOwnedProduct() { public async Task<ActionResult<Receipt[]>> GetOwnedProduct() {
try { try {
if( User.Identity != null && User.Identity.IsAuthenticated ) { if( User.Identity != null && User.Identity.IsAuthenticated ) {
string? email = User.FindFirstValue(ClaimTypes.Email); string? email = User.FindFirstValue(ClaimTypes.Email);
@@ -116,13 +115,13 @@ namespace MistoxWebsite.Server.Controllers {
Account? test = await _databaseService.GetAccount(email); Account? test = await _databaseService.GetAccount(email);
if( test != null ) { if( test != null ) {
List<Receipt> returned = await _databaseService.GetAllReceipts(test); List<Receipt> returned = await _databaseService.GetAllReceipts(test);
return returned; return returned.ToArray();
} }
} }
} }
return new List<Receipt>(); return new Receipt[0];
} catch { } catch {
return new List<Receipt>(); return new Receipt[0];
} }
} }
@@ -25,7 +25,7 @@ namespace MistoxWebsite.Server.Entities {
public string Name { get; set; } = ""; public string Name { get; set; } = "";
public string Description { get; set; } = ""; public string Description { get; set; } = "";
public int CurShowingIMG = 0; public int CurShowingIMG = 0;
public List<string> Images { get; set; } = new List<string>(); public string[] Images { get; set; } = new string[0];
public int Cost { get; set; } public int Cost { get; set; }
public string URL { get; set; } = ""; public string URL { get; set; } = "";
} }
@@ -3,9 +3,9 @@ namespace MistoxWebsite.Server.Entities {
public class PageLoadObject { public class PageLoadObject {
public Account? user { get; set; } public Account? user { get; set; }
public AccountClaims? claims { get; set; } public AccountClaims? claims { get; set; }
public List<Receipt>? receipts { get; set; } public Receipt[]? receipts { get; set; }
public List<Product>? products { get; set; } public Product[]? products { get; set; }
public List<Cart>? Cart { get; set; } public Cart[]? Cart { get; set; }
} }
public class AccountClaims { public class AccountClaims {
@@ -6,7 +6,7 @@ using System.Data.Common;
namespace MistoxWebsite.Server.Services.DatabaseService { namespace MistoxWebsite.Server.Services.DatabaseService {
public partial class DatabaseService { public partial class DatabaseService {
public async Task<List<Cart>> GetCart( Account account ) { public async Task<Cart[]> GetCart( Account account ) {
List<Cart> list = new List<Cart>(); List<Cart> list = new List<Cart>();
using( MySqlConnection connection = GetConnection() ) { using( MySqlConnection connection = GetConnection() ) {
connection.Open(); connection.Open();
@@ -34,7 +34,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
} }
} }
} }
return list; return list.ToArray();
} }
public async Task AddToCart( Cart item ) { public async Task AddToCart( Cart item ) {
@@ -62,8 +62,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
} }
} }
account.products = new List<Product>(); List<Product> tempProds = new List<Product>();
account.receipts = new List<Receipt>(); List<Receipt> tempReceipt = new List<Receipt>();
command = @" command = @"
SELECT * FROM Product SELECT * FROM Product
@@ -93,17 +93,17 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
string[] _imageList = _gameImg.Split('|', StringSplitOptions.RemoveEmptyEntries); string[] _imageList = _gameImg.Split('|', StringSplitOptions.RemoveEmptyEntries);
account.products.Add( new Product { tempProds.Add(new Product {
ID = _productID, ID = _productID,
Cost = _gameCost, Cost = _gameCost,
Description = _gameDesc, Description = _gameDesc,
Name = _gameName, Name = _gameName,
URL = _gameURL, URL = _gameURL,
Images = _imageList.ToList() Images = _imageList
}); });
if (_receiptAccountID != -1) { if (_receiptAccountID != -1) {
account.receipts.Add( new Receipt { tempReceipt.Add(new Receipt {
AccountID = _receiptAccountID, AccountID = _receiptAccountID,
ProductID = _productID, ProductID = _productID,
ReceiptID = _receiptID, ReceiptID = _receiptID,
@@ -111,6 +111,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
}); });
} }
account.products = tempProds.ToArray();
account.receipts = tempReceipt.ToArray();
} }
} }
} }
@@ -37,7 +37,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
Name = _name, Name = _name,
Description = _description, Description = _description,
Cost = _cost, Cost = _cost,
Images = _imageList.ToList(), Images = _imageList,
URL = _url URL = _url
}; };
} }
@@ -70,7 +70,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
Name = _name, Name = _name,
Description = _description, Description = _description,
Cost = _cost, Cost = _cost,
Images = _imageList.ToList(), Images = _imageList,
URL = _url URL = _url
} ); } );
} }