mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-03-14 10:04:55 +00:00
fix: removed old shit
This commit is contained in:
parent
b3fb3dbfe9
commit
1dc7ecdc8f
@ -46,7 +46,5 @@ public class ApplicationDbContext:DbContext
|
||||
public DbSet<SellerProfileRequest> SellerProfileRequests { get; set; }= null!;
|
||||
public DbSet<SellerProfilePortfolioPiece> SellerProfilePortfolioPieces { get; set; }= null!;
|
||||
public DbSet<SellerService> SellerServices { get; set; }= null!;
|
||||
public DbSet<SellerServiceOrder> SellerServiceOrders { get; set; } = null!;
|
||||
public DbSet<SellerServiceOrderReview> SellerServiceOrderReviews { get; set; }= null!;
|
||||
#endregion
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.database;
|
||||
using comissions.app.database.Entities;
|
||||
using comissions.app.database.Enums;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace comissions.app.api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize("admin")]
|
||||
[Route("api/admin/[controller]")]
|
||||
public class AdminOrdersController:ControllerBase
|
||||
{
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
|
||||
public AdminOrdersController(ApplicationDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetOrders(string search="", int offset = 0, int pageSize = 10)
|
||||
{
|
||||
var orders = _dbContext.SellerServiceOrders.Include(x=>x.Seller).ThenInclude(x=>x.User).Include(x=>x.Buyer)
|
||||
.Where(x=>x.Seller.User.DisplayName.Contains(search)
|
||||
|| x.Seller.User.Email.Contains(search)
|
||||
|| x.Buyer.DisplayName.Contains(search)
|
||||
|| x.Buyer.Email.Contains(search))
|
||||
.Skip(offset).Take(pageSize).ToList();
|
||||
return Ok(orders);
|
||||
}
|
||||
|
||||
[HttpGet("Count")]
|
||||
public async Task<IActionResult> GetOrdersCount(string search="")
|
||||
{
|
||||
var result = _dbContext.SellerServiceOrders.Include(x=>x.Seller).ThenInclude(x=>x.User).Include(x=>x.Buyer)
|
||||
.Where(x=>x.Seller.User.DisplayName.Contains(search)
|
||||
|| x.Seller.User.Email.Contains(search)
|
||||
|| x.Buyer.DisplayName.Contains(search)
|
||||
|| x.Buyer.Email.Contains(search))
|
||||
.Count();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("{orderId:int}")]
|
||||
public async Task<IActionResult> GetOrder(int orderId)
|
||||
{
|
||||
var order = await _dbContext.SellerServiceOrders.Include(x=>x.Seller).ThenInclude(x=>x.User).Include(x=>x.Buyer)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId);
|
||||
|
||||
if (order == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(order);
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{orderId:int}/Terminate")]
|
||||
public async Task<IActionResult> TerminateOrder(int orderId)
|
||||
{
|
||||
var order = await _dbContext.SellerServiceOrders.Include(x=>x.Seller).ThenInclude(x=>x.User).Include(x=>x.Buyer)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId);
|
||||
|
||||
if (order == null)
|
||||
return NotFound("Order not found.");
|
||||
|
||||
order.Status = EnumOrderStatus.Declined;
|
||||
_dbContext.SellerServiceOrders.Update(order);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return Ok(order);
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using comissions.app.api.Models.SellerProfileRequest;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Services.Payment;
|
||||
using comissions.app.database;
|
||||
using comissions.app.database.Entities;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using ArtPlatform.Database;
|
||||
using comissions.app.database;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@ -50,18 +49,6 @@ public class AdminSellersController:ControllerBase
|
||||
return Ok(seller);
|
||||
}
|
||||
|
||||
[HttpGet("{sellerId:int}/Orders")]
|
||||
public async Task<IActionResult> GetSellerOrders(int sellerId)
|
||||
{
|
||||
var seller = _dbContext.UserSellerProfiles.Include(x=>x.User)
|
||||
.FirstOrDefault(x=>x.Id==sellerId);
|
||||
|
||||
if (seller == null)
|
||||
return NotFound();
|
||||
|
||||
var orders = await _dbContext.SellerServiceOrders.Where(x=>x.SellerId==sellerId).ToListAsync();
|
||||
return Ok(orders);
|
||||
}
|
||||
|
||||
[HttpPut("{sellerId:int}/Suspend")]
|
||||
public async Task<IActionResult> SuspendSeller(int sellerId, [FromQuery]string reason, [FromQuery]int days)
|
||||
|
@ -1,5 +1,4 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using ArtPlatform.Database;
|
||||
using comissions.app.database;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -48,16 +47,6 @@ public class AdminUsersController:ControllerBase
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("{userId}/Orders")]
|
||||
public async Task<IActionResult> GetUserOrders(string userId)
|
||||
{
|
||||
var user = await _dbContext.Users.Include(x=>x.Orders).FirstOrDefaultAsync(x=>x.Id==userId);
|
||||
|
||||
if (user == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(user.Orders);
|
||||
}
|
||||
|
||||
[HttpPut("{userId}/Suspend")]
|
||||
public async Task<IActionResult> SuspendUser(string userId, [FromQuery]string reason, [FromQuery]int days)
|
||||
|
@ -1,6 +1,5 @@
|
||||
using comissions.app.api.Models.SellerProfile;
|
||||
using comissions.app.api.Models.SellerService;
|
||||
using ArtPlatform.Database;
|
||||
using comissions.app.api.Models.Discovery;
|
||||
using comissions.app.api.Models.PortfolioModel;
|
||||
using comissions.app.api.Services.Storage;
|
||||
@ -41,8 +40,7 @@ public class DiscoveryController : Controller
|
||||
public async Task<IActionResult> GetSeller(int sellerId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.SellerServices).ThenInclude(x=>x.Reviews)
|
||||
.Include(x=>x.User)
|
||||
.Include(x=>x.SellerServices)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
@ -113,42 +111,6 @@ public class DiscoveryController : Controller
|
||||
return new FileStreamResult(content, "application/octet-stream");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Reviews")]
|
||||
public async Task<IActionResult> GetSellerReviews(int sellerId, int offset = 0, int pageSize = 10)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerReviews = await _dbContext.SellerServiceOrderReviews
|
||||
.Where(x=>x.SellerService.SellerProfileId==sellerId)
|
||||
.Skip(offset).Take(pageSize).ToListAsync();
|
||||
var result = sellerReviews.Select(x=> new DiscoveryReviewModel()
|
||||
{
|
||||
Rating = x.Rating,
|
||||
WriterDisplayName = x.Reviewer.DisplayName,
|
||||
WriterId = x.ReviewerId,
|
||||
}).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Reviews/Count")]
|
||||
public async Task<IActionResult> GetSellerReviewsCount(int sellerId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerReviews = await _dbContext.SellerServiceOrderReviews
|
||||
.Where(x=>x.SellerService.SellerProfileId==sellerId)
|
||||
.CountAsync();
|
||||
return Ok(sellerReviews);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/Count")]
|
||||
public async Task<IActionResult> GetSellersCount(string search="")
|
||||
@ -159,156 +121,4 @@ public class DiscoveryController : Controller
|
||||
.CountAsync();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services")]
|
||||
public async Task<IActionResult> GetSellerServices(int sellerId, int offset = 0, int pageSize = 10)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerServices = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews)
|
||||
.Where(x=>x.SellerProfileId==sellerId && !x.Archived)
|
||||
.Skip(offset).Take(pageSize).ToListAsync();
|
||||
var result = sellerServices.Select(x=>x.ToModel()).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}")]
|
||||
public async Task<IActionResult> GetSellerService(int sellerId, int serviceId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var result = sellerService.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/Count")]
|
||||
public async Task<IActionResult> GetSellerServicesCount(int sellerId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerServices = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews)
|
||||
.Where(x=>x.SellerProfileId==sellerId && !x.Archived)
|
||||
.ToListAsync();
|
||||
var result = sellerServices.Count;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}/Portfolio")]
|
||||
public async Task<IActionResult> GetSellerServicePortfolio(int sellerId, int serviceId, int offset = 0, int pageSize = 10)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.PortfolioPieces)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var result = sellerService.PortfolioPieces.Select(x=>x.ToModel()).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}/Portfolio/Count")]
|
||||
public async Task<IActionResult> GetSellerServicePortfolioCount(int sellerId, int serviceId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.PortfolioPieces)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var result = sellerService.PortfolioPieces.Count;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}/Portfolio/{portfolioId:int}")]
|
||||
public async Task<IActionResult> GetSellerServicePortfolioPiece(int sellerId, int serviceId, int portfolioId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.PortfolioPieces)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var sellerPortfolio = await _dbContext.SellerProfilePortfolioPieces
|
||||
.FirstOrDefaultAsync(x=>x.Id==portfolioId);
|
||||
if(sellerPortfolio==null)
|
||||
return NotFound("Portfolio piece not found.");
|
||||
|
||||
var content = await _storageService.DownloadImageAsync(sellerPortfolio.FileReference);
|
||||
return new FileStreamResult(content, "application/octet-stream");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}/Reviews")]
|
||||
public async Task<IActionResult> GetSellerServiceReviews(int sellerId, int serviceId, int offset = 0, int pageSize = 10)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews).ThenInclude(x=>x.Reviewer)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var result = sellerService.Reviews.Select(x=> new DiscoveryReviewModel()
|
||||
{
|
||||
Rating = x.Rating,
|
||||
WriterDisplayName = x.Reviewer.DisplayName,
|
||||
WriterId = x.ReviewerId,
|
||||
}).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Sellers/{sellerId:int}/Services/{serviceId:int}/Reviews/Count")]
|
||||
public async Task<IActionResult> GetSellerServiceReviewsCount(int sellerId, int serviceId)
|
||||
{
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
var sellerService = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews).ThenInclude(x=>x.Reviewer)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(sellerService==null)
|
||||
return NotFound();
|
||||
var result = sellerService.Reviews.Count;
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Models.Order;
|
||||
using comissions.app.api.Services.Payment;
|
||||
using comissions.app.api.Services.Storage;
|
||||
using comissions.app.database;
|
||||
using comissions.app.database.Entities;
|
||||
using comissions.app.database.Enums;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Stripe;
|
||||
using Stripe.Checkout;
|
||||
|
||||
namespace comissions.app.api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class OrderController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly string _webHookSecret;
|
||||
|
||||
public OrderController(ApplicationDbContext dbContext, IConfiguration configuration, IStorageService storageService, IPaymentService paymentService)
|
||||
{
|
||||
_paymentService = paymentService;
|
||||
_storageService = storageService;
|
||||
_dbContext = dbContext;
|
||||
_webHookSecret = configuration.GetValue<string>("Stripe:WebHookSecret");
|
||||
}
|
||||
|
||||
[HttpPost("PaymentWebhook")]
|
||||
public async Task<IActionResult> ProcessWebhookEvent()
|
||||
{
|
||||
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
|
||||
|
||||
// If you are testing your webhook locally with the Stripe CLI you
|
||||
// can find the endpoint's secret by running `stripe listen`
|
||||
// Otherwise, find your endpoint's secret in your webhook settings
|
||||
// in the Developer Dashboard
|
||||
var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], _webHookSecret);
|
||||
|
||||
if (stripeEvent.Type == Events.CheckoutSessionExpired)
|
||||
{
|
||||
var session = stripeEvent.Data.Object as Session;
|
||||
var connectedAccountId = stripeEvent.Account;
|
||||
var orderId = session.LineItems.First().Price.Product.Name;
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.Seller)
|
||||
.Include(x=>x.Buyer)
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==int.Parse(orderId));
|
||||
if (order != null && order.Status == EnumOrderStatus.WaitingForPayment)
|
||||
{
|
||||
order.PaymentUrl = null;
|
||||
}
|
||||
}
|
||||
else if (stripeEvent.Type == Events.CheckoutSessionCompleted)
|
||||
{
|
||||
var session = stripeEvent.Data.Object as Session;
|
||||
var connectedAccountId = stripeEvent.Account;
|
||||
var orderId = session.Metadata["/OrderId"];
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.Seller)
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==int.Parse(orderId));
|
||||
if (order != null && order.Seller.StripeAccountId==connectedAccountId && order.Status == EnumOrderStatus.WaitingForPayment)
|
||||
{
|
||||
order.Status = EnumOrderStatus.InProgress;
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("/api/Orders")]
|
||||
[Authorize("read:orders")]
|
||||
public async Task<IActionResult> GetOrders(int offset = 0, int pageSize = 10, EnumOrderStatus? status = null)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var orders = await _dbContext.SellerServiceOrders
|
||||
.Where(x => x.BuyerId == userId && status==null ? true : status==x.Status)
|
||||
.Skip(offset).Take(pageSize).ToListAsync();
|
||||
var result = orders.Select(x => x.ToModel()).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("/api/Orders/{orderId:int}")]
|
||||
[Authorize("read:orders")]
|
||||
public async Task<IActionResult> GetOrder(int orderId,int offset = 0, int pageSize = 10, EnumOrderStatus? status = null)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.FirstAsync(x => x.Id==orderId && x.BuyerId == userId && status == null ? true : status == x.Status);
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("/api/Sellers/{sellerId:int}/Services/{serviceId:int}")]
|
||||
[Authorize("write:orders")]
|
||||
public async Task<IActionResult> CreateOrder(int sellerId, int serviceId, double amount)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var seller = await _dbContext.UserSellerProfiles
|
||||
.Include(x=>x.User)
|
||||
.FirstOrDefaultAsync(x=>x.Id==sellerId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
if(seller.Suspended)
|
||||
return NotFound();
|
||||
|
||||
var service = await _dbContext.SellerServices
|
||||
.Include(x=>x.Reviews)
|
||||
.FirstOrDefaultAsync(x=>x.Id==serviceId);
|
||||
if(service==null)
|
||||
return NotFound();
|
||||
|
||||
if(service.Archived)
|
||||
return BadRequest();
|
||||
|
||||
if(_dbContext.SellerServiceOrders.Where(x=>x.BuyerId==userId && x.Status!=EnumOrderStatus.Completed && x.Status!=EnumOrderStatus.Declined).Count()>=3)
|
||||
return BadRequest();
|
||||
|
||||
var order = new SellerServiceOrder()
|
||||
{
|
||||
BuyerId = userId,
|
||||
SellerId = seller.Id,
|
||||
SellerServiceId = serviceId,
|
||||
Status = EnumOrderStatus.PendingAcceptance,
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
Price = amount,
|
||||
SellerService = service,
|
||||
Buyer = await _dbContext.Users.FirstOrDefaultAsync(x=>x.Id==userId),
|
||||
};
|
||||
order = _dbContext.SellerServiceOrders.Add(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize("write:orders")]
|
||||
[Route("/api/Orders/{orderId:int}")]
|
||||
public async Task<IActionResult> CancelOrder(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId && x.BuyerId==userId);
|
||||
if(order==null)
|
||||
return NotFound();
|
||||
if(order.BuyerId!=userId)
|
||||
return BadRequest();
|
||||
if(order.Status==EnumOrderStatus.Completed)
|
||||
return BadRequest();
|
||||
order.Status = EnumOrderStatus.Declined;
|
||||
order.EndDate = DateTime.UtcNow;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Authorize("write:orders")]
|
||||
[Route("/api/Orders/{orderId:int}/Payment")]
|
||||
public async Task<IActionResult> Payment(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.SellerService)
|
||||
.Include(x=>x.Buyer)
|
||||
.Include(x=>x.Seller)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId && x.BuyerId==userId);
|
||||
if(order==null)
|
||||
return NotFound();
|
||||
if(order.Seller.UserId!=userId)
|
||||
return BadRequest();
|
||||
if(order.Status==EnumOrderStatus.Completed)
|
||||
return BadRequest();
|
||||
if(order.Status!=EnumOrderStatus.WaitingForPayment)
|
||||
return BadRequest();
|
||||
if (order.PaymentUrl != null)
|
||||
return Ok(order.PaymentUrl);
|
||||
var url = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
|
||||
order.PaymentUrl = url;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return Ok(order.PaymentUrl);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize("write:orders")]
|
||||
[Route("/api/Orders/{orderId:int}/Review")]
|
||||
public async Task<IActionResult> Review(int orderId, [FromBody] SellerServiceOrderReviewModel model)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.Reviews)
|
||||
.Include(x=>x.Seller)
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId && x.BuyerId==userId);
|
||||
if(order==null)
|
||||
return NotFound();
|
||||
if(order.BuyerId!=userId)
|
||||
return BadRequest("");
|
||||
if(order.Status!=EnumOrderStatus.Completed)
|
||||
return BadRequest("");
|
||||
if(order.Reviews.Any(x=>x.SellerServiceOrderId==orderId))
|
||||
return BadRequest("");
|
||||
var review = new SellerServiceOrderReview()
|
||||
{
|
||||
SellerServiceOrderId = orderId,
|
||||
SellerServiceId = order.SellerServiceId,
|
||||
Rating = model.Rating,
|
||||
Review = model.Review,
|
||||
ReviewDate = DateTime.UtcNow,
|
||||
ReviewerId = userId,
|
||||
Reviewer = await _dbContext.Users.FirstOrDefaultAsync(x=>x.Id==userId),
|
||||
};
|
||||
await _dbContext.SellerServiceOrderReviews.AddAsync(review);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
@ -1,177 +0,0 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using comissions.app.api.Models.Order;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Services.Storage;
|
||||
using comissions.app.database;
|
||||
using comissions.app.database.Entities;
|
||||
using comissions.app.database.Enums;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace comissions.app.api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class SellerOrderController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
public SellerOrderController(IStorageService storageService, ApplicationDbContext dbContext)
|
||||
{
|
||||
_storageService = storageService;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("/api/SellerOrders")]
|
||||
[Authorize("read:seller-orders")]
|
||||
public async Task<IActionResult> GetOrders(int offset = 0, int pageSize = 10, EnumOrderStatus? status = null)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var orders = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.Seller)
|
||||
.Where(x => x.Seller.UserId == userId && status==null ? true : status==x.Status)
|
||||
.Skip(offset).Take(pageSize).ToListAsync();
|
||||
|
||||
var result = orders.Select(x => x.ToModel()).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("/api/SellerOrders/{orderId:int}")]
|
||||
[Authorize("read:seller-orders")]
|
||||
public async Task<IActionResult> GetOrder(int orderId, int offset = 0, int pageSize = 10, EnumOrderStatus? status = null)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x => x.Seller)
|
||||
.FirstAsync(x => x.Id==orderId && x.Seller.UserId == userId && status == null ? true : status == x.Status);
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize("write:seller-orders")]
|
||||
[Route("/api/SellerOrders/{orderId:int}/Cancel")]
|
||||
public async Task<IActionResult> CancelOrder(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var seller = await _dbContext.UserSellerProfiles.FirstOrDefaultAsync(x=>x.UserId==userId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
if(seller.Suspended)
|
||||
return BadRequest();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId && x.Seller.UserId==userId);
|
||||
if(order==null)
|
||||
return NotFound();
|
||||
if(order.Status==EnumOrderStatus.Completed || order.Status== EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
if(order.BuyerId!=userId)
|
||||
return BadRequest();
|
||||
if(order.Status!=EnumOrderStatus.Completed && order.Status!= EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
order.Status = EnumOrderStatus.Declined;
|
||||
order.EndDate = DateTime.UtcNow;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Authorize("write:seller-orders")]
|
||||
[Route("/api/SellerOrders/{orderId:int}/Accept")]
|
||||
public async Task<IActionResult> AcceptOrder(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var seller = await _dbContext.UserSellerProfiles.FirstOrDefaultAsync(x => x.UserId == userId);
|
||||
if (seller == null)
|
||||
return NotFound();
|
||||
if (seller.Suspended)
|
||||
return BadRequest();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x => x.SellerService)
|
||||
.FirstOrDefaultAsync(x => x.Id == orderId && x.Seller.UserId == userId);
|
||||
if (order == null)
|
||||
return NotFound();
|
||||
if (order.Status == EnumOrderStatus.Completed || order.Status == EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
if (order.BuyerId != userId)
|
||||
return BadRequest();
|
||||
if (order.Status != EnumOrderStatus.PendingAcceptance)
|
||||
return BadRequest();
|
||||
if (order.Status == EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
order.Status = EnumOrderStatus.WaitingForPayment;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Authorize("write:seller-orders")]
|
||||
[Route("/api/SellerOrders/{orderId:int}/Decline")]
|
||||
public async Task<IActionResult> DeclineOrder(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var seller = await _dbContext.UserSellerProfiles.FirstOrDefaultAsync(x => x.UserId == userId);
|
||||
if (seller == null)
|
||||
return NotFound();
|
||||
if (seller.Suspended)
|
||||
return BadRequest();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x => x.SellerService)
|
||||
.FirstOrDefaultAsync(x => x.Id == orderId && x.Seller.UserId == userId);
|
||||
if (order == null)
|
||||
return NotFound();
|
||||
if (order.Status == EnumOrderStatus.Completed || order.Status == EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
if (order.BuyerId != userId)
|
||||
return BadRequest();
|
||||
if (order.Status != EnumOrderStatus.PendingAcceptance)
|
||||
return BadRequest();
|
||||
order.Status = EnumOrderStatus.Declined;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
[HttpPut]
|
||||
[Authorize("write:seller-orders")]
|
||||
[Route("/api/SellerOrders/{orderId:int}/CompleteRevision")]
|
||||
public async Task<IActionResult> CompleteRevision(int orderId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var order = await _dbContext.SellerServiceOrders
|
||||
.Include(x=>x.Seller)
|
||||
.Include(x=>x.SellerService)
|
||||
.FirstOrDefaultAsync(x=>x.Id==orderId && x.Seller.UserId==userId);
|
||||
var seller = await _dbContext.UserSellerProfiles.FirstOrDefaultAsync(x=>x.UserId==userId);
|
||||
if(seller==null)
|
||||
return NotFound();
|
||||
if(seller.Suspended)
|
||||
return BadRequest();
|
||||
if(order==null)
|
||||
return NotFound();
|
||||
if(order.Seller.UserId!=userId)
|
||||
return BadRequest();
|
||||
if(order.Status==EnumOrderStatus.Completed || order.Status== EnumOrderStatus.Declined)
|
||||
return BadRequest();
|
||||
if(order.Status<EnumOrderStatus.InProgress)
|
||||
return BadRequest();
|
||||
if(order.Status>EnumOrderStatus.InProgress)
|
||||
return BadRequest();
|
||||
order.Status = EnumOrderStatus.Completed;
|
||||
order = _dbContext.SellerServiceOrders.Update(order).Entity;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var result = order.ToModel();
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
using comissions.app.api.Extensions;
|
||||
using comissions.app.api.Models.PortfolioModel;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Models.SellerProfile;
|
||||
using comissions.app.api.Models.SellerProfileRequest;
|
||||
using comissions.app.api.Services.Payment;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Security.Claims;
|
||||
using comissions.app.api.Extensions;
|
||||
using ArtPlatform.Database;
|
||||
using comissions.app.api.Models.User;
|
||||
using comissions.app.database;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -10,6 +10,5 @@ public class SellerService
|
||||
public bool Archived { get; set; } = false;
|
||||
|
||||
public virtual ICollection<SellerProfilePortfolioPiece> PortfolioPieces { get; set; } = new List<SellerProfilePortfolioPiece>();
|
||||
public virtual ICollection<SellerServiceOrderReview> Reviews { get; set; } = new List<SellerServiceOrderReview>();
|
||||
public virtual UserSellerProfile SellerProfile { get; set; } = null!;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using comissions.app.database.Enums;
|
||||
|
||||
namespace comissions.app.database.Entities;
|
||||
|
||||
public class SellerServiceOrder
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string BuyerId { get; set; }
|
||||
public int SellerServiceId { get; set; }
|
||||
public int SellerId { get; set; }
|
||||
public EnumOrderStatus Status { get; set; }
|
||||
public double Price { get; set; }
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public DateTime? TermsAcceptedDate { get; set; }
|
||||
public DateTime? EndDate { get; set; }
|
||||
|
||||
public virtual User Buyer { get; set; } = null!;
|
||||
public virtual SellerService SellerService { get; set; } = null!;
|
||||
public virtual UserSellerProfile Seller { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<SellerServiceOrderReview> Reviews { get; set; } = new List<SellerServiceOrderReview>();
|
||||
public string? PaymentUrl { get; set; }
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace comissions.app.database.Entities;
|
||||
|
||||
public class SellerServiceOrderReview
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ReviewerId { get; set; }
|
||||
public int SellerServiceOrderId { get; set; }
|
||||
public int SellerServiceId { get; set; }
|
||||
public DateTime ReviewDate { get; set; }
|
||||
public string? Review { get; set; }
|
||||
public int Rating { get; set; }
|
||||
|
||||
public virtual User Reviewer { get; set; } = null!;
|
||||
public virtual SellerServiceOrder SellerServiceOrder { get; set; } = null!;
|
||||
public virtual SellerService SellerService { get; set; } = null!;
|
||||
}
|
@ -25,5 +25,4 @@ public record User
|
||||
public string? SuspendAdminId { get; set; }
|
||||
|
||||
[JsonIgnore] public virtual UserSellerProfile? UserSellerProfile { get; set; }
|
||||
[JsonIgnore] public virtual ICollection<SellerServiceOrder> Orders { get; set; }
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using System.Security.Claims;
|
||||
using ArtPlatform.Database;
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Services.Payment;
|
||||
using comissions.app.database;
|
||||
using comissions.app.database.Entities;
|
||||
|
@ -1,16 +0,0 @@
|
||||
using comissions.app.database.Enums;
|
||||
|
||||
namespace comissions.app.api.Models.Order;
|
||||
|
||||
public class OrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string BuyerId { get; set; }
|
||||
public int SellerServiceId { get; set; }
|
||||
public int SellerId { get; set; }
|
||||
public EnumOrderStatus Status { get; set; }
|
||||
|
||||
public string StatusLabel => Status.ToString();
|
||||
public double Price { get; set; }
|
||||
public string? PaymentUrl { get; set; }
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.database.Entities;
|
||||
|
||||
namespace comissions.app.api.Models.Order;
|
||||
|
||||
public static class OrderModelExtensions
|
||||
{
|
||||
|
||||
public static OrderModel ToModel(this SellerServiceOrder sellerProfile)
|
||||
{
|
||||
return new OrderModel()
|
||||
{
|
||||
Id = sellerProfile.Id,
|
||||
BuyerId = sellerProfile.BuyerId,
|
||||
SellerServiceId = sellerProfile.SellerServiceId,
|
||||
SellerId = sellerProfile.SellerId,
|
||||
Status = sellerProfile.Status,
|
||||
Price = sellerProfile.Price,
|
||||
PaymentUrl = sellerProfile.PaymentUrl
|
||||
};
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace ArtPlatform.Database.Entities;
|
||||
|
||||
public class SellerServiceOrderMessageModel
|
||||
{
|
||||
public string Message { get; set; }
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace comissions.app.api.Models.Order;
|
||||
|
||||
public class SellerServiceOrderReviewModel
|
||||
{
|
||||
public int Rating { get; set; }
|
||||
public string? Review { get; set; }
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.database.Entities;
|
||||
|
||||
namespace comissions.app.api.Models.PortfolioModel;
|
||||
|
@ -1,4 +1,3 @@
|
||||
using ArtPlatform.Database.Entities;
|
||||
using comissions.app.api.Models.Discovery;
|
||||
using comissions.app.database.Entities;
|
||||
|
||||
@ -39,9 +38,6 @@ public static class SellerProfileModelExtensions
|
||||
}
|
||||
public static DiscoverySellerModel ToDiscoveryModel(this UserSellerProfile sellerProfile)
|
||||
{
|
||||
var reviews = sellerProfile.SellerServices.SelectMany(x => x.Reviews);
|
||||
double reviewAverage = 0;
|
||||
if(reviews.Count()>0) reviewAverage = reviews.Average(x=>x.Rating);
|
||||
|
||||
return new DiscoverySellerModel()
|
||||
{
|
||||
@ -53,9 +49,7 @@ public static class SellerProfileModelExtensions
|
||||
SocialMeidaLink4 = sellerProfile.SocialMediaLink4,
|
||||
Description = sellerProfile.Description,
|
||||
RequestGuidelines = sellerProfile.RequestGuidelines,
|
||||
PrepaymentRequired = sellerProfile.PrepaymentRequired,
|
||||
AverageRating =reviewAverage,
|
||||
ReviewCount = reviews.Count()
|
||||
PrepaymentRequired = sellerProfile.PrepaymentRequired
|
||||
};
|
||||
}
|
||||
public static UserSellerProfile ToModel(this SellerProfileModel sellerProfile, UserSellerProfile existingSellerProfile)
|
||||
|
@ -7,12 +7,6 @@ public static class SellerServiceModelExtensions
|
||||
{
|
||||
double avgRating = 0;
|
||||
int reviewCount = 0;
|
||||
var ratings = sellerProfileRequest.Reviews;
|
||||
if (ratings.Any())
|
||||
{
|
||||
avgRating = ratings.Average(x => x.Rating);
|
||||
reviewCount = sellerProfileRequest.Reviews.Count;
|
||||
}
|
||||
return new SellerServiceModel()
|
||||
{
|
||||
Id = sellerProfileRequest.Id,
|
||||
|
@ -4,7 +4,6 @@ using comissions.app.api.Middleware;
|
||||
using comissions.app.api.Middleware.Authentication;
|
||||
using comissions.app.api.Services.Payment;
|
||||
using comissions.app.api.Services.Storage;
|
||||
using ArtPlatform.Database;
|
||||
using Auth0.AspNetCore.Authentication;
|
||||
using comissions.app.database;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
@ -1,4 +1,3 @@
|
||||
using ArtPlatform.Database.Entities;
|
||||
|
||||
namespace comissions.app.api.Services.Payment;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
using ArtPlatform.Database.Entities;
|
||||
using Stripe;
|
||||
|
||||
namespace comissions.app.api.Services.Payment;
|
||||
|
Loading…
x
Reference in New Issue
Block a user