Skip to content

Commit

Permalink
Merge pull request #112 from flurium/dev
Browse files Browse the repository at this point in the history
MVP
  • Loading branch information
roman-koshchei authored Nov 5, 2023
2 parents 502f57e + 62fd0d9 commit 749fda9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
7 changes: 7 additions & 0 deletions Backend/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,11 @@ public async Task<IActionResult> ResetPassword(ResetPasswordInput input)
}
return Ok();
}

[HttpPost("logout")]
public IActionResult Logout()
{
Response.Cookies.Delete(RefreshOnly.Cookie);
return Ok();
}
}
14 changes: 3 additions & 11 deletions Backend/Controllers/ShopRoutes/CartController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Data;
using Data.Models.ProductTables;
using Lib.EntityFrameworkCore;
using Lib.Storage;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -17,24 +18,15 @@ public CartController(Db db)
this.db = db;
}

[HttpGet("test")]
public async Task<IActionResult> Test()
{
var products = await db.Products.QueryMany();
return Ok(products);
}

public record LocalListInput(List<string> Ids, string Domain);
public record LocalListOutput(string Id, string Name, double Price, StorageFile? Image);

[HttpPost("local")]
public async Task<IActionResult> LocalList([FromBody] LocalListInput input)
{
var products = await db.Products
// .OwnedBy(input.Domain)
.Where(x =>
// !x.IsDraft &&
input.Ids.Contains(x.Id))
.WithDomain(input.Domain)
.Where(x => x.IsDraft == false && input.Ids.Contains(x.Id))
.Include(x => x.Images)
.Select(x => new LocalListOutput(
x.Id, x.Name, x.Price,
Expand Down
8 changes: 2 additions & 6 deletions Backend/Controllers/ShopRoutes/CatalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Lib.EntityFrameworkCore;
using Lib.Storage;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Backend.Controllers.ShopRoutes;

Expand Down Expand Up @@ -53,8 +52,7 @@ public async Task<IActionResult> List([FromRoute] string domain, [FromBody] Cata
var search = input.Search.ToLower();

IQueryable<Product> query = db.Products
.Where(x => x.ShopId == shop.Id && x.Name.ToLower().Contains(search) && x.IsDraft == false)
.Include(x => x.Images)
.Where(x => x.ShopId == shop.Id && x.Name.ToLower().Contains(search) && x.IsDraft == false && x.Amount > 0)
.OrderBy(x => x.Name.ToLower().StartsWith(search));

if (input.Min != null && input.Min > 0) query = query.Where(x => x.Price >= input.Min);
Expand All @@ -73,14 +71,12 @@ public async Task<IActionResult> List([FromRoute] string domain, [FromBody] Cata
));
}

query = query.Where(x => x.Amount > 0);

query = query.Skip(input.Start).Take(input.Count);

var products = await query
.Select(x => new ProductsOutput(
x.Id, x.Name, x.Price, x.DiscountPrice, x.IsDiscount,
x.Images.Select(x => x.GetStorageFile()).FirstOrDefault(), x.SeoSlug
x.Images.OrderBy(i => i.Id == x.PreviewImage).Select(x => x.GetStorageFile()).FirstOrDefault(), x.SeoSlug
))
.QueryMany();

Expand Down
5 changes: 3 additions & 2 deletions Backend/Controllers/ShopRoutes/SingleProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IActionResult> SingleProduct(
{
var product = await db.Products
.WithDomain(domain)
.Where(x => x.SeoSlug == slugOrId || x.Id == slugOrId)
.Where(x => x.IsDraft == false && (x.SeoSlug == slugOrId || x.Id == slugOrId))
.Select(x => new
{
x.Id,
Expand Down Expand Up @@ -99,7 +99,8 @@ public async Task<List<ProductItemOutput>> SimilarProducts(string domain, string
}

var products = await db.Products
.Where(x => x.Shop.Domains.Any(x => x.Domain == domain && x.Verified) && x.Name != name)
.WithDomain(domain)
.Where(x => x.IsDraft == false && x.Name != name)
.Where(keywordsPredicate)
.Select(x => new ProductItemOutput(
x.Id, x.Name, x.Price, x.DiscountPrice, x.IsDiscount,
Expand Down
1 change: 0 additions & 1 deletion Backend/Controllers/SiteRoutes/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Lib.EntityFrameworkCore;
using Lib.Storage;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

Expand Down
10 changes: 2 additions & 8 deletions Backend/Controllers/SiteRoutes/OrderController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Backend.Auth;
using Data;
using Data.Models.ProductTables;
using Data.Models.ShopTables;
using Lib.Email;
using Lib.EntityFrameworkCore;
using LinqKit;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -15,12 +13,10 @@ namespace Backend.Controllers.SiteRoutes;
public class OrderController : ControllerBase
{
private readonly Db db;
private readonly IEmailSender email;

public OrderController(Db db, IEmailSender email)
public OrderController(Db db)
{
this.db = db;
this.email = email;
}

public record OrderOutput(string Id, double Total, int Amount, string Status, DateTime Date);
Expand Down Expand Up @@ -57,7 +53,6 @@ public async Task<IActionResult> SetStatus([FromRoute] string orderId, [FromBody

if (input.Status == "Скасовано")
{

var predicate = PredicateBuilder.New<Product>();
foreach (var orderProduct in order.OrderProducts)
{
Expand All @@ -75,9 +70,8 @@ public async Task<IActionResult> SetStatus([FromRoute] string orderId, [FromBody

product.Amount += orderProduct.Amount;
}

}
else if ((input.Status == "Готується" || input.Status == "Виконано") && order.Status == "Скасовано" )
else if ((input.Status == "Готується" || input.Status == "Виконано") && order.Status == "Скасовано")
{
var predicate = PredicateBuilder.New<Product>();
foreach (var orderProduct in order.OrderProducts)
Expand Down

0 comments on commit 749fda9

Please sign in to comment.