Create Query for wishlist

This commit is contained in:
––AsTroLog 2023-11-02 16:28:02 +02:00
parent 6cadba038a
commit dade9b4a29
10 changed files with 229 additions and 46 deletions

View File

@ -14,6 +14,8 @@ public class GlobalUserMiddleware
}
public async Task InvokeAsync(HttpContext httpContext, AuthenticationService authenticationService, ApiClient apiClient)
{
if (httpContext.Request.Path != "/login")
{
try
{
@ -30,9 +32,9 @@ public class GlobalUserMiddleware
catch (AuthenticationException ex)
{
httpContext.Response.Cookies.Delete("accessToken");
httpContext.Response.Redirect("");
httpContext.Response.Redirect("/login");
}
}
await _next(httpContext);
}
}

View File

@ -1,4 +1,7 @@
@page "/chat/{chatId}"
@inject IHttpClientFactory ClientFactory
<PageTitle>Gift for Jessica</PageTitle>
<div class="right_frame" id="rightFrame">
@ -40,6 +43,27 @@
</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>
@ -62,6 +86,8 @@
[Parameter] public string chatId { get; set; }
}

View File

@ -1,14 +1,50 @@
using Microsoft.AspNetCore.Components;
using ShoppingAssistantWebClient.Web.Models;
using GraphQL;
using Newtonsoft.Json;
using ShoppingAssistantWebClient.Web.Network;
namespace ShoppingAssistantWebClient.Web.Pages;
public partial class Chat : ComponentBase
{
[Inject]
public ILogger<Chat> Logger { get; set; }
private ApiClient _apiClient { get; set; }
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);
}
}

View File

@ -55,6 +55,36 @@
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 {
width: 100%;
height: 2.5em;
@ -72,8 +102,8 @@
cursor: pointer;
line-height: 2.5em;
margin-right: 0.8em;
width: 1.8em;
height: 1.7em;
width: 1.5em;
height: 1.4em;
}
.new_chat {

View File

@ -0,0 +1,8 @@
@page "/login"
@model ShoppingAssistantWebClient.Web.Pages.LoginModel
<h1>Login</h1>
@{
}

View 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()
{
}
}
}

View File

@ -1,5 +1,7 @@
using GraphQL.Client.Http;
using ShoppingAssistantWebClient.Web.Configurations;
using ShoppingAssistantWebClient.Web.Data;
using ShoppingAssistantWebClient.Web.Network;
var builder = WebApplication.CreateBuilder(args);
@ -28,6 +30,6 @@ app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
// app.ConfigureGlobalUserMiddleware();
app.ConfigureGlobalUserMiddleware();
app.Run();

View File

@ -1,4 +1,6 @@
@inject NavigationManager Navigation

@inject NavigationManager Navigation
<div id="leftframe" class="left_frame">
@ -27,6 +29,8 @@
<div class="wishlist_names">
@if(!isLoading){
@foreach (var item in Wishlists)
{
<section class="cont_wishlist">
@ -36,6 +40,10 @@
</section>
}
}else{
<div>loading ...</div>
}
</div>
@ -90,6 +98,7 @@
@code {
private void RedirectToPage(string itemId) {
var url = $"/chat/{itemId}";
Navigation.NavigateTo(url);
@ -102,7 +111,9 @@
var url = $"/chat/{itemId}/cart";
Navigation.NavigateTo(url);
}
private void DeleteWishlist(string itemId) {
private async void DeleteWishlist(string itemId) {
await DeleteWish(itemId);
}

View File

@ -1,21 +1,80 @@
using Microsoft.AspNetCore.Components;
using ShoppingAssistantWebClient.Web.Models;
using GraphQL;
using Newtonsoft.Json;
using ShoppingAssistantWebClient.Web.Network;
namespace ShoppingAssistantWebClient.Web.Shared
{
public partial class NavMenu : ComponentBase
{
public List<Wishlist> Wishlists = new()
{
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 = "Marks Birthday", Type="product", CreateById="2"}
};
[Inject]
private ApiClient _apiClient { get; set; }
//public string jwt;
public List<Wishlist> Wishlists { get; set; }
public bool isLoading = true;
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;
}
}

View File

@ -1,10 +1,7 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ApiUrl": "https://localhost:7268/"
"ApiUrl": "https://shopping-assistant-api-dev.azurewebsites.net/"
}