Skip to content

Commit

Permalink
feat: add search to promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
Jangkuz committed Jul 10, 2024
1 parent bf77f71 commit a0881a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/Helper/PromotionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PromotionQuery
public long PromotionId { get; set; }
public string? PromotionName { get; set; }
public string PromotionCode { get; set; } = string.Empty;
public string? SearchPromotion { get; set; } = string.Empty;
public float DiscountPercent { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions backend/Repository/PromotionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using backend.Mappers;
using backend.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;

namespace backend.Repository
{
Expand Down Expand Up @@ -43,6 +44,15 @@ public async Task<PromotionResult> GetAllPromotionAsync(PromotionQuery query)
);
}

if (!query.SearchPromotion.IsNullOrEmpty())
{
promotionQueries = promotionQueries.Where(x =>
x.PromotionName.Contains(query.SearchPromotion!) ||
x.PromotionCode.Contains(query.SearchPromotion!)
);

}

var totalCount = await promotionQueries.CountAsync();
var totalPages = (int)Math.Ceiling((double)totalCount / query.PageSize);

Expand Down
13 changes: 8 additions & 5 deletions frontend/src/pages/dashboard/promotion/PromotionManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ export default function PriceRate() {
<Form.Item className="flex-grow">
<Input
type="text"
placeholder="Search"
placeholder="Search by code"
id="keyword"
className="border p-2 rounded-md w-full"
value={params.get("PromotionName") || ""}
// value={params.get("PromotionName") || ""}
value={searchTerm}
onChange={(e) => {
params.set("PromotionName", e.target.value);
setSearchTerm(e.target.value)
params.set("SearchPromotion", e.target.value);
setQueryUrl(`/api/Promotion?` + params.toString());
navigate({ search: params.toString() });
}}
/>
Expand All @@ -107,7 +110,7 @@ export default function PriceRate() {
setSearchTerm("");
// Clear the URL parameters
const params = new URLSearchParams(location.search);
params.delete("PromotionName");
params.delete("SearchPromotion");
setQueryUrl(`/api/Promotion?` + params.toString());
// params.delete("type");
navigate({ search: params.toString() });
Expand Down Expand Up @@ -148,7 +151,7 @@ export default function PriceRate() {
<LoadingItem key={key} />
))}
{promotionList?.data &&
promotionList?.data?.promotion?.length > 0 ? (
promotionList?.data?.promotion?.length > 0 ? (
promotionList?.data?.promotion?.map(renderPromotionRow)
) : (
<td colSpan={100} className="py-20 w-full">
Expand Down

0 comments on commit a0881a3

Please sign in to comment.