From e8c0b86cc05682568f9b9f88c81a876e88d9d414 Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 11 Feb 2024 18:29:41 -0500 Subject: [PATCH] fix: added new endpoints for getting portfolio for a service --- .../Controllers/DiscoveryController.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/comissions.app.api/Controllers/DiscoveryController.cs b/src/comissions.app.api/Controllers/DiscoveryController.cs index c8e0811..68c7a4f 100644 --- a/src/comissions.app.api/Controllers/DiscoveryController.cs +++ b/src/comissions.app.api/Controllers/DiscoveryController.cs @@ -180,6 +180,65 @@ public class DiscoveryController : Controller 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("Seller not found."); + var sellerService = await _dbContext.SellerServices + .Include(x=>x.PortfolioPieces) + .FirstOrDefaultAsync(x=>x.Id==serviceId); + if(sellerService==null) + return NotFound("Seller service not found."); + 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("Seller not found."); + var sellerService = await _dbContext.SellerServices + .Include(x=>x.PortfolioPieces) + .FirstOrDefaultAsync(x=>x.Id==serviceId); + if(sellerService==null) + return NotFound("Seller service not found."); + 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("Seller not found."); + var sellerService = await _dbContext.SellerServices + .Include(x=>x.PortfolioPieces) + .FirstOrDefaultAsync(x=>x.Id==serviceId); + if(sellerService==null) + return NotFound("Seller service not found."); + 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)