mirror of
https://github.com/Shchoholiev/shopping-assistant-web-client.git
synced 2025-04-05 00:59:38 +00:00
Create Query for wishlist
This commit is contained in:
parent
6cadba038a
commit
dade9b4a29
@ -14,6 +14,8 @@ public class GlobalUserMiddleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task InvokeAsync(HttpContext httpContext, AuthenticationService authenticationService, ApiClient apiClient)
|
public async Task InvokeAsync(HttpContext httpContext, AuthenticationService authenticationService, ApiClient apiClient)
|
||||||
|
{
|
||||||
|
if (httpContext.Request.Path != "/login")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -30,9 +32,9 @@ public class GlobalUserMiddleware
|
|||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
{
|
{
|
||||||
httpContext.Response.Cookies.Delete("accessToken");
|
httpContext.Response.Cookies.Delete("accessToken");
|
||||||
httpContext.Response.Redirect("");
|
httpContext.Response.Redirect("/login");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _next(httpContext);
|
await _next(httpContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
@page "/chat/{chatId}"
|
@page "/chat/{chatId}"
|
||||||
|
|
||||||
|
@inject IHttpClientFactory ClientFactory
|
||||||
|
|
||||||
<PageTitle>Gift for Jessica</PageTitle>
|
<PageTitle>Gift for Jessica</PageTitle>
|
||||||
|
|
||||||
<div class="right_frame" id="rightFrame">
|
<div class="right_frame" id="rightFrame">
|
||||||
@ -40,6 +43,27 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="possible_options">
|
||||||
|
|
||||||
|
<div class="tite_options">Several possible options</div>
|
||||||
|
|
||||||
|
<div class="options" >
|
||||||
|
|
||||||
|
<div class="topic_options">
|
||||||
|
HDMI
|
||||||
|
</div>
|
||||||
|
<div class="topic_options">
|
||||||
|
VGA
|
||||||
|
</div>
|
||||||
|
<div class="topic_options">
|
||||||
|
DisplayPort
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -62,6 +86,8 @@
|
|||||||
|
|
||||||
[Parameter] public string chatId { get; set; }
|
[Parameter] public string chatId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,50 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using ShoppingAssistantWebClient.Web.Models;
|
||||||
|
using GraphQL;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using ShoppingAssistantWebClient.Web.Network;
|
||||||
|
|
||||||
namespace ShoppingAssistantWebClient.Web.Pages;
|
namespace ShoppingAssistantWebClient.Web.Pages;
|
||||||
|
|
||||||
public partial class Chat : ComponentBase
|
public partial class Chat : ComponentBase
|
||||||
{
|
{
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public ILogger<Chat> Logger { get; set; }
|
private ApiClient _apiClient { get; set; }
|
||||||
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
// Get data from Back-end
|
await LoadMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task LoadMenus()
|
||||||
|
{
|
||||||
|
var pageNumber = 1;
|
||||||
|
var request = new GraphQLRequest
|
||||||
|
{
|
||||||
|
Query = @"mutation StartPersonalWishlist {
|
||||||
|
startPersonalWishlist(dto: { type: product, firstMessageText: hello }) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
type
|
||||||
|
createdById
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
|
||||||
|
Variables = new
|
||||||
|
{
|
||||||
|
pageNumber = pageNumber,
|
||||||
|
pageSize = 12,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await _apiClient.QueryAsync(request);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,36 @@
|
|||||||
border-radius: 0.6em;
|
border-radius: 0.6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.possible_options {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 5.5em;
|
||||||
|
margin-left: 25%;
|
||||||
|
width: 50%;
|
||||||
|
border-radius: 0.6em;
|
||||||
|
}
|
||||||
|
.tite_options{
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #ADADAD;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
|
||||||
|
}
|
||||||
|
.options{
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
.topic_options
|
||||||
|
{
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.5em;
|
||||||
|
border: 0.09em solid;
|
||||||
|
border-color: #009FFF;
|
||||||
|
border-radius: 0.6em;
|
||||||
|
margin: 0em 0.6em;
|
||||||
|
flex: 1;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.input_messages {
|
.input_messages {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 2.5em;
|
height: 2.5em;
|
||||||
@ -72,8 +102,8 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
line-height: 2.5em;
|
line-height: 2.5em;
|
||||||
margin-right: 0.8em;
|
margin-right: 0.8em;
|
||||||
width: 1.8em;
|
width: 1.5em;
|
||||||
height: 1.7em;
|
height: 1.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.new_chat {
|
.new_chat {
|
||||||
|
8
ShoppingAssistantWebClient.Web/Pages/Login.cshtml
Normal file
8
ShoppingAssistantWebClient.Web/Pages/Login.cshtml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
@page "/login"
|
||||||
|
@model ShoppingAssistantWebClient.Web.Pages.LoginModel
|
||||||
|
|
||||||
|
<h1>Login</h1>
|
||||||
|
|
||||||
|
@{
|
||||||
|
|
||||||
|
}
|
12
ShoppingAssistantWebClient.Web/Pages/Login.cshtml.cs
Normal file
12
ShoppingAssistantWebClient.Web/Pages/Login.cshtml.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace ShoppingAssistantWebClient.Web.Pages
|
||||||
|
{
|
||||||
|
public class LoginModel : PageModel
|
||||||
|
{
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
|
using GraphQL.Client.Http;
|
||||||
using ShoppingAssistantWebClient.Web.Configurations;
|
using ShoppingAssistantWebClient.Web.Configurations;
|
||||||
using ShoppingAssistantWebClient.Web.Data;
|
using ShoppingAssistantWebClient.Web.Data;
|
||||||
|
using ShoppingAssistantWebClient.Web.Network;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -28,6 +30,6 @@ app.UseRouting();
|
|||||||
app.MapBlazorHub();
|
app.MapBlazorHub();
|
||||||
app.MapFallbackToPage("/_Host");
|
app.MapFallbackToPage("/_Host");
|
||||||
|
|
||||||
// app.ConfigureGlobalUserMiddleware();
|
app.ConfigureGlobalUserMiddleware();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
@inject NavigationManager Navigation
|
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
|
||||||
|
|
||||||
<div id="leftframe" class="left_frame">
|
<div id="leftframe" class="left_frame">
|
||||||
|
|
||||||
@ -27,6 +29,8 @@
|
|||||||
|
|
||||||
<div class="wishlist_names">
|
<div class="wishlist_names">
|
||||||
|
|
||||||
|
@if(!isLoading){
|
||||||
|
|
||||||
@foreach (var item in Wishlists)
|
@foreach (var item in Wishlists)
|
||||||
{
|
{
|
||||||
<section class="cont_wishlist">
|
<section class="cont_wishlist">
|
||||||
@ -36,6 +40,10 @@
|
|||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
<div>loading ...</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -90,6 +98,7 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
|
|
||||||
private void RedirectToPage(string itemId) {
|
private void RedirectToPage(string itemId) {
|
||||||
var url = $"/chat/{itemId}";
|
var url = $"/chat/{itemId}";
|
||||||
Navigation.NavigateTo(url);
|
Navigation.NavigateTo(url);
|
||||||
@ -102,7 +111,9 @@
|
|||||||
var url = $"/chat/{itemId}/cart";
|
var url = $"/chat/{itemId}/cart";
|
||||||
Navigation.NavigateTo(url);
|
Navigation.NavigateTo(url);
|
||||||
}
|
}
|
||||||
private void DeleteWishlist(string itemId) {
|
private async void DeleteWishlist(string itemId) {
|
||||||
|
|
||||||
|
await DeleteWish(itemId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,80 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using ShoppingAssistantWebClient.Web.Models;
|
using ShoppingAssistantWebClient.Web.Models;
|
||||||
|
using GraphQL;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using ShoppingAssistantWebClient.Web.Network;
|
||||||
|
|
||||||
namespace ShoppingAssistantWebClient.Web.Shared
|
namespace ShoppingAssistantWebClient.Web.Shared
|
||||||
{
|
{
|
||||||
public partial class NavMenu : ComponentBase
|
public partial class NavMenu : ComponentBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public List<Wishlist> Wishlists = new()
|
[Inject]
|
||||||
{
|
private ApiClient _apiClient { get; set; }
|
||||||
new Wishlist {Id = "0", Name = "Gift for Jessica", Type="product", CreateById="0"},
|
|
||||||
new Wishlist {Id = "1", Name = "Secret Santa", Type="gift", CreateById="1"},
|
|
||||||
new Wishlist {Id = "2", Name = "Mark’s Birthday", Type="product", CreateById="2"}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
//public string jwt;
|
||||||
|
|
||||||
|
public List<Wishlist> Wishlists { get; set; }
|
||||||
|
public bool isLoading = true;
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
// Get data from Back-end
|
//jwt = _apiClient.JwtToken;
|
||||||
|
|
||||||
|
await LoadMenus();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task LoadMenus()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
isLoading = true;
|
||||||
|
var pageNumber = 1;
|
||||||
|
var request = new GraphQLRequest
|
||||||
|
{
|
||||||
|
Query = @"query PersonalWishlistsPage( $pageNumber: Int!, $pageSize: Int!) {
|
||||||
|
personalWishlistsPage(pageNumber: $pageNumber, pageSize: $pageSize) {
|
||||||
|
items {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
|
||||||
|
Variables = new
|
||||||
|
{
|
||||||
|
pageNumber,
|
||||||
|
pageSize = 10,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await _apiClient.QueryAsync(request);
|
||||||
|
var responseData = response.Data;
|
||||||
|
var jsonCategoriesResponse = JsonConvert.SerializeObject(responseData.personalWishlistsPage.items);
|
||||||
|
this.Wishlists = JsonConvert.DeserializeObject<List<Wishlist>>(jsonCategoriesResponse);
|
||||||
|
isLoading = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task DeleteWish(string wishlistId)
|
||||||
|
{
|
||||||
|
var request = new GraphQLRequest
|
||||||
|
{
|
||||||
|
Query = @"mutation DeletePersonalWishlist($wishlistId: String!) {
|
||||||
|
deletePersonalWishlist(wishlistId: $wishlistId) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
Variables = new
|
||||||
|
{
|
||||||
|
wishlistId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await _apiClient.QueryAsync(request);
|
||||||
|
var responseData = response.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
{
|
{
|
||||||
"DetailedErrors": true,
|
|
||||||
"Logging": {
|
"ApiUrl": "https://shopping-assistant-api-dev.azurewebsites.net/"
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ApiUrl": "https://localhost:7268/"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user