diff --git a/src/comissions.app.api/ApplicationDbContext.cs b/src/comissions.app.api/ApplicationDbContext.cs index 950d7e3..d74e215 100644 --- a/src/comissions.app.api/ApplicationDbContext.cs +++ b/src/comissions.app.api/ApplicationDbContext.cs @@ -46,7 +46,5 @@ public class ApplicationDbContext:DbContext public DbSet SellerProfileRequests { get; set; }= null!; public DbSet SellerProfilePortfolioPieces { get; set; }= null!; public DbSet SellerServices { get; set; }= null!; - public DbSet SellerServiceOrders { get; set; } = null!; - public DbSet SellerServiceOrderReviews { get; set; }= null!; #endregion } \ No newline at end of file diff --git a/src/comissions.app.api/Controllers/Admin/AdminOrdersController.cs b/src/comissions.app.api/Controllers/Admin/AdminOrdersController.cs deleted file mode 100644 index 08b1477..0000000 --- a/src/comissions.app.api/Controllers/Admin/AdminOrdersController.cs +++ /dev/null @@ -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 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 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 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 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); - } -} \ No newline at end of file diff --git a/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs b/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs index d321baf..dc97785 100644 --- a/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs +++ b/src/comissions.app.api/Controllers/Admin/AdminSellerRequestsController.cs @@ -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; diff --git a/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs b/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs index 4c75e52..695b908 100644 --- a/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs +++ b/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs @@ -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 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 SuspendSeller(int sellerId, [FromQuery]string reason, [FromQuery]int days) diff --git a/src/comissions.app.api/Controllers/Admin/AdminUsersController.cs b/src/comissions.app.api/Controllers/Admin/AdminUsersController.cs index f89e2fc..2428fcd 100644 --- a/src/comissions.app.api/Controllers/Admin/AdminUsersController.cs +++ b/src/comissions.app.api/Controllers/Admin/AdminUsersController.cs @@ -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 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 SuspendUser(string userId, [FromQuery]string reason, [FromQuery]int days) diff --git a/src/comissions.app.api/Controllers/DiscoveryController.cs b/src/comissions.app.api/Controllers/DiscoveryController.cs index 0aca862..aecef66 100644 --- a/src/comissions.app.api/Controllers/DiscoveryController.cs +++ b/src/comissions.app.api/Controllers/DiscoveryController.cs @@ -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 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 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 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 GetSellersCount(string search="") @@ -159,156 +121,4 @@ public class DiscoveryController : Controller .CountAsync(); return Ok(result); } - - [HttpGet] - [Route("Sellers/{sellerId:int}/Services")] - public async Task 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 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 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 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 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 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 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 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); - } } \ No newline at end of file diff --git a/src/comissions.app.api/Controllers/OrderController.cs b/src/comissions.app.api/Controllers/OrderController.cs deleted file mode 100644 index 5531ad4..0000000 --- a/src/comissions.app.api/Controllers/OrderController.cs +++ /dev/null @@ -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("Stripe:WebHookSecret"); - } - - [HttpPost("PaymentWebhook")] - public async Task 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 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 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 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 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 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 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(); - } -} - diff --git a/src/comissions.app.api/Controllers/SellerOrderController.cs b/src/comissions.app.api/Controllers/SellerOrderController.cs deleted file mode 100644 index b300951..0000000 --- a/src/comissions.app.api/Controllers/SellerOrderController.cs +++ /dev/null @@ -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 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 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 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 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 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 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.StatusEnumOrderStatus.InProgress) - return BadRequest(); - order.Status = EnumOrderStatus.Completed; - order = _dbContext.SellerServiceOrders.Update(order).Entity; - await _dbContext.SaveChangesAsync(); - var result = order.ToModel(); - return Ok(result); - } -} \ No newline at end of file diff --git a/src/comissions.app.api/Controllers/SellerProfileController.cs b/src/comissions.app.api/Controllers/SellerProfileController.cs index bbf3d72..f212a09 100644 --- a/src/comissions.app.api/Controllers/SellerProfileController.cs +++ b/src/comissions.app.api/Controllers/SellerProfileController.cs @@ -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; diff --git a/src/comissions.app.api/Controllers/UserController.cs b/src/comissions.app.api/Controllers/UserController.cs index 06afdb4..e9775fb 100644 --- a/src/comissions.app.api/Controllers/UserController.cs +++ b/src/comissions.app.api/Controllers/UserController.cs @@ -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; diff --git a/src/comissions.app.api/Entities/SellerService.cs b/src/comissions.app.api/Entities/SellerService.cs index 06887ba..974e5c5 100644 --- a/src/comissions.app.api/Entities/SellerService.cs +++ b/src/comissions.app.api/Entities/SellerService.cs @@ -10,6 +10,5 @@ public class SellerService public bool Archived { get; set; } = false; public virtual ICollection PortfolioPieces { get; set; } = new List(); - public virtual ICollection Reviews { get; set; } = new List(); public virtual UserSellerProfile SellerProfile { get; set; } = null!; } \ No newline at end of file diff --git a/src/comissions.app.api/Entities/SellerServiceOrder.cs b/src/comissions.app.api/Entities/SellerServiceOrder.cs deleted file mode 100644 index 30be3ab..0000000 --- a/src/comissions.app.api/Entities/SellerServiceOrder.cs +++ /dev/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 Reviews { get; set; } = new List(); - public string? PaymentUrl { get; set; } -} \ No newline at end of file diff --git a/src/comissions.app.api/Entities/SellerServiceOrderReview.cs b/src/comissions.app.api/Entities/SellerServiceOrderReview.cs deleted file mode 100644 index 335173e..0000000 --- a/src/comissions.app.api/Entities/SellerServiceOrderReview.cs +++ /dev/null @@ -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!; -} \ No newline at end of file diff --git a/src/comissions.app.api/Entities/User.cs b/src/comissions.app.api/Entities/User.cs index fbecb73..43c8752 100644 --- a/src/comissions.app.api/Entities/User.cs +++ b/src/comissions.app.api/Entities/User.cs @@ -25,5 +25,4 @@ public record User public string? SuspendAdminId { get; set; } [JsonIgnore] public virtual UserSellerProfile? UserSellerProfile { get; set; } - [JsonIgnore] public virtual ICollection Orders { get; set; } } \ No newline at end of file diff --git a/src/comissions.app.api/Middleware/UserMiddleware.cs b/src/comissions.app.api/Middleware/UserMiddleware.cs index 3a3abae..211ff9b 100644 --- a/src/comissions.app.api/Middleware/UserMiddleware.cs +++ b/src/comissions.app.api/Middleware/UserMiddleware.cs @@ -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; diff --git a/src/comissions.app.api/Models/Order/OrderModel.cs b/src/comissions.app.api/Models/Order/OrderModel.cs deleted file mode 100644 index a416a1d..0000000 --- a/src/comissions.app.api/Models/Order/OrderModel.cs +++ /dev/null @@ -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; } -} \ No newline at end of file diff --git a/src/comissions.app.api/Models/Order/OrderModelExtensions.cs b/src/comissions.app.api/Models/Order/OrderModelExtensions.cs deleted file mode 100644 index 11fef1b..0000000 --- a/src/comissions.app.api/Models/Order/OrderModelExtensions.cs +++ /dev/null @@ -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 - }; - } -} \ No newline at end of file diff --git a/src/comissions.app.api/Models/Order/SellerServiceOrderMessageModel.cs b/src/comissions.app.api/Models/Order/SellerServiceOrderMessageModel.cs deleted file mode 100644 index cc658d6..0000000 --- a/src/comissions.app.api/Models/Order/SellerServiceOrderMessageModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace ArtPlatform.Database.Entities; - -public class SellerServiceOrderMessageModel -{ - public string Message { get; set; } -} \ No newline at end of file diff --git a/src/comissions.app.api/Models/Order/SellerServiceOrderReviewModel.cs b/src/comissions.app.api/Models/Order/SellerServiceOrderReviewModel.cs deleted file mode 100644 index 6d96afc..0000000 --- a/src/comissions.app.api/Models/Order/SellerServiceOrderReviewModel.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace comissions.app.api.Models.Order; - -public class SellerServiceOrderReviewModel -{ - public int Rating { get; set; } - public string? Review { get; set; } -} \ No newline at end of file diff --git a/src/comissions.app.api/Models/PortfolioModel/PortfolioModelExtensions.cs b/src/comissions.app.api/Models/PortfolioModel/PortfolioModelExtensions.cs index ee5b97e..74c3dfb 100644 --- a/src/comissions.app.api/Models/PortfolioModel/PortfolioModelExtensions.cs +++ b/src/comissions.app.api/Models/PortfolioModel/PortfolioModelExtensions.cs @@ -1,4 +1,3 @@ -using ArtPlatform.Database.Entities; using comissions.app.database.Entities; namespace comissions.app.api.Models.PortfolioModel; diff --git a/src/comissions.app.api/Models/SellerProfile/SellerProfileModelExtensions.cs b/src/comissions.app.api/Models/SellerProfile/SellerProfileModelExtensions.cs index 881a8eb..cb430f7 100644 --- a/src/comissions.app.api/Models/SellerProfile/SellerProfileModelExtensions.cs +++ b/src/comissions.app.api/Models/SellerProfile/SellerProfileModelExtensions.cs @@ -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) diff --git a/src/comissions.app.api/Models/SellerService/SellerServiceModelExtensions.cs b/src/comissions.app.api/Models/SellerService/SellerServiceModelExtensions.cs index 092c38c..c61b10d 100644 --- a/src/comissions.app.api/Models/SellerService/SellerServiceModelExtensions.cs +++ b/src/comissions.app.api/Models/SellerService/SellerServiceModelExtensions.cs @@ -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, diff --git a/src/comissions.app.api/Program.cs b/src/comissions.app.api/Program.cs index 111bb1e..2537236 100644 --- a/src/comissions.app.api/Program.cs +++ b/src/comissions.app.api/Program.cs @@ -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; diff --git a/src/comissions.app.api/Services/Payment/IPaymentService.cs b/src/comissions.app.api/Services/Payment/IPaymentService.cs index e5804cc..29a3dd7 100644 --- a/src/comissions.app.api/Services/Payment/IPaymentService.cs +++ b/src/comissions.app.api/Services/Payment/IPaymentService.cs @@ -1,4 +1,3 @@ -using ArtPlatform.Database.Entities; namespace comissions.app.api.Services.Payment; diff --git a/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs b/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs index cc11818..e137f60 100644 --- a/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs +++ b/src/comissions.app.api/Services/Payment/StripePaymentServiceProvider.cs @@ -1,4 +1,3 @@ -using ArtPlatform.Database.Entities; using Stripe; namespace comissions.app.api.Services.Payment;