Skip to content

Commit

Permalink
Avalonia Client Implementation
Browse files Browse the repository at this point in the history
Configured Avalonia for ordering and authentication. User can create new order, pay for it and check order details in order history.
  • Loading branch information
mqsrr committed May 17, 2024
1 parent 35a2d55 commit 584fea0
Show file tree
Hide file tree
Showing 58 changed files with 686 additions and 323 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,5 @@ MigrationBackup/
*.DS_Store
DigiCertGlobalRootCA.crt.pem

/.idea
/.idea
.env
13 changes: 9 additions & 4 deletions CoffeeSpace.AClient/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaWebView;
using CoffeeSpace.AClient.Extensions;
using CoffeeSpace.AClient.HttpHandlers;
using CoffeeSpace.AClient.RefitClients;
using CoffeeSpace.AClient.Settings;
using CoffeeSpace.AClient.ViewModels;
using CoffeeSpace.AClient.Services;
using CoffeeSpace.AClient.Services.Abstractions;
using CoffeeSpace.AClient.Views;
using HotAvalonia;
using Microsoft.Extensions.DependencyInjection;

namespace CoffeeSpace.AClient;

public partial class App : Application
public class App : Application
{
public override void Initialize()
{
this.EnableHotReload();

AvaloniaWebViewBuilder.Initialize(default);
AvaloniaXamlLoader.Load(this);
}

Expand All @@ -27,18 +30,20 @@ public override void OnFrameworkInitializationCompleted()
{
var services = new ServiceCollection();
services.AddMediator();

services.RegisterViews();
services.RegisterViewModels();

services.AddTransient<BearerAuthorizationMessageHandler>();
services.AddTransient<ApiKeyAuthorizationMessageHandler>();

services.AddSingleton<IHubConnectionService, HubConnectionService>();
services.AddWebApiClient<IIdentityWebApi, ApiKeyAuthorizationMessageHandler>()
.AddWebApiClient<IProductsWebApi>()
.AddWebApiClient<IOrderingWebApi>()
.AddWebApiClient<IBuyersWebApi>();

Services = services.BuildServiceProvider(true);

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.ShutdownMode = ShutdownMode.OnLastWindowClose;
Expand Down
18 changes: 11 additions & 7 deletions CoffeeSpace.AClient/CoffeeSpace.AClient.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<LangVersion>12</LangVersion>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,10 +19,13 @@
<ItemGroup>
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="Avalonia.Markup.Xaml.Loader" Version="11.0.10" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.0.1" />
<PackageReference Include="HotAvalonia.Extensions" Version="1.0.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.1" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.1.1" />
<PackageReference Include="HotAvalonia.Extensions" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.5" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.2" />
<PackageReference Include="WebView.Avalonia" Version="11.0.0.1" />
<PackageReference Include="WebView.Avalonia.Desktop" Version="11.0.0.1" />
<PackageReference Include="WebView.Avalonia.MacCatalyst" Version="11.0.0.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -40,9 +44,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="Riok.Mapperly" Version="3.4.0" />
<PackageReference Include="Riok.Mapperly" Version="3.5.1" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="SukiUI" Version="6.0.0-beta" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace CoffeeSpace.AClient.Contracts.Requests.Orders;

public sealed class CreateOrderItemRequest
{
public required string Title { get; init; }

public required string Description { get; init; }

public required float UnitPrice { get; init; }

public required int Quantity { get; set; }

public int Discount { get; set; } = 0;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using CoffeeSpace.AClient.Models;

namespace CoffeeSpace.AClient.Contracts.Requests.Orders;

Expand All @@ -9,5 +8,5 @@ public sealed class CreateOrderRequest

public required CreateAddressRequest Address { get; init; }

public required IEnumerable<OrderItem> OrderItems { get; init; }
public required IEnumerable<CreateOrderItemRequest> OrderItems { get; init; }
}
19 changes: 19 additions & 0 deletions CoffeeSpace.AClient/Converters/IdConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace CoffeeSpace.AClient.Converters;

internal sealed class IdConverter : IValueConverter
{

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value!.ToString()![..8] + "...";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return null;
}
}
Loading

0 comments on commit 584fea0

Please sign in to comment.