Removed Unneccesary Controllers
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BoredCareers.Entities;
|
||||
using BoredCareers.Services.DatabaseService;
|
||||
|
||||
namespace BoredCareers.Controllers {
|
||||
[ApiController]
|
||||
[Route("api/cart/[controller]")]
|
||||
public class CartController : MistoxControllerBase {
|
||||
|
||||
CartController(DatabaseService db) : base(db) { }
|
||||
|
||||
[Route("get")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Cart[]>> GetCart() {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
return Ok(await _databaseService.GetCart(getLoggedInUserID()));
|
||||
}
|
||||
return StatusCode(500);
|
||||
} catch {
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("add")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddCart([FromBody] Cart cart) {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
cart.AccountID = getLoggedInUserID();
|
||||
await _databaseService.AddToCart(cart);
|
||||
return Ok();
|
||||
}
|
||||
return StatusCode(500);
|
||||
} catch {
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("remove")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> RemoveCart([FromBody] Cart cart) {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
cart.AccountID = getLoggedInUserID();
|
||||
await _databaseService.RemoveFromCart(cart);
|
||||
return Ok();
|
||||
}
|
||||
return StatusCode(500);
|
||||
} catch {
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("clear")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ClearCart() {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
await _databaseService.ClearCart(getLoggedInUserID());
|
||||
return Ok();
|
||||
}
|
||||
return StatusCode(500);
|
||||
} catch {
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BoredCareers.Services.DatabaseService;
|
||||
using BoredCareers.Entities;
|
||||
|
||||
namespace BoredCareers.Controllers {
|
||||
[ApiController]
|
||||
[Route("api/product/[controller]")]
|
||||
public class ProductController : MistoxControllerBase {
|
||||
|
||||
public ProductController(DatabaseService db) : base(db) { }
|
||||
|
||||
[Route("set")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<bool>> CreateProduct([FromForm] Product obj, [FromForm] IFormFile[] images) {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
Account user = await getLoggedInUser();
|
||||
if (user.Role == "Admin") {
|
||||
List<ProductImage> building = new List<ProductImage>();
|
||||
foreach (var file in images) {
|
||||
using (var stream = new MemoryStream()) {
|
||||
await file.CopyToAsync(stream);
|
||||
var bytes = stream.ToArray();
|
||||
|
||||
// Convert to your image model or whatever your logic is
|
||||
ProductImage img = new ProductImage { Image = bytes, Name = file.FileName };
|
||||
building.Add(img);
|
||||
}
|
||||
}
|
||||
obj.Images = building.ToArray();
|
||||
await _databaseService.SetProduct(obj);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Route("get")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Product>> GetProduct([FromForm] int productID) {
|
||||
try {
|
||||
Product? product = await _databaseService.GetProduct(productID);
|
||||
if (product != null) {
|
||||
return product;
|
||||
}
|
||||
else {
|
||||
return NotFound();
|
||||
}
|
||||
} catch {
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[Route("getall")]
|
||||
[HttpPost]
|
||||
public async Task<Product[]> GetAllProducts() {
|
||||
try {
|
||||
return await _databaseService.GetAllProducts();
|
||||
} catch {
|
||||
return Array.Empty<Product>();
|
||||
}
|
||||
}
|
||||
|
||||
[Route("delete")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<bool>> DeleteProduct([FromForm] int productID) {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
Account user = await getLoggedInUser();
|
||||
if (user.Role == "Admin") {
|
||||
await _databaseService.DeleteProduct(productID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Route("getimage")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetProductImage([FromForm] int ProductID, [FromForm] int ImageID) {
|
||||
try {
|
||||
ProductImage? img = await _databaseService.GetImage(ProductID, ImageID);
|
||||
if (img != null) {
|
||||
return File(img.Image, "Image/*");
|
||||
}
|
||||
else {
|
||||
return NotFound();
|
||||
}
|
||||
} catch {
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[Route("getowned")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Receipt[]>> GetOwnedProduct() {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
Receipt[] returned = await _databaseService.GetAllReceipts(getLoggedInUserID());
|
||||
return returned;
|
||||
}
|
||||
return new Receipt[0];
|
||||
} catch {
|
||||
return new Receipt[0];
|
||||
}
|
||||
}
|
||||
|
||||
[Route("download")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> Download([FromQuery] string Product) {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
Product[] games = await _databaseService.GetAllProducts();
|
||||
foreach (Product product in games) {
|
||||
if (contains(Product, product.URL)) {
|
||||
Receipt? receipt = await _databaseService.GetReceipt(getLoggedInUserID(), product.ID);
|
||||
if (receipt != null) {
|
||||
//FileStream fileStream = new FileStream(_FolderRoot + Product, FileMode.Open, FileAccess.Read);
|
||||
//return new FileStreamResult( fileStream, "application/octet-stream" ) {
|
||||
// FileDownloadName = fileStream.Name
|
||||
//};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Unauthorized();
|
||||
}
|
||||
return Unauthorized();
|
||||
} catch {
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user