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);
Account? acc = await _databaseService.GetAccount(userID);
if (acc != null) {
List<Cart> cart = await _databaseService.GetCart(acc);
(bool, string) PaymentResponse = await _paymentService.TryGetCheckoutToken(OrderNumber, acc, cart);
Cart[] carts = await _databaseService.GetCart(acc);
(bool, string) PaymentResponse = await _paymentService.TryGetCheckoutToken(OrderNumber, acc, carts);
if (PaymentResponse.Item1) {
// Returns client secret
return PaymentResponse.Item2;
@@ -7,7 +7,7 @@ namespace MistoxWebsite.Server.Controllers.Payment {
public static PaymentType _PaymentType;
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);
}
@@ -12,7 +12,7 @@ namespace MistoxWebsite.Server.Controllers {
_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 {
// build Recipt and calculate Tax
var options = new Stripe.Tax.CalculationCreateOptions {
@@ -17,12 +17,11 @@ namespace MistoxWebsite.Server.Controllers {
[Route( "api/cart/get" )]
[HttpPost]
public async Task<List<Cart>> GetCart( [FromBody] Account acc ) {
public async Task<Cart[]> GetCart( [FromBody] Account acc ) {
try {
List<Cart> cart = await _databaseService.GetCart( acc );
return cart;
return await _databaseService.GetCart( acc );
} catch {
return new List<Cart>();
return new Cart[0];
}
}
@@ -98,17 +97,17 @@ namespace MistoxWebsite.Server.Controllers {
[Route( "api/product/getall" )]
[HttpPost]
public ActionResult<List<Product>> GetAllProducts() {
public ActionResult<Product[]> GetAllProducts() {
try {
return CatalogItems;
return CatalogItems.ToArray();
} catch {
return new List<Product>();
return new Product[0];
}
}
[Route( "api/product/getowned" )]
[HttpPost]
public async Task<ActionResult<List<Receipt>>> GetOwnedProduct() {
public async Task<ActionResult<Receipt[]>> GetOwnedProduct() {
try {
if( User.Identity != null && User.Identity.IsAuthenticated ) {
string? email = User.FindFirstValue(ClaimTypes.Email);
@@ -116,13 +115,13 @@ namespace MistoxWebsite.Server.Controllers {
Account? test = await _databaseService.GetAccount(email);
if( test != null ) {
List<Receipt> returned = await _databaseService.GetAllReceipts(test);
return returned;
return returned.ToArray();
}
}
}
return new List<Receipt>();
return new Receipt[0];
} catch {
return new List<Receipt>();
return new Receipt[0];
}
}
@@ -25,7 +25,7 @@ namespace MistoxWebsite.Server.Entities {
public string Name { get; set; } = "";
public string Description { get; set; } = "";
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 string URL { get; set; } = "";
}
@@ -3,9 +3,9 @@ namespace MistoxWebsite.Server.Entities {
public class PageLoadObject {
public Account? user { get; set; }
public AccountClaims? claims { get; set; }
public List<Receipt>? receipts { get; set; }
public List<Product>? products { get; set; }
public List<Cart>? Cart { get; set; }
public Receipt[]? receipts { get; set; }
public Product[]? products { get; set; }
public Cart[]? Cart { get; set; }
}
public class AccountClaims {
@@ -6,7 +6,7 @@ using System.Data.Common;
namespace MistoxWebsite.Server.Services.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>();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
@@ -34,7 +34,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
}
}
}
return list;
return list.ToArray();
}
public async Task AddToCart( Cart item ) {
@@ -62,8 +62,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
}
}
account.products = new List<Product>();
account.receipts = new List<Receipt>();
List<Product> tempProds = new List<Product>();
List<Receipt> tempReceipt = new List<Receipt>();
command = @"
SELECT * FROM Product
@@ -76,8 +76,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
cmd2.Parameters.AddWithValue("@AccountID", AccountID);
using( DbDataReader reader = await cmd2.ExecuteReaderAsync() ) {
while( await reader.ReadAsync() ) {
if( reader == null ) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
@@ -93,24 +93,26 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
string[] _imageList = _gameImg.Split('|', StringSplitOptions.RemoveEmptyEntries);
account.products.Add( new Product {
tempProds.Add(new Product {
ID = _productID,
Cost = _gameCost,
Description = _gameDesc,
Name = _gameName,
URL = _gameURL,
Images = _imageList.ToList()
} );
Images = _imageList
});
if( _receiptAccountID != -1 ) {
account.receipts.Add( new Receipt {
if (_receiptAccountID != -1) {
tempReceipt.Add(new Receipt {
AccountID = _receiptAccountID,
ProductID = _productID,
ReceiptID = _receiptID,
Time = _receiptTime
} );
});
}
account.products = tempProds.ToArray();
account.receipts = tempReceipt.ToArray();
}
}
}
@@ -37,7 +37,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
Name = _name,
Description = _description,
Cost = _cost,
Images = _imageList.ToList(),
Images = _imageList,
URL = _url
};
}
@@ -70,7 +70,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
Name = _name,
Description = _description,
Cost = _cost,
Images = _imageList.ToList(),
Images = _imageList,
URL = _url
} );
}