# [WP] BistroQ - Milestone 3 Report
> [!Note]
> This report can be viewed in [HackMD - Milestone 3](https://hackmd.io/IyPQ1qkBQi6bd1jpK7Frmw) (We strongly recommend to read on the web for better reading experience).
> [!Note] Links
> Milestone 1 report: [HackMD - Milestone 1](https://hackmd.io/4tSDCY54TkaXIRHzsXetDg)
> Milestone 2 report: [HackMD - Milestone 2](https://hackmd.io/gwAceDgMRQSu2DYeAvD3Sg)
> Link to project: [Google Drive](https://drive.google.com/drive/folders/1yOPkMX5zgYTEN986CiEkPVB_U9MS15DY?usp=sharing)
> Documentation (Generated by Doxygen): [WinUI](https://tien4112004.github.io/bistro-q-documentation/html/index.html), [API](https://tien4112004.github.io/bistro-q-api-documentation/)
> Published GitHub Repositories: [WinUI](https://github.com/tien4112004/bistro-q), [API](https://github.com/tien4112004/bistro-q-api)
> Demo video: [YouTube]](https://youtu.be/fLFgXRDfpOc)
## Table of Contents
- [Overview](#Overview)
- [Project Setup](#Project-Setup)
- [Backend Setup](#Backend-Setup)
- [Frontend Setup](#Frontend-Setup)
- [Test Accounts](#Test-Accounts)
- [Features](#Features)
- [Completed Works](#Completed-Works)
- [UI/UX](#UI-UX)
- [Design Pattern](#Design-Pattern)
- [Architecture](#Architecture)
- [Documentation](#Documentation)
- [Advanced Topics](#Advanced-Topics)
- [SignalR](#SignalR)
- [VietQR](#VietQR)
- [Unit Test](#Unit-Test)
- [Git Flow Evidence](#Git-Flow-Evidence)
- [Code Review Evidence](#Code-Review-Evidence)
- [Admin Account API](#Admin-Account-API)
- [Admin Account WinUI](#Admin-Account-WinUI)
- [Nutrition Fact CRUD API](#Nutrition-Fact-CRUD-API)
- [UpdateNutritionFact API](#Update-Nutrition-Fact-API)
- [Nutrition Fact Admin Interface WinUI](#Nutrition-Fact-Admin-Interface-WinUI)
- [Refactor Version 2 WinUI](#Refactor-Version-2-WinUI)
- [Product Recommendation API](#Product-Recommendation-API)
- [Nutrition Fact Client Interface WinUI](#Nutrition-Fact-Client-Interface-WinUI)
- [Checkout API](#Checkout-API)
- [Checkout WinUI](#Checkout-WinUI)
- [Recommendation Products WinUI](#Recommendation-Products-WinUI)
- [Documentation](#Documentation)
## Overview
In this milestone, we are focused in the new features about nutrition facts, product recommendations and realtime handling between clients.
## Project Setup
### Backend Setup
1. Create `.env` based on `.env.sample` file and fill the API Key with the key provided in submission in Moodle.
2. Ensure MySQL and database is working
3. Run database migration:
```bash!
dotnet ef database update --project BistroQ.Infrastructure --startup-project BistroQ.API --context BistroQ.Infrastructure.Data.BistroQContext --verbose # Run migrations
```
4. Run server:
```bash!
dotnet watch run --project .\BistroQ.API
```
### Frontend Setup
1. Have backend server running successfully.
2. Run `BistroQ.Presentation` Project through Visual Studio.
### Test Accounts
| Role | Username | Password |
| ------- | -------- | -------- |
| Admin | admin | admin |
| Kitchen | kitchen | kitchen |
| Cashier | cashier | cashier |
| Client | client1 | client |
| Client | client2 | client |
| Client | client3 | client |
...
| Client | client8 | client |
| Client | client9 | client |
## Features
### Completed Works
In this milestone, we have done these tasks below:
| Task | Working hours (est.) | Responsible by |
| -------------------------------------- | -------------------- | -------------- |
| Admin Account API Implementation | 1 hours | Toàn |
| Admin Account WinUI Interface | 0.5 hours | Toàn |
| Nutrition Fact CRUD API | 1 hours | Tiến |
| Nutrition Fact Admin Interface WinUI | 0.75 hours | Tiến |
| Product Recommendation API | 2.25 hours | Both |
| Nutrition Fact Client WinUI (Integrated LiveCharts2) | 2 hours| Tiến |
| Checkout API Implementation | 2 hours | Toàn |
| Checkout WinUI Interface | 2.5 hours | Toàn |
| Recommendation Products WinUI | 0.5 hours | Tiến |
| Documentation | 1.5 hours | Both |
Total estimated working hours: 14 hours.
## UI/UX
- Demo video: [here](https://youtu.be/fLFgXRDfpOc)
- Realtime PR (see how cashier know the client is checking out): [here](https://github.com/tien4112004/bistro-q/pull/26)
## Design Pattern
:::info
In this milestone, we only utilized the patterns from previous milestones without introducing any new ones.
:::
## Architecture
:::info
We decided to keep architecture since it was well-constructed.
:::
## Documentation
In both projects, we have prepared the Doxyfile for generating documentations. Please install `doxygen` and its dependencies, then run the command below to generate documents.
```bash
doxygen
```
Because of the generation process may takes some times (~100MB for both projects), we have hosted the documentation to GitHub Pages: [WinUI](https://tien4112004.github.io/bistro-q-documentation/html/index.html) & [Backend](https://tien4112004.github.io/bistro-q-api-documentation/)
## Advanced Topics
### SignalR
`SignalR` is used to implement real-time communication between the Client and Cashier during the checkout process. This enables immediate updates and interactions between both parties.
Example:
```csharp!
// Server
public class CheckoutHub : Hub
{
public async Task InitiateCheckout(int tableId)
{
// Some implementations
await Clients.Caller.SendAsync("CheckoutInitiated", paymentData); // Send payment data back to client
await Clients.Group("Cashiers").SendAsync("NewCheckout", tableId, table.Number, table.ZoneName); // Send new payment announcement to cashier
}
public async Task CompleteCheckout(int tableId)
{
// Some implementations
await Clients.Group($"Client_{tableId}").SendAsync("CheckoutCompleted"); // Send client that the checkout is completed
}
}
// Client
public class CheckoutRealTimeService : ICheckoutRealTimeService
{
public CheckoutRealTimeService()
{
// Some other connections and initializations
// Shows the payment URL to the client
_hubConnection.On<string>("CheckoutInitiated", (paymentData) =>
OnCheckoutInitiated?.Invoke(paymentData));
// Notifies the client that the payment has been completed
_hubConnection.On("CheckoutCompleted", () =>
OnCheckoutCompleted?.Invoke());
// Notifies the cashier that a new checkout has been requested
_hubConnection.On<int, int, string>("NewCheckout", (tableId, tableNumber, zoneName) =>
OnNewCheckout?.Invoke(tableId, tableNumber, zoneName));
}
public async Task StartAsync()
{
await _hubConnection.StartAsync();
}
public async Task StopAsync()
{
await _hubConnection.StopAsync();
}
public async Task NotifyCheckoutRequestedAsync(int tableId)
{
await _hubConnection.InvokeAsync("InitiateCheckout", tableId);
}
public async Task NotifyCheckoutCompletedAsync(int tableId)
{
await _hubConnection.InvokeAsync("CompleteCheckout", tableId);
}
}
```
#### Demo
Please check this [Pull Request](https://github.com/tien4112004/bistro-q/pull/26) to see how it behave in actual use cases. We have a video on PR detail.
### VietQR
The application integrates the [VietQR API by Casso](https://www.vietqr.io/danh-sach-api/link-tao-ma-nhanh/api-tao-ma-qr/) to generate QR codes for banking payments during checkout. This allows seamless payment processing using bank QR codes.
## Unit test
We have implement some tests in backend. We decided to mock the backend services and test routes in controllers.
To run the test, please use the Test runner/Test explorer in IDE like Visual Studio or Jetbrains Rider.
## Git Flow Evidence
#### WinUI project



#### ASP .NET project

## Code Review Evidence
:::success
These PRs are sorted in ascending chronological order.
:::
:::info
### PR Admin Account API
:::


:::info
### PR Admin Account WinUI
:::


:::info
### PR Nutrition Fact CRUD API
:::




:::info
### PR Nutrition Fact Admin Interface WinUI
:::




:::info
### PR Refactor Version 2 WinUI
:::







:::info
### PR Product Recommendation API
:::






:::info
### PR Nutrition Fact Client Interface WinUI
:::







:::info
### PR Checkout API
:::


:::info
### PR Checkout WinUI
:::





:::info
### PR Recommendation Products WinUI
:::



:::info
### PR Documentation
:::

