Compare commits
33 Commits
51f70df63b
...
invoice-co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4782bd3a89 | ||
|
|
81f6d83fd0 | ||
|
|
f31176cfc9 | ||
|
|
437d6d8f42 | ||
| 2b7ed3e451 | |||
| a631cd6b3e | |||
| cef0f73dbb | |||
|
|
9e15afc1c2 | ||
|
|
36dc42239a | ||
|
|
decc72c554 | ||
|
|
e086a919c3 | ||
|
|
da43860c61 | ||
|
|
5441e280e0 | ||
|
|
8fd8a79d75 | ||
|
|
04174fff3b | ||
|
|
27433d1bd5 | ||
|
|
bc3a76b82b | ||
|
|
41c18590d8 | ||
|
|
1be0866c69 | ||
|
|
730eb6c3b7 | ||
|
|
140ece8080 | ||
|
|
b24aaab679 | ||
|
|
de5b8fbe16 | ||
|
|
6d2c46d971 | ||
|
|
b4edaf007e | ||
|
|
569245c296 | ||
|
|
14c61ca1ee | ||
|
|
b673fd2da3 | ||
|
|
2a42f16daf | ||
|
|
518eff0ec7 | ||
|
|
eb4b2efbff | ||
|
|
1e823ab4d3 | ||
|
|
bbea0741a3 |
4
.git-crypt/.gitattributes
vendored
@@ -1,4 +0,0 @@
|
|||||||
# Do not edit this file. To specify the files to encrypt, create your own
|
|
||||||
# .gitattributes file in the directory where your files are.
|
|
||||||
* !filter !diff
|
|
||||||
*.gpg binary
|
|
||||||
2
.gitattributes
vendored
@@ -1,2 +0,0 @@
|
|||||||
Bimix.API/appsettings.Development.json filter=git-crypt diff=git-crypt
|
|
||||||
Bimix.UI.Web/appsettings.Development.json filter=git-crypt diff=git-crypt
|
|
||||||
72
.gitea/scripts/replaceTokens.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
// .gitea/scripts/replaceTokens.js
|
||||||
|
// Skanuje:
|
||||||
|
// - artifacts/api/appsettings.Production.json (jeśli jest)
|
||||||
|
// - artifacts/ui/appsettings.Production.json (jeśli jest)
|
||||||
|
// Tokeny: #{NAME}# -> wartość z VARIABLES/SECRETS (NAME: uppercased, '-'->'_')
|
||||||
|
// Dodatkowo: #{BUILDID}# -> RUN_ID (z ENV)
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function replaceInFile(file, mapToken) {
|
||||||
|
let data = fs.readFileSync(file, 'utf8');
|
||||||
|
const re = /#\{(.*?)\}#/g;
|
||||||
|
let changed = false;
|
||||||
|
data = data.replace(re, (_, raw) => {
|
||||||
|
const token = (raw || '').replace(/-/g, '_').toUpperCase();
|
||||||
|
const val = mapToken(token);
|
||||||
|
if (val == null || val === '') return `#{${raw}}#`; // zostaw bez zmian, podbijemy błąd później
|
||||||
|
changed = true;
|
||||||
|
return String(val);
|
||||||
|
});
|
||||||
|
fs.writeFileSync(file, data, 'utf8');
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const secrets = JSON.parse(process.env.SECRETS || '{}');
|
||||||
|
const variables = JSON.parse(process.env.VARIABLES || '{}');
|
||||||
|
const RUN_ID = process.env.RUN_ID || process.env.GITHUB_RUN_ID || '';
|
||||||
|
|
||||||
|
const mapToken = (token) => {
|
||||||
|
if (token === 'BUILDID') return RUN_ID;
|
||||||
|
return (variables[token] != null ? variables[token] : secrets[token]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const beRoot = path.resolve('artifacts');
|
||||||
|
const beFiles = [];
|
||||||
|
['api/appsettings.Production.json', 'ui/appsettings.Production.json'].forEach((name) => {
|
||||||
|
const p = path.join(beRoot, name);
|
||||||
|
if (fs.existsSync(p)) beFiles.push(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
const files = beFiles;
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
console.error('❌ No candidate files found to tokenize (artifacts/api or artifacts/ui appsettings.Production.json).');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`🔎 Tokenizing ${files.length} file(s)`);
|
||||||
|
const missing = new Set();
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
replaceInFile(file, mapToken);
|
||||||
|
}
|
||||||
|
for (const file of files) {
|
||||||
|
const content = fs.readFileSync(file, 'utf8');
|
||||||
|
const reLeft = /#\{(.*?)\}#/g;
|
||||||
|
let m;
|
||||||
|
while ((m = reLeft.exec(content))) {
|
||||||
|
const token = (m[1] || '').replace(/-/g, '_').toUpperCase();
|
||||||
|
missing.add(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missing.size > 0) {
|
||||||
|
console.error(`❌ Missing values for tokens: ${Array.from(missing).join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Tokenization complete.');
|
||||||
|
})();
|
||||||
65
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
name: Build Docker Images
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: build-${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: https://github.com/docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Gitea Container Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login code.bim-it.pl -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push API image
|
||||||
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/amd64 \
|
||||||
|
--label "org.opencontainers.image.source=https://code.bim-it.pl/mz/BimAI" \
|
||||||
|
-f BimAI.API/Dockerfile \
|
||||||
|
-t code.bim-it.pl/mz/bimai-api:latest \
|
||||||
|
-t code.bim-it.pl/mz/bimai-api:build-${{ github.run_id }} \
|
||||||
|
--push \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Build and push UI image
|
||||||
|
run: |
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/amd64 \
|
||||||
|
--label "org.opencontainers.image.source=https://code.bim-it.pl/mz/BimAI" \
|
||||||
|
-f BimAI.UI.Web/Dockerfile \
|
||||||
|
-t code.bim-it.pl/mz/bimai-ui:latest \
|
||||||
|
-t code.bim-it.pl/mz/bimai-ui:build-${{ github.run_id }} \
|
||||||
|
--push \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Output build info
|
||||||
|
run: |
|
||||||
|
echo "## ️ Docker Images Built" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "**Build ID:** ${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "### Images pushed:" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```bash' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "# Latest (for release)" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-api:latest" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-ui:latest" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "# Specific build (for rollback)" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-api:build-${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-ui:build-${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||||
116
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
name: Release Docker Images
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: https://github.com/actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
|
- name: Log in to Gitea Container Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login code.bim-it.pl -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
|
|
||||||
|
- name: Pull latest build artifacts (images)
|
||||||
|
run: |
|
||||||
|
echo "Pulling latest build images..."
|
||||||
|
docker pull code.bim-it.pl/mz/bimai-api:latest
|
||||||
|
docker pull code.bim-it.pl/mz/bimai-ui:latest
|
||||||
|
|
||||||
|
- name: Extract appsettings from images
|
||||||
|
run: |
|
||||||
|
mkdir -p artifacts/api artifacts/ui
|
||||||
|
|
||||||
|
# Extract from API image
|
||||||
|
docker create --name temp-api code.bim-it.pl/mz/bimai-api:latest
|
||||||
|
docker cp temp-api:/app/appsettings.Production.json artifacts/api/
|
||||||
|
docker rm temp-api
|
||||||
|
|
||||||
|
# Extract from UI image
|
||||||
|
docker create --name temp-ui code.bim-it.pl/mz/bimai-ui:latest
|
||||||
|
docker cp temp-ui:/app/appsettings.Production.json artifacts/ui/
|
||||||
|
docker rm temp-ui
|
||||||
|
|
||||||
|
- name: Show extracted configs (before tokenization)
|
||||||
|
run: |
|
||||||
|
echo "::group::API appsettings.Production.json (with placeholders)"
|
||||||
|
cat artifacts/api/appsettings.Production.json
|
||||||
|
echo "::endgroup::"
|
||||||
|
echo "::group::UI appsettings.Production.json (with placeholders)"
|
||||||
|
cat artifacts/ui/appsettings.Production.json
|
||||||
|
echo "::endgroup::"
|
||||||
|
|
||||||
|
- name: Tokenize appsettings
|
||||||
|
env:
|
||||||
|
SECRETS: ${{ toJson(secrets) }}
|
||||||
|
VARIABLES: ${{ toJson(vars) }}
|
||||||
|
RUN_ID: ${{ github.run_id }}
|
||||||
|
run: |
|
||||||
|
node .gitea/scripts/replaceTokens.js
|
||||||
|
|
||||||
|
- name: Show tokenized configs (after tokenization)
|
||||||
|
run: |
|
||||||
|
echo "::group::API appsettings.Production.json (tokenized, passwords hidden)"
|
||||||
|
cat artifacts/api/appsettings.Production.json | sed 's/Password=[^;]*/Password=***/g' | sed 's/"SecretKey":"[^"]*"/"SecretKey":"***"/g'
|
||||||
|
echo "::endgroup::"
|
||||||
|
echo "::group::UI appsettings.Production.json (tokenized)"
|
||||||
|
cat artifacts/ui/appsettings.Production.json
|
||||||
|
echo "::endgroup::"
|
||||||
|
|
||||||
|
- name: Rebuild images with tokenized configs
|
||||||
|
run: |
|
||||||
|
# API
|
||||||
|
cat > Dockerfile.release.api <<'EOF'
|
||||||
|
FROM code.bim-it.pl/mz/bimai-api:latest
|
||||||
|
LABEL org.opencontainers.image.source=https://code.bim-it.pl/mz/BimAI
|
||||||
|
COPY artifacts/api/appsettings.Production.json /app/
|
||||||
|
EOF
|
||||||
|
docker build -f Dockerfile.release.api \
|
||||||
|
-t code.bim-it.pl/mz/bimai-api:prod \
|
||||||
|
-t code.bim-it.pl/mz/bimai-api:release-${{ github.run_id }} \
|
||||||
|
.
|
||||||
|
|
||||||
|
# UI
|
||||||
|
cat > Dockerfile.release.ui <<'EOF'
|
||||||
|
FROM code.bim-it.pl/mz/bimai-ui:latest
|
||||||
|
LABEL org.opencontainers.image.source=https://code.bim-it.pl/mz/BimAI
|
||||||
|
COPY artifacts/ui/appsettings.Production.json /app/
|
||||||
|
EOF
|
||||||
|
docker build -f Dockerfile.release.ui \
|
||||||
|
-t code.bim-it.pl/mz/bimai-ui:prod \
|
||||||
|
-t code.bim-it.pl/mz/bimai-ui:release-${{ github.run_id }} \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Push final images
|
||||||
|
run: |
|
||||||
|
docker push code.bim-it.pl/mz/bimai-api:prod
|
||||||
|
docker push code.bim-it.pl/mz/bimai-api:release-${{ github.run_id }}
|
||||||
|
docker push code.bim-it.pl/mz/bimai-ui:prod
|
||||||
|
docker push code.bim-it.pl/mz/bimai-ui:release-${{ github.run_id }}
|
||||||
|
|
||||||
|
- name: Output release info
|
||||||
|
run: |
|
||||||
|
echo "## Docker Images Released" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "**Release ID:** ${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "### 🚀 Production images ready to deploy:" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```bash' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "# Production (latest release)" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-api:prod" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-ui:prod" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "# Specific release (for rollback)" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-api:release-${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull code.bim-it.pl/mz/bimai-ui:release-${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||||
47
.github/workflows/build
vendored
@@ -1,47 +0,0 @@
|
|||||||
name: Build Bimix
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build WebAPI and WebUI
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
env:
|
|
||||||
DOTNET_VERSION: '8.0.x'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup .NET
|
|
||||||
uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
|
||||||
|
|
||||||
- name: Restore dependencies
|
|
||||||
run: dotnet restore
|
|
||||||
|
|
||||||
- name: Build solution
|
|
||||||
run: dotnet build --configuration Release --no-restore
|
|
||||||
|
|
||||||
- name: Publish WebAPI
|
|
||||||
run: |
|
|
||||||
dotnet publish Bimix.API/Bimix.API.csproj \
|
|
||||||
--configuration Release \
|
|
||||||
--output ./publish/Bimix-WebAPI
|
|
||||||
|
|
||||||
- name: Publish Web (Blazor Server)
|
|
||||||
run: |
|
|
||||||
dotnet publish Bimix.UI.Web/Bimix.UI.Web.csproj \
|
|
||||||
--configuration Release \
|
|
||||||
--output ./publish/Bimix-Web
|
|
||||||
|
|
||||||
- name: Upload publish artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: bimix-artifacts
|
|
||||||
path: ./publish
|
|
||||||
9
.gitignore
vendored
@@ -24,10 +24,6 @@ Generated/
|
|||||||
*.db-shm
|
*.db-shm
|
||||||
*.db-wal
|
*.db-wal
|
||||||
|
|
||||||
# Visual Studio Code
|
|
||||||
.vscode/
|
|
||||||
.vscode/*
|
|
||||||
|
|
||||||
# MAUI / Mobile (Xcode/iOS)
|
# MAUI / Mobile (Xcode/iOS)
|
||||||
**/bin/
|
**/bin/
|
||||||
**/obj/
|
**/obj/
|
||||||
@@ -86,3 +82,8 @@ nunit-*.xml
|
|||||||
.idea/indexLayout.xml
|
.idea/indexLayout.xml
|
||||||
.idea/tasks.xml
|
.idea/tasks.xml
|
||||||
.idea/.idea_modules
|
.idea/.idea_modules
|
||||||
|
|
||||||
|
# VSCode - ignore personal settings but keep shared configs
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/tasks.json
|
||||||
47
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "API",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build-api",
|
||||||
|
"program": "${workspaceFolder}/BimAI.API/bin/Debug/net10.0/BimAI.API.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/BimAI.API",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"env": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Web",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build-web",
|
||||||
|
"program": "${workspaceFolder}/BimAI.UI.Web/bin/Debug/net10.0/BimAI.UI.Web.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/BimAI.UI.Web",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"serverReadyAction": {
|
||||||
|
"action": "openExternally",
|
||||||
|
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
|
||||||
|
"uriFormat": "%s"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"launchBrowser": {
|
||||||
|
"enabled": true,
|
||||||
|
"args": "${auto-detect-url}",
|
||||||
|
"browser": [
|
||||||
|
{
|
||||||
|
"osx": "Google Chrome",
|
||||||
|
"linux": "chrome",
|
||||||
|
"windows": "chrome"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
77
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build-api",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/BimAI.API/BimAI.API.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "build-web",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/BimAI.UI.Web/BimAI.UI.Web.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish-api",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/BimAI.API/BimAI.API.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish-web",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/BimAI.UI.Web/BimAI.UI.Web.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch-api",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"--project",
|
||||||
|
"${workspaceFolder}/BimAI.API/BimAI.API.csproj"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch-web",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"--project",
|
||||||
|
"${workspaceFolder}/BimAI.UI.Web/BimAI.UI.Web.csproj"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
27
BimAI.API/BimAI.API.csproj
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Google.Apis.Auth" Version="1.70.0" />
|
||||||
|
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.21" />
|
||||||
|
<PackageReference Include="Hangfire.Core" Version="1.8.21" />
|
||||||
|
<PackageReference Include="Hangfire.SqlServer" Version="1.8.21" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0-rc.1.25451.107">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-rc.1.25451.107" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BimAI.Application\BimAI.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\BimAI.Infrastructure\BimAI.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
6
BimAI.API/BimAI.API.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@BimAI.API_HostAddress = http://localhost:5090
|
||||||
|
|
||||||
|
GET {{BimAI.API_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
96
BimAI.API/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using BimAI.API.Services;
|
||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BimAI.API.Controllers;
|
||||||
|
|
||||||
|
public class AuthController(
|
||||||
|
GoogleAuthService googleAuthService,
|
||||||
|
JwtTokenService jwtTokenService,
|
||||||
|
ILogger<AuthController> logger)
|
||||||
|
: ControllerBase
|
||||||
|
{
|
||||||
|
[HttpPost("google")]
|
||||||
|
public async Task<IActionResult> GoogleAuth([FromBody] GoogleAuthRequest request)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(request.IdToken))
|
||||||
|
{
|
||||||
|
return BadRequest(new GoogleAuthResponse
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Error = "IdToken is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var (isValid, user, error) = await googleAuthService.ValidateGoogleTokenAsync(request.IdToken);
|
||||||
|
|
||||||
|
if (!isValid || user == null)
|
||||||
|
{
|
||||||
|
var statusCode = error switch
|
||||||
|
{
|
||||||
|
"User not authorized to access this application" => 403,
|
||||||
|
"User account is not active" => 403,
|
||||||
|
"Invalid Google token" => 401,
|
||||||
|
_ => 401
|
||||||
|
};
|
||||||
|
|
||||||
|
return StatusCode(statusCode, new GoogleAuthResponse
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Error = error ?? "Authentication failed"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var jwt = jwtTokenService.GenerateToken(user);
|
||||||
|
|
||||||
|
return Ok(new GoogleAuthResponse
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Token = jwt,
|
||||||
|
User = new UserDto
|
||||||
|
{
|
||||||
|
Id = user.Id,
|
||||||
|
Email = user.Email,
|
||||||
|
FullName = user.FullName,
|
||||||
|
IsActive = user.IsActive,
|
||||||
|
LastLoginAt = user.LastLoginAt
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "Error during Google authentication");
|
||||||
|
return StatusCode(500, new GoogleAuthResponse
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Error = "Internal server error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("me")]
|
||||||
|
[Authorize]
|
||||||
|
public IActionResult GetCurrentUser()
|
||||||
|
{
|
||||||
|
var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier);
|
||||||
|
var emailClaim = User.FindFirst(ClaimTypes.Email);
|
||||||
|
var nameClaim = User.FindFirst(ClaimTypes.Name);
|
||||||
|
|
||||||
|
if (userIdClaim == null || emailClaim == null || nameClaim == null)
|
||||||
|
{
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new UserDto
|
||||||
|
{
|
||||||
|
Id = Guid.Parse(userIdClaim.Value),
|
||||||
|
Email = emailClaim.Value,
|
||||||
|
FullName = nameClaim.Value,
|
||||||
|
IsActive = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
108
BimAI.API/Controllers/InvoiceController.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace BimAI.API.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class InvoiceController(BimAIDbContext context) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly BimAIDbContext _context = context;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<PagedResult<InvoiceDto>>> GetInvoices([FromQuery] InvoiceFilterRequest request)
|
||||||
|
{
|
||||||
|
var query = _context.Invoices.AsQueryable();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Search))
|
||||||
|
{
|
||||||
|
var searchTerm = request.Search.ToLower();
|
||||||
|
query = query.Where(x =>
|
||||||
|
x.DocumentNo.ToLower().Contains(searchTerm) ||
|
||||||
|
x.ClientName.ToLower().Contains(searchTerm)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.DocumentNo))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.DocumentNo.ToLower().Contains(request.DocumentNo.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.ClientName))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.ClientName.ToLower().Contains(request.ClientName.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Type))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Type.ToLower().Contains(request.Type.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Source))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Source.ToLower().Contains(request.Source.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.RegisterDateFrom.HasValue)
|
||||||
|
{
|
||||||
|
var from = request.RegisterDateFrom.Value.Date;
|
||||||
|
query = query.Where(x => x.RegisterDate >= from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.RegisterDateTo.HasValue)
|
||||||
|
{
|
||||||
|
var toExclusive = request.RegisterDateTo.Value.Date.AddDays(1);
|
||||||
|
query = query.Where(x => x.RegisterDate < toExclusive);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.SellDateFrom.HasValue)
|
||||||
|
{
|
||||||
|
var from = request.SellDateFrom.Value.Date;
|
||||||
|
query = query.Where(x => x.SellDate >= from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.SellDateTo.HasValue)
|
||||||
|
{
|
||||||
|
var toExclusive = request.SellDateTo.Value.Date.AddDays(1);
|
||||||
|
query = query.Where(x => x.SellDate < toExclusive);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
var items = await query
|
||||||
|
.OrderByDescending(x => x.RegisterDate)
|
||||||
|
.Skip((request.Page - 1) * request.PageSize)
|
||||||
|
.Take(request.PageSize)
|
||||||
|
.Select(x => new InvoiceDto
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
DocumentNo = x.DocumentNo,
|
||||||
|
Type = x.Type,
|
||||||
|
RegisterDate = x.RegisterDate,
|
||||||
|
SellDate = x.SellDate,
|
||||||
|
ClientName = x.ClientName,
|
||||||
|
ClientId = x.ClientId,
|
||||||
|
ClientNip = x.ClientNip,
|
||||||
|
ClientAddress = x.ClientAddress,
|
||||||
|
Currency = x.Currency,
|
||||||
|
TotalNetto = x.TotalNetto,
|
||||||
|
TotalBrutto = x.TotalBrutto,
|
||||||
|
TotalVat = x.TotalVat,
|
||||||
|
Source = x.Source,
|
||||||
|
CreatedAt = x.CreatedAt,
|
||||||
|
UpdatedAt = x.UpdatedAt
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Ok(new PagedResult<InvoiceDto>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
Page = request.Page,
|
||||||
|
PageSize = request.PageSize,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
71
BimAI.API/Controllers/ProductsController.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace BimAI.API.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class ProductsController(BimAIDbContext context) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly BimAIDbContext _context = context;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<IEnumerable<ProductDto>>> GetProducts([FromQuery] ProductFilterRequest request)
|
||||||
|
{
|
||||||
|
var query = _context.Products.AsQueryable();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Search))
|
||||||
|
{
|
||||||
|
var searchTerm = request.Search.ToLower();
|
||||||
|
query = query.Where(x =>
|
||||||
|
x.Name.ToLower().Contains(searchTerm) ||
|
||||||
|
(x.Code != null && x.Code.ToLower().Contains(searchTerm)) ||
|
||||||
|
(x.Ean != null && x.Ean.ToLower().Contains(searchTerm))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Name))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Name.ToLower().Contains(request.Name.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Code))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Code != null && x.Code.ToLower().Contains(request.Code.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Ean))
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.Ean != null && x.Ean.ToLower().Contains(request.Ean.ToLower()));
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
var items = await query
|
||||||
|
.OrderBy(x => x.Name)
|
||||||
|
.Skip((request.Page -1) * request.PageSize)
|
||||||
|
.Take(request.PageSize)
|
||||||
|
.Select(x => new ProductDto
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Name = x.Name,
|
||||||
|
Code = x.Code ?? string.Empty,
|
||||||
|
Ean = x.Ean ?? string.Empty,
|
||||||
|
StockAddresses = x.StockAddresses ?? string.Empty,
|
||||||
|
CreatedAt = x.CreatedAt,
|
||||||
|
UpdatedAt = x.UpdatedAt
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Ok(new PagedResult<ProductDto>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
Page = request.Page,
|
||||||
|
PageSize = request.PageSize,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
25
BimAI.API/Controllers/SyncController.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using BimAI.Infrastructure.Sync;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace BimAI.API.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class SyncController(
|
||||||
|
ProductSyncService productSyncService,
|
||||||
|
InvoiceSyncService invoiceSyncService) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpPost("run-product-sync")]
|
||||||
|
public async Task<IActionResult> RunProductSync()
|
||||||
|
{
|
||||||
|
await productSyncService.RunAsync();
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("run-invoice-sync")]
|
||||||
|
public async Task<IActionResult> RunInvoiceSync()
|
||||||
|
{
|
||||||
|
await invoiceSyncService.RunAsync();
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
48
BimAI.API/Dockerfile
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Stage 1: Build
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# Copy solution and all project files for restore
|
||||||
|
COPY BimAI.sln ./
|
||||||
|
COPY BimAI.API/BimAI.API.csproj BimAI.API/
|
||||||
|
COPY BimAI.Domain/BimAI.Domain.csproj BimAI.Domain/
|
||||||
|
COPY BimAI.Application/BimAI.Application.csproj BimAI.Application/
|
||||||
|
COPY BimAI.Infrastructure/BimAI.Infrastructure.csproj BimAI.Infrastructure/
|
||||||
|
|
||||||
|
# Restore dependencies
|
||||||
|
RUN dotnet restore BimAI.API/BimAI.API.csproj
|
||||||
|
|
||||||
|
# Copy all source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build and publish
|
||||||
|
WORKDIR /src/BimAI.API
|
||||||
|
RUN dotnet publish -c Release -o /app/publish --no-restore
|
||||||
|
|
||||||
|
# Stage 2: Runtime
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install wget for health checks
|
||||||
|
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Set timezone
|
||||||
|
ENV TZ=Europe/Warsaw
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
|
# Copy published files
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
ENV ASPNETCORE_URLS=http://0.0.0.0:7142
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 7142
|
||||||
|
|
||||||
|
# Health check
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||||
|
CMD wget --no-verbose --tries=1 --spider http://localhost:7142/health || exit 1
|
||||||
|
|
||||||
|
# Run the application
|
||||||
|
ENTRYPOINT ["dotnet", "BimAI.API.dll"]
|
||||||
151
BimAI.API/Program.cs
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
using System.Text;
|
||||||
|
using BimAI.API.Services;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using BimAI.Infrastructure.Jobs;
|
||||||
|
using BimAI.Infrastructure.Sync;
|
||||||
|
using Hangfire;
|
||||||
|
using Hangfire.SqlServer;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
builder.Services.AddDbContext<BimAIDbContext>(options => options.UseSqlServer(connectionString));
|
||||||
|
builder.Services.AddScoped<ProductSyncService>();
|
||||||
|
builder.Services.AddScoped<InvoiceSyncService>();
|
||||||
|
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
// Start Hangfire section
|
||||||
|
builder.Services.AddHangfire(configuration => configuration
|
||||||
|
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
|
||||||
|
.UseSimpleAssemblyNameTypeSerializer()
|
||||||
|
.UseRecommendedSerializerSettings()
|
||||||
|
.UseSqlServerStorage(builder.Configuration.GetConnectionString("HangfireConnection"),
|
||||||
|
new SqlServerStorageOptions
|
||||||
|
{
|
||||||
|
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||||
|
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||||
|
QueuePollInterval = TimeSpan.Zero,
|
||||||
|
UseRecommendedIsolationLevel = true,
|
||||||
|
DisableGlobalLocks = true,
|
||||||
|
SchemaName = "Hangfire"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
builder.Services.AddHangfireServer(options =>
|
||||||
|
{
|
||||||
|
options.ServerName = builder.Configuration["Hangfire:ServerName"];
|
||||||
|
options.WorkerCount = builder.Configuration.GetValue<int>("Hangfire:WorkerCount", 5);
|
||||||
|
});
|
||||||
|
// End Hangfire section
|
||||||
|
// Start auth section
|
||||||
|
var jwtSettings = builder.Configuration.GetSection("JwtSettings");
|
||||||
|
var secretKey = jwtSettings["SecretKey"];
|
||||||
|
var issuer = jwtSettings["Issuer"];
|
||||||
|
var audience = jwtSettings["Audience"];
|
||||||
|
|
||||||
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = issuer,
|
||||||
|
ValidAudience = audience,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey)),
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
builder.Services.AddAuthentication();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<GoogleAuthService>();
|
||||||
|
builder.Services.AddScoped<JwtTokenService>();
|
||||||
|
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowAll", policy =>
|
||||||
|
{
|
||||||
|
policy.AllowAnyOrigin()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// End auth section
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Auto-apply migrations on startup
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<BimAIDbContext>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var pending = await db.Database.GetPendingMigrationsAsync();
|
||||||
|
if (pending.Any())
|
||||||
|
{
|
||||||
|
app.Logger.LogWarning("Applying {Count} pending migrations: {List}",
|
||||||
|
pending.Count(), string.Join(", ", pending));
|
||||||
|
await db.Database.MigrateAsync();
|
||||||
|
app.Logger.LogInformation("Migrations applied successfully.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.Logger.LogInformation("No pending migrations.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
app.Logger.LogCritical(ex, "Migration failed - application will not start.");
|
||||||
|
throw; // stop startup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseCors("AllowAll");
|
||||||
|
app.UseHangfireDashboard(builder.Configuration["Hangfire:DashboardPath"] ?? "/hangfire", new DashboardOptions
|
||||||
|
{
|
||||||
|
AsyncAuthorization = new[] { new HangfireAuthorizationFilter() },
|
||||||
|
DashboardTitle = "BimAI - Job Dashboard"
|
||||||
|
});
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.MapGet("/health", () => Results.Ok(new { status = "OK", timestamp = DateTime.UtcNow }))
|
||||||
|
.AllowAnonymous();
|
||||||
|
|
||||||
|
RecurringJob.AddOrUpdate<ProductSyncJob>(
|
||||||
|
"product-sync",
|
||||||
|
job => job.ExecuteAsync(),
|
||||||
|
Cron.Daily(2, 0), // Every day at 2:00 AM
|
||||||
|
new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = TimeZoneInfo.Local,
|
||||||
|
MisfireHandling = app.Environment.IsDevelopment()
|
||||||
|
? MisfireHandlingMode.Relaxed
|
||||||
|
: MisfireHandlingMode.Strict
|
||||||
|
});
|
||||||
|
|
||||||
|
RecurringJob.AddOrUpdate<InvoiceSyncJob>(
|
||||||
|
"invoice-sync",
|
||||||
|
job => job.ExecuteAsync(),
|
||||||
|
Cron.Daily(2, 30), // Every day at 2:30 AM
|
||||||
|
new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = TimeZoneInfo.Local,
|
||||||
|
MisfireHandling = app.Environment.IsDevelopment()
|
||||||
|
? MisfireHandlingMode.Relaxed
|
||||||
|
: MisfireHandlingMode.Strict
|
||||||
|
});
|
||||||
|
|
||||||
|
app.Run();
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
"applicationUrl": "https://localhost:7142;http://localhost:5142",
|
"applicationUrl": "http://localhost:7142;http://0.0.0.0:7142",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
72
BimAI.API/Services/GoogleAuthService.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using BimAI.Domain.Entities;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Google.Apis.Auth;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace BimAI.API.Services;
|
||||||
|
|
||||||
|
public class GoogleAuthService(BimAIDbContext context, IConfiguration configuration, ILogger<GoogleAuthService> logger)
|
||||||
|
{
|
||||||
|
private readonly BimAIDbContext _context = context;
|
||||||
|
private readonly IConfiguration _configuration = configuration;
|
||||||
|
private readonly ILogger<GoogleAuthService> _logger = logger;
|
||||||
|
|
||||||
|
public async Task<(bool IsValid, User? user, string? error)> ValidateGoogleTokenAsync(string idToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var clientId = _configuration["GoogleAuth:ClientId"];
|
||||||
|
if (string.IsNullOrEmpty(clientId))
|
||||||
|
{
|
||||||
|
_logger.LogError("Google Auth Client Id is not configured");
|
||||||
|
return (false, null, "Google Auth Client Id is not configured");
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = await GoogleJsonWebSignature.ValidateAsync(idToken,
|
||||||
|
new GoogleJsonWebSignature.ValidationSettings
|
||||||
|
{
|
||||||
|
Audience = new[] { clientId }
|
||||||
|
});
|
||||||
|
|
||||||
|
_logger.LogInformation("Google token validated for user: {Email}", payload.Email);
|
||||||
|
|
||||||
|
var user = await _context.Users
|
||||||
|
.FirstOrDefaultAsync(x => x.GoogleId == payload.Subject || x.Email == payload.Email);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("User not found in BimAI database: {Email}", payload.Email);
|
||||||
|
return (false, null, "User not found in BimAI database");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.IsActive)
|
||||||
|
{
|
||||||
|
_logger.LogError("User is not active: {Email}", payload.Email);
|
||||||
|
return (false, null, "User is not active");
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastLoginAt = DateTime.UtcNow;
|
||||||
|
user.FullName = payload.Name;
|
||||||
|
|
||||||
|
if (user.GoogleId != payload.Subject)
|
||||||
|
{
|
||||||
|
user.GoogleId = payload.Subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("User logged in: {Email}", payload.Email);
|
||||||
|
|
||||||
|
return (true, user, null);
|
||||||
|
}
|
||||||
|
catch (InvalidJwtException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Invalid JWT token");
|
||||||
|
return (false, null, "Invalid JWT token");
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error validating Google token");
|
||||||
|
return (false, null, "Error validating Google token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
BimAI.API/Services/HangfireAuthorizationFilter.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Hangfire.Dashboard;
|
||||||
|
|
||||||
|
namespace BimAI.API.Services;
|
||||||
|
|
||||||
|
public class HangfireAuthorizationFilter: IDashboardAsyncAuthorizationFilter
|
||||||
|
{
|
||||||
|
public Task<bool> AuthorizeAsync(DashboardContext context)
|
||||||
|
{
|
||||||
|
var httpContext = context.GetHttpContext();
|
||||||
|
|
||||||
|
var env = httpContext.RequestServices.GetService<IWebHostEnvironment>();
|
||||||
|
if (env != null && env.IsDevelopment())
|
||||||
|
{
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var isAuthenticated = httpContext.User.Identity?.IsAuthenticated ?? false;
|
||||||
|
return Task.FromResult(isAuthenticated);
|
||||||
|
}
|
||||||
|
}
|
||||||
86
BimAI.API/Services/JwtTokenService.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text;
|
||||||
|
using BimAI.Domain.Entities;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
namespace BimAI.API.Services;
|
||||||
|
|
||||||
|
public class JwtTokenService(IConfiguration configuration, ILogger<JwtTokenService> logger)
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration = configuration;
|
||||||
|
private readonly ILogger<JwtTokenService> _logger = logger;
|
||||||
|
|
||||||
|
public string GenerateToken(User user)
|
||||||
|
{
|
||||||
|
var jwtSettings = _configuration.GetSection("JwtSettings");
|
||||||
|
var securityKey = jwtSettings["SecurityKey"];
|
||||||
|
var issuer = jwtSettings["Issuer"];
|
||||||
|
var audience = jwtSettings["Audience"];
|
||||||
|
var expiryDays = int.Parse(jwtSettings["ExpiryDays"] ?? "7");
|
||||||
|
|
||||||
|
var claims = new[]
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim(ClaimTypes.Name, user.FullName),
|
||||||
|
new Claim("google_id", user.GoogleId),
|
||||||
|
new Claim("is_active", user.IsActive.ToString()),
|
||||||
|
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||||
|
new Claim(JwtRegisteredClaimNames.Iat, new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds().ToString(),
|
||||||
|
ClaimValueTypes.Integer64)
|
||||||
|
};
|
||||||
|
|
||||||
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey));
|
||||||
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||||
|
|
||||||
|
var token = new JwtSecurityToken(
|
||||||
|
issuer: issuer,
|
||||||
|
audience: audience,
|
||||||
|
claims: claims,
|
||||||
|
expires: DateTime.UtcNow.AddDays(expiryDays),
|
||||||
|
signingCredentials: creds
|
||||||
|
);
|
||||||
|
|
||||||
|
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
|
||||||
|
|
||||||
|
_logger.LogInformation("Generated JWT token for user: {Email}", user.Email);
|
||||||
|
|
||||||
|
return tokenString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClaimsPrincipal? ValidateToken(string token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jwtSettings = _configuration.GetSection("JwtSettings");
|
||||||
|
var secretKey = jwtSettings["SecretKey"];
|
||||||
|
var issuer = jwtSettings["Issuer"];
|
||||||
|
var audience = jwtSettings["Audience"];
|
||||||
|
|
||||||
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
var key = Encoding.UTF8.GetBytes(secretKey);
|
||||||
|
|
||||||
|
var validationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = issuer,
|
||||||
|
ValidAudience = audience,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||||
|
ClockSkew = TimeSpan.Zero
|
||||||
|
};
|
||||||
|
|
||||||
|
var principal = tokenHandler.ValidateToken(token, validationParameters, out _);
|
||||||
|
return principal;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error validating JWT token");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
21
BimAI.API/appsettings.Development.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=localhost,1433;Database=bimai;User Id=sa;Password=BimAI_SA_2025x@;TrustServerCertificate=True;Encrypt=False",
|
||||||
|
"HangfireConnection": "Server=localhost,1433;Database=bimai;User Id=sa;Password=BimAI_SA_2025x@;TrustServerCertificate=True;Encrypt=False"
|
||||||
|
},
|
||||||
|
"E5_CRM": {
|
||||||
|
"ApiKey": "7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5"
|
||||||
|
},
|
||||||
|
"TWINPOL_CRM": {
|
||||||
|
"ApiKey": "d68dac4c-f784-4e1b-8267-9ffcfa0eda4c"
|
||||||
|
},
|
||||||
|
"GoogleAuth": {
|
||||||
|
"ClientId": "896226687615-rhmqk06t1hvll1hh2gtje2u6nbadtras.apps.googleusercontent.com"
|
||||||
|
},
|
||||||
|
"JwtSettings": {
|
||||||
|
"SecretKey": "BimAISuperSecretKeyThatMustBeAtLeast32CharactersLong123456789"
|
||||||
|
},
|
||||||
|
"Hangfire": {
|
||||||
|
"ServerName": "BimAI-Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
BimAI.API/appsettings.Production.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "",
|
||||||
|
"HangfireConnection": ""
|
||||||
|
},
|
||||||
|
"E5_CRM": {
|
||||||
|
"ApiKey": ""
|
||||||
|
},
|
||||||
|
"GoogleAuth": {
|
||||||
|
"ClientId": ""
|
||||||
|
},
|
||||||
|
"JwtSettings": {
|
||||||
|
"SecretKey": ""
|
||||||
|
},
|
||||||
|
"Hangfire": {
|
||||||
|
"ServerName": "BimAI-Production"
|
||||||
|
},
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://0.0.0.0:7142"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
BimAI.API/appsettings.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"JwtSettings": {
|
||||||
|
"Issuer": "BimAI.API",
|
||||||
|
"Audience": "BimAI.Clients",
|
||||||
|
"ExpiryDays": 7
|
||||||
|
},
|
||||||
|
"Hangfire": {
|
||||||
|
"WorkerCount": 5,
|
||||||
|
"DashboardPath": "/hangfire"
|
||||||
|
},
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"Microsoft.EntityFrameworkCore": "Warning",
|
||||||
|
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
|
||||||
|
"Microsoft.EntityFrameworkCore.Infrastructure": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Bimix.Domain\Bimix.Domain.csproj" />
|
<ProjectReference Include="..\BimAI.Domain\BimAI.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
22
BimAI.Application/DTOModels/AuthDto.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace BimAI.Application.DTOModels;
|
||||||
|
|
||||||
|
public class GoogleAuthRequest
|
||||||
|
{
|
||||||
|
public string? IdToken { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GoogleAuthResponse
|
||||||
|
{
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public string? Token { get; set; }
|
||||||
|
public UserDto? User { get; set; }
|
||||||
|
public string? Error { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserDto {
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Email { get; set; } = default!;
|
||||||
|
public string FullName { get; set; } = default!;
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
public DateTime? LastLoginAt { get; set; }
|
||||||
|
}
|
||||||
12
BimAI.Application/DTOModels/Common/PagedResult.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace BimAI.Application.DTOModels.Common;
|
||||||
|
|
||||||
|
public class PagedResult<T>
|
||||||
|
{
|
||||||
|
public List<T> Items { get; set; } = new();
|
||||||
|
public int TotalCount { get; set; }
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
public int Page { get; set; }
|
||||||
|
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||||
|
public bool HasPreviousPage => Page > 1;
|
||||||
|
public bool HasNextPage => Page < TotalPages;
|
||||||
|
}
|
||||||
37
BimAI.Application/DTOModels/InvoiceDto.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
namespace BimAI.Application.DTOModels;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvoiceDto
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string DocumentNo { get; set; } = string.Empty;
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public DateTime RegisterDate { get; set; }
|
||||||
|
public DateTime SellDate { get; set; }
|
||||||
|
public string ClientName { get; set; } = string.Empty;
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
public string? ClientNip { get; set; }
|
||||||
|
public string? ClientAddress { get; set; }
|
||||||
|
public string Currency { get; set; } = string.Empty;
|
||||||
|
public decimal TotalNetto { get; set; }
|
||||||
|
public decimal TotalBrutto { get; set; }
|
||||||
|
public decimal TotalVat { get; set; }
|
||||||
|
public string Source { get; set; } = string.Empty;
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
public DateTime UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InvoiceFilterRequest
|
||||||
|
{
|
||||||
|
public string? Search { get; set; }
|
||||||
|
public string? DocumentNo { get; set; }
|
||||||
|
public string? ClientName { get; set; }
|
||||||
|
public string? Type { get; set; }
|
||||||
|
public string? Source { get; set; }
|
||||||
|
public DateTime? RegisterDateFrom { get; set; }
|
||||||
|
public DateTime? RegisterDateTo { get; set; }
|
||||||
|
public DateTime? SellDateFrom { get; set; }
|
||||||
|
public DateTime? SellDateTo { get; set; }
|
||||||
|
public int Page { get; set; } = 1;
|
||||||
|
public int PageSize { get; set; } = 20;
|
||||||
|
}
|
||||||
22
BimAI.Application/DTOModels/ProductDto.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace BimAI.Application.DTOModels;
|
||||||
|
|
||||||
|
public class ProductDto
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string Code { get; set; } = string.Empty;
|
||||||
|
public string Ean { get; set; } = string.Empty;
|
||||||
|
public string StockAddresses { get; set; } = string.Empty;
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
public DateTime UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProductFilterRequest
|
||||||
|
{
|
||||||
|
public string? Search { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Code { get; set; }
|
||||||
|
public string? Ean { get; set; }
|
||||||
|
public int Page { get; set; } = 1;
|
||||||
|
public int PageSize { get; set; } = 20;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Bimix.Domain.Entities;
|
namespace BimAI.Domain.Entities;
|
||||||
|
|
||||||
public abstract class BaseEntity
|
public abstract class BaseEntity
|
||||||
{
|
{
|
||||||
18
BimAI.Domain/Entities/Invoice.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace BimAI.Domain.Entities;
|
||||||
|
|
||||||
|
public class Invoice: BaseEntity
|
||||||
|
{
|
||||||
|
public required string DocumentNo { get; set; }
|
||||||
|
public required string Type { get; set; }
|
||||||
|
public DateTime RegisterDate { get; set; }
|
||||||
|
public DateTime SellDate { get; set; }
|
||||||
|
public required string ClientName { get; set; }
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
public string? ClientNip { get; set; }
|
||||||
|
public string? ClientAddress { get; set; }
|
||||||
|
public required string Currency { get; set; }
|
||||||
|
public decimal TotalNetto { get; set; }
|
||||||
|
public decimal TotalBrutto { get; set; }
|
||||||
|
public decimal TotalVat { get; set; }
|
||||||
|
public required string Source { get; set; }
|
||||||
|
}
|
||||||
9
BimAI.Domain/Entities/Product.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace BimAI.Domain.Entities;
|
||||||
|
|
||||||
|
public class Product : BaseEntity
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public string? Code { get; set; }
|
||||||
|
public string? Ean { get; set; }
|
||||||
|
public string? StockAddresses { get; set; }
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Bimix.Domain.Entities;
|
namespace BimAI.Domain.Entities;
|
||||||
|
|
||||||
public class SyncState
|
public class SyncState
|
||||||
{
|
{
|
||||||
public required string Entity { get; set; }
|
public required string Entity { get; init; }
|
||||||
public required long LastSynced { get; set; } // UnixTimestamp
|
public required long LastSynced { get; set; } // UnixTimestamp
|
||||||
}
|
}
|
||||||
10
BimAI.Domain/Entities/User.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace BimAI.Domain.Entities;
|
||||||
|
|
||||||
|
public class User : BaseEntity
|
||||||
|
{
|
||||||
|
public string GoogleId { get; set; } = default!;
|
||||||
|
public string Email { get; set; } = default!;
|
||||||
|
public string FullName { get; set; } = default!;
|
||||||
|
public bool IsActive { get; set; } = false;
|
||||||
|
public DateTime? LastLoginAt { get; set; }
|
||||||
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Bimix.Domain\Bimix.Domain.csproj" />
|
<ProjectReference Include="..\BimAI.Domain\BimAI.Domain.csproj" />
|
||||||
<ProjectReference Include="..\Bimix.Application\Bimix.Application.csproj" />
|
<ProjectReference Include="..\BimAI.Application\BimAI.Application.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.17" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0-rc.1.25451.107" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.17" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0-rc.1.25451.107" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.17">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0-rc.1.25451.107">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
106
BimAI.Infrastructure/Data/BimixDbContext.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using BimAI.Domain.Entities;
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Data;
|
||||||
|
|
||||||
|
public class BimAIDbContext(DbContextOptions<BimAIDbContext> options) : DbContext(options)
|
||||||
|
{
|
||||||
|
public DbSet<Product> Products { get; set; }
|
||||||
|
public DbSet<Invoice> Invoices { get; set; }
|
||||||
|
public DbSet<SyncState> SyncStates { get; set; }
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
// Product properties
|
||||||
|
modelBuilder.Entity<Product>().HasKey(x => x.Id);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.Name).IsRequired().HasMaxLength(512);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.Code).IsRequired().HasMaxLength(40);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.Ean).IsRequired().HasMaxLength(50);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.StockAddresses).IsRequired().HasMaxLength(512);
|
||||||
|
|
||||||
|
// Invoice properties
|
||||||
|
modelBuilder.Entity<Invoice>().HasKey(x => x.Id);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.DocumentNo).IsRequired().HasMaxLength(100);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.Type).IsRequired().HasMaxLength(50);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.ClientName).IsRequired().HasMaxLength(255);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.ClientId).HasMaxLength(100);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.ClientNip).HasMaxLength(50);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.ClientAddress).HasMaxLength(500);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.Currency).IsRequired().HasMaxLength(10);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.Source).IsRequired().HasMaxLength(50);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.TotalNetto).HasPrecision(18, 2);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.TotalBrutto).HasPrecision(18, 2);
|
||||||
|
modelBuilder.Entity<Invoice>().Property(x => x.TotalVat).HasPrecision(18, 2);
|
||||||
|
modelBuilder.Entity<Invoice>().HasIndex(x => new { x.DocumentNo, x.Source }).IsUnique().HasDatabaseName("IX_Invoices_DocumentNo_Source");
|
||||||
|
|
||||||
|
// SyncState properties
|
||||||
|
modelBuilder.Entity<SyncState>().HasKey((x => x.Entity));
|
||||||
|
|
||||||
|
// User properties
|
||||||
|
modelBuilder.Entity<User>().HasKey(x => x.Id);
|
||||||
|
modelBuilder.Entity<User>().Property(x => x.GoogleId).IsRequired().HasMaxLength(100);
|
||||||
|
modelBuilder.Entity<User>().Property(x => x.Email).IsRequired().HasMaxLength(255);
|
||||||
|
modelBuilder.Entity<User>().Property(x => x.FullName).IsRequired().HasMaxLength(255);
|
||||||
|
modelBuilder.Entity<User>().Property(x => x.IsActive).IsRequired().HasDefaultValue(false);
|
||||||
|
modelBuilder.Entity<User>().Property(x => x.LastLoginAt).IsRequired(false);
|
||||||
|
|
||||||
|
// User indexes
|
||||||
|
modelBuilder.Entity<User>().HasIndex(x => x.GoogleId).IsUnique().HasDatabaseName("IX_Users_GoogleId");
|
||||||
|
modelBuilder.Entity<User>().HasIndex(x => x.Email).IsUnique().HasDatabaseName("IX_Users_Email");
|
||||||
|
|
||||||
|
// Configure defaults for all CreatedAt and UpdatedAt in entities
|
||||||
|
ConfigureBaseEntity(modelBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureBaseEntity(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||||
|
{
|
||||||
|
if (typeof(BaseEntity).IsAssignableFrom(entityType.ClrType))
|
||||||
|
{
|
||||||
|
modelBuilder.Entity(entityType.ClrType)
|
||||||
|
.Property(nameof(BaseEntity.CreatedAt))
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
modelBuilder.Entity(entityType.ClrType)
|
||||||
|
.Property(nameof(BaseEntity.UpdatedAt))
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int SaveChanges()
|
||||||
|
{
|
||||||
|
UpdateTimestamps();
|
||||||
|
return base.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
UpdateTimestamps();
|
||||||
|
return base.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTimestamps()
|
||||||
|
{
|
||||||
|
var entities = ChangeTracker.Entries<BaseEntity>();
|
||||||
|
|
||||||
|
foreach (var entity in entities)
|
||||||
|
{
|
||||||
|
if (entity.State == EntityState.Added)
|
||||||
|
{
|
||||||
|
entity.Entity.CreatedAt = DateTime.UtcNow;
|
||||||
|
entity.Entity.UpdatedAt = DateTime.UtcNow;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (entity.State == EntityState.Modified)
|
||||||
|
{
|
||||||
|
entity.Entity.UpdatedAt = DateTime.UtcNow;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
BimAI.Infrastructure/Jobs/InvoiceSyncJob.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using BimAI.Infrastructure.Sync;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Jobs;
|
||||||
|
|
||||||
|
public class InvoiceSyncJob
|
||||||
|
{
|
||||||
|
private readonly InvoiceSyncService _invoiceSyncService;
|
||||||
|
private readonly ILogger<InvoiceSyncJob> _logger;
|
||||||
|
|
||||||
|
public InvoiceSyncJob(InvoiceSyncService invoiceSyncService, ILogger<InvoiceSyncJob> logger)
|
||||||
|
{
|
||||||
|
_invoiceSyncService = invoiceSyncService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ExecuteAsync()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Starting invoice sync...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _invoiceSyncService.RunAsync();
|
||||||
|
_logger.LogInformation("Invoice sync finished.");
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error during invoice sync.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
BimAI.Infrastructure/Jobs/ProductSyncJob.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using BimAI.Infrastructure.Sync;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Jobs;
|
||||||
|
|
||||||
|
public class ProductSyncJob
|
||||||
|
{
|
||||||
|
private readonly ProductSyncService _productSyncService;
|
||||||
|
private readonly ILogger<ProductSyncJob> _logger;
|
||||||
|
|
||||||
|
public ProductSyncJob(ProductSyncService productSyncService, ILogger<ProductSyncJob> logger)
|
||||||
|
{
|
||||||
|
_productSyncService = productSyncService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ExecuteAsync()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Starting product sync...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _productSyncService.RunAsync();
|
||||||
|
_logger.LogInformation("Product sync finished.");
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error during product sync.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using Bimix.Infrastructure.Data;
|
using BimAI.Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
@@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(BimixDbContext))]
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
[Migration("20250619185202_InitDatabase")]
|
[Migration("20250619185202_InitDatabase")]
|
||||||
partial class InitDatabase
|
partial class InitDatabase
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.Product", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitDatabase : Migration
|
public partial class InitDatabase : Migration
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using Bimix.Infrastructure.Data;
|
using BimAI.Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
@@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(BimixDbContext))]
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
[Migration("20250623184943_AddSyncState")]
|
[Migration("20250623184943_AddSyncState")]
|
||||||
partial class AddSyncState
|
partial class AddSyncState
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.Product", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -47,7 +47,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
b.ToTable("Products");
|
b.ToTable("Products");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.SyncState", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.SyncState", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Entity")
|
b.Property<string>("Entity")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(450)");
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class AddSyncState : Migration
|
public partial class AddSyncState : Migration
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using Bimix.Infrastructure.Data;
|
using BimAI.Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
@@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(BimixDbContext))]
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
[Migration("20250623194653_ResizeProductName")]
|
[Migration("20250623194653_ResizeProductName")]
|
||||||
partial class ResizeProductName
|
partial class ResizeProductName
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.Product", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -47,7 +47,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
b.ToTable("Products");
|
b.ToTable("Products");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.SyncState", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.SyncState", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Entity")
|
b.Property<string>("Entity")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(450)");
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class ResizeProductName : Migration
|
public partial class ResizeProductName : Migration
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using Bimix.Infrastructure.Data;
|
using BimAI.Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Migrations
|
namespace BimAI.Infrastructure.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(BimixDbContext))]
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
partial class BimixDbContextModelSnapshot : ModelSnapshot
|
[Migration("20250624193445_Products-NewFields")]
|
||||||
|
partial class ProductsNewFields
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
@@ -22,20 +25,35 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.Product", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uniqueidentifier");
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(40)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAt")
|
b.Property<DateTime>("CreatedAt")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("Ean")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(512)
|
.HasMaxLength(512)
|
||||||
.HasColumnType("nvarchar(512)");
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<string>("StockAddresses")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedAt")
|
b.Property<DateTime>("UpdatedAt")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
@@ -44,7 +62,7 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
b.ToTable("Products");
|
b.ToTable("Products");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bimix.Domain.Entities.SyncState", b =>
|
modelBuilder.Entity("BimAI.Domain.Entities.SyncState", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Entity")
|
b.Property<string>("Entity")
|
||||||
.HasColumnType("nvarchar(450)");
|
.HasColumnType("nvarchar(450)");
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ProductsNewFields : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Code",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(40)",
|
||||||
|
maxLength: 40,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Ean",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(50)",
|
||||||
|
maxLength: 50,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "StockAddresses",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(512)",
|
||||||
|
maxLength: 512,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Code",
|
||||||
|
table: "Products");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Ean",
|
||||||
|
table: "Products");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "StockAddresses",
|
||||||
|
table: "Products");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
136
BimAI.Infrastructure/Migrations/20250718162313_AddUsersTable.Designer.cs
generated
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
|
[Migration("20250718162313_AddUsersTable")]
|
||||||
|
partial class AddUsersTable
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.17")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(40)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.Property<string>("Ean")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<string>("StockAddresses")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.SyncState", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Entity")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<long>("LastSynced")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Entity");
|
||||||
|
|
||||||
|
b.ToTable("SyncStates");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("FullName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("GoogleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bit")
|
||||||
|
.HasDefaultValue(false);
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastLoginAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Email")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("IX_Users_Email");
|
||||||
|
|
||||||
|
b.HasIndex("GoogleId")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("IX_Users_GoogleId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddUsersTable : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "UpdatedAt",
|
||||||
|
table: "Products",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: false,
|
||||||
|
defaultValueSql: "GETUTCDATE()",
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "datetime2");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "Products",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: false,
|
||||||
|
defaultValueSql: "GETUTCDATE()",
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "datetime2");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Users",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||||
|
GoogleId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
|
Email = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
||||||
|
FullName = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
||||||
|
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
|
||||||
|
LastLoginAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||||
|
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_Email",
|
||||||
|
table: "Users",
|
||||||
|
column: "Email",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_GoogleId",
|
||||||
|
table: "Users",
|
||||||
|
column: "GoogleId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "UpdatedAt",
|
||||||
|
table: "Products",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "datetime2",
|
||||||
|
oldDefaultValueSql: "GETUTCDATE()");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<DateTime>(
|
||||||
|
name: "CreatedAt",
|
||||||
|
table: "Products",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(DateTime),
|
||||||
|
oldType: "datetime2",
|
||||||
|
oldDefaultValueSql: "GETUTCDATE()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
133
BimAI.Infrastructure/Migrations/BimixDbContextModelSnapshot.cs
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(BimAIDbContext))]
|
||||||
|
partial class BimAIDbContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.17")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(40)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.Property<string>("Ean")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<string>("StockAddresses")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.SyncState", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Entity")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<long>("LastSynced")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Entity");
|
||||||
|
|
||||||
|
b.ToTable("SyncStates");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("BimAI.Domain.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("FullName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("GoogleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsActive")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bit")
|
||||||
|
.HasDefaultValue(false);
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastLoginAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("datetime2")
|
||||||
|
.HasDefaultValueSql("GETUTCDATE()");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Email")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("IX_Users_Email");
|
||||||
|
|
||||||
|
b.HasIndex("GoogleId")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("IX_Users_GoogleId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
151
BimAI.Infrastructure/Sync/InvoiceSyncService.cs
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Web;
|
||||||
|
using BimAI.Domain.Entities;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace BimAI.Infrastructure.Sync;
|
||||||
|
|
||||||
|
public class InvoiceSyncService(HttpClient httpClient, BimAIDbContext db, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
private string DecodeHtmlEntities(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
return text;
|
||||||
|
|
||||||
|
return HttpUtility.HtmlDecode(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunAsync()
|
||||||
|
{
|
||||||
|
var apiKey = configuration["TWINPOL_CRM:ApiKey"];
|
||||||
|
var syncState = db.SyncStates.FirstOrDefault(x => x.Entity == "Invoice") ?? new SyncState { Entity = "Invoice", LastSynced = 0 };
|
||||||
|
|
||||||
|
var url = $"https://crm.twinpol.com/REST/index.php?key={apiKey}&action=bimai.export.ecommerce&since=0";
|
||||||
|
var response = await httpClient.GetStringAsync(url);
|
||||||
|
|
||||||
|
var jsonDoc = JsonSerializer.Deserialize<JsonElement>(response);
|
||||||
|
if (!jsonDoc.TryGetProperty("data", out var dataElement))
|
||||||
|
{
|
||||||
|
Console.WriteLine("[SYNC] No 'data' property in response");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var invoices = dataElement.EnumerateArray();
|
||||||
|
var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||||
|
var processedCount = 0;
|
||||||
|
var batchSize = 20;
|
||||||
|
|
||||||
|
foreach (var invoiceJson in invoices)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var e5Id = invoiceJson.GetProperty("e5Id").GetString() ?? "";
|
||||||
|
var documentNo = DecodeHtmlEntities(invoiceJson.GetProperty("documentNo").GetString() ?? "");
|
||||||
|
var type = DecodeHtmlEntities(invoiceJson.GetProperty("type").GetString() ?? "");
|
||||||
|
var registerDateStr = invoiceJson.GetProperty("registerDate").GetString() ?? "";
|
||||||
|
var sellDateStr = invoiceJson.GetProperty("sellDate").GetString() ?? "";
|
||||||
|
var clientName = DecodeHtmlEntities(invoiceJson.GetProperty("clientName").GetString() ?? "");
|
||||||
|
var clientId = DecodeHtmlEntities(invoiceJson.GetProperty("clientId").GetString() ?? "");
|
||||||
|
var clientNip = DecodeHtmlEntities(invoiceJson.GetProperty("clientNip").GetString() ?? "");
|
||||||
|
var clientAddress = DecodeHtmlEntities(invoiceJson.GetProperty("clientAddress").GetString() ?? "");
|
||||||
|
var currency = invoiceJson.GetProperty("currency").GetString() ?? "PLN";
|
||||||
|
var totalNettoStr = invoiceJson.GetProperty("totalNetto").GetString() ?? "0";
|
||||||
|
var totalBruttoStr = invoiceJson.GetProperty("totalBrutto").GetString() ?? "0";
|
||||||
|
var totalVatStr = invoiceJson.GetProperty("totalVat").GetString() ?? "0";
|
||||||
|
var source = invoiceJson.GetProperty("source").GetString() ?? "";
|
||||||
|
|
||||||
|
if (!DateTime.TryParse(registerDateStr, out var registerDate))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SYNC] Invalid registerDate for invoice {documentNo}: {registerDateStr}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DateTime.TryParse(sellDateStr, out var sellDate))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SYNC] Invalid sellDate for invoice {documentNo}: {sellDateStr}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!decimal.TryParse(totalNettoStr, out var totalNetto))
|
||||||
|
totalNetto = 0;
|
||||||
|
|
||||||
|
if (!decimal.TryParse(totalBruttoStr, out var totalBrutto))
|
||||||
|
totalBrutto = 0;
|
||||||
|
|
||||||
|
if (!decimal.TryParse(totalVatStr, out var totalVat))
|
||||||
|
totalVat = 0;
|
||||||
|
|
||||||
|
var existing = db.Invoices.FirstOrDefault(x => x.DocumentNo == documentNo && x.Source == source);
|
||||||
|
|
||||||
|
if (existing == null)
|
||||||
|
{
|
||||||
|
var invoice = new Invoice
|
||||||
|
{
|
||||||
|
DocumentNo = documentNo,
|
||||||
|
Type = type,
|
||||||
|
RegisterDate = registerDate,
|
||||||
|
SellDate = sellDate,
|
||||||
|
ClientName = clientName,
|
||||||
|
ClientId = string.IsNullOrWhiteSpace(clientId) ? null : clientId,
|
||||||
|
ClientNip = string.IsNullOrWhiteSpace(clientNip) ? null : clientNip,
|
||||||
|
ClientAddress = string.IsNullOrWhiteSpace(clientAddress) ? null : clientAddress,
|
||||||
|
Currency = currency,
|
||||||
|
TotalNetto = totalNetto,
|
||||||
|
TotalBrutto = totalBrutto,
|
||||||
|
TotalVat = totalVat,
|
||||||
|
Source = source,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
UpdatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
db.Invoices.Add(invoice);
|
||||||
|
Console.WriteLine($"[SYNC] Added invoice: {documentNo} from {source}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
existing.Type = type;
|
||||||
|
existing.RegisterDate = registerDate;
|
||||||
|
existing.SellDate = sellDate;
|
||||||
|
existing.ClientName = clientName;
|
||||||
|
existing.ClientId = string.IsNullOrWhiteSpace(clientId) ? null : clientId;
|
||||||
|
existing.ClientNip = string.IsNullOrWhiteSpace(clientNip) ? null : clientNip;
|
||||||
|
existing.ClientAddress = string.IsNullOrWhiteSpace(clientAddress) ? null : clientAddress;
|
||||||
|
existing.Currency = currency;
|
||||||
|
existing.TotalNetto = totalNetto;
|
||||||
|
existing.TotalBrutto = totalBrutto;
|
||||||
|
existing.TotalVat = totalVat;
|
||||||
|
existing.UpdatedAt = DateTime.UtcNow;
|
||||||
|
Console.WriteLine($"[SYNC] Updated invoice: {documentNo} from {source}");
|
||||||
|
}
|
||||||
|
|
||||||
|
processedCount++;
|
||||||
|
|
||||||
|
if (processedCount % batchSize == 0)
|
||||||
|
{
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
Console.WriteLine($"[SYNC] Saved batch of {batchSize} invoices. Total processed: {processedCount}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[SYNC] Error processing invoice: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
Console.WriteLine($"[SYNC] Saved remaining invoices. Total processed: {processedCount}");
|
||||||
|
|
||||||
|
syncState.LastSynced = now;
|
||||||
|
if (db.SyncStates.FirstOrDefault(x => x.Entity == "Invoice") == null)
|
||||||
|
{
|
||||||
|
db.SyncStates.Add(syncState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
db.SyncStates.Update(syncState);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Before final SaveChangesAsync");
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
Console.WriteLine("[SYNC] Invoice sync completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,30 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Bimix.Domain.Entities;
|
using System.Web;
|
||||||
using Bimix.Infrastructure.Data;
|
using BimAI.Domain.Entities;
|
||||||
|
using BimAI.Infrastructure.Data;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Bimix.Infrastructure.Sync;
|
namespace BimAI.Infrastructure.Sync;
|
||||||
|
|
||||||
public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfiguration configuration)
|
public class ProductSyncService(HttpClient httpClient, BimAIDbContext db, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient = httpClient;
|
/// <summary>
|
||||||
private readonly BimixDbContext _db = db;
|
/// Dekoduje encje HTML w ciągu znaków (np. " na ")
|
||||||
private readonly IConfiguration _configuration = configuration;
|
/// </summary>
|
||||||
|
private string DecodeHtmlEntities(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
return text;
|
||||||
|
|
||||||
|
return HttpUtility.HtmlDecode(text);
|
||||||
|
}
|
||||||
public async Task RunAsync()
|
public async Task RunAsync()
|
||||||
{
|
{
|
||||||
var apiKey = _configuration["E5_CRM:ApiKey"];
|
var apiKey = configuration["E5_CRM:ApiKey"];
|
||||||
var syncState = _db.SyncStates.FirstOrDefault(x => x.Entity == "Product") ?? new SyncState { Entity = "Product", LastSynced = 0};
|
var syncState = db.SyncStates.FirstOrDefault(x => x.Entity == "Product") ?? new SyncState { Entity = "Product", LastSynced = 0};
|
||||||
|
|
||||||
var url = $"https://crm.e5.pl/REST/index.php?key={apiKey}&action=export.products.list&since={syncState.LastSynced}";
|
var url = $"https://crm.e5.pl/REST/index.php?key={apiKey}&action=export.products.list&since={syncState.LastSynced}";
|
||||||
var response = await _httpClient.GetStringAsync(url);
|
var response = await httpClient.GetStringAsync(url);
|
||||||
|
|
||||||
var products = JsonSerializer.Deserialize<List<JsonElement>>(response);
|
var products = JsonSerializer.Deserialize<List<JsonElement>>(response);
|
||||||
if (products == null) return;
|
if (products == null) return;
|
||||||
@@ -27,7 +34,10 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
foreach (var p in products)
|
foreach (var p in products)
|
||||||
{
|
{
|
||||||
var idStr = p.GetProperty("id").GetString() ?? "";
|
var idStr = p.GetProperty("id").GetString() ?? "";
|
||||||
var name = p.GetProperty("name").GetString() ?? "";
|
var name = DecodeHtmlEntities(p.GetProperty("name").GetString() ?? "");
|
||||||
|
var code = DecodeHtmlEntities(p.GetProperty("code").GetString() ?? "");
|
||||||
|
var stockAddresses = DecodeHtmlEntities(p.GetProperty("stock_addresses").GetString() ?? "");
|
||||||
|
var ean = DecodeHtmlEntities(p.GetProperty("ean").GetString() ?? "");
|
||||||
|
|
||||||
if (!Guid.TryParse(idStr, out Guid id))
|
if (!Guid.TryParse(idStr, out Guid id))
|
||||||
{
|
{
|
||||||
@@ -35,7 +45,7 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var existing = _db.Products.FirstOrDefault(x => x.Id == id);
|
var existing = db.Products.FirstOrDefault(x => x.Id == id);
|
||||||
|
|
||||||
if (existing == null)
|
if (existing == null)
|
||||||
{
|
{
|
||||||
@@ -43,10 +53,13 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
|
Ean = ean,
|
||||||
|
Code = code,
|
||||||
|
StockAddresses = stockAddresses,
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
UpdatedAt = DateTime.UtcNow
|
UpdatedAt = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
_db.Products.Add(product);
|
db.Products.Add(product);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -58,17 +71,17 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
|
|
||||||
var exportedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
var exportedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||||
var updateUrl = $"https://crm.e5.pl/REST/index.php?key={apiKey}&action=export.products.setExportedAt&id={id}&exportedAt={exportedAt}";
|
var updateUrl = $"https://crm.e5.pl/REST/index.php?key={apiKey}&action=export.products.setExportedAt&id={id}&exportedAt={exportedAt}";
|
||||||
await _httpClient.GetAsync(updateUrl);
|
await httpClient.GetAsync(updateUrl);
|
||||||
}
|
}
|
||||||
syncState.LastSynced = now;
|
syncState.LastSynced = now;
|
||||||
if (_db.SyncStates.FirstOrDefault(x => x.Entity == "Product") == null)
|
if (db.SyncStates.FirstOrDefault(x => x.Entity == "Product") == null)
|
||||||
{
|
{
|
||||||
_db.SyncStates.Add(syncState);
|
db.SyncStates.Add(syncState);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_db.SyncStates.Update(syncState);
|
db.SyncStates.Update(syncState);
|
||||||
}
|
}
|
||||||
await _db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Bimix.UI.Mobile;
|
namespace BimAI.UI.Mobile;
|
||||||
|
|
||||||
public partial class App : Microsoft.Maui.Controls.Application
|
public partial class App : Microsoft.Maui.Controls.Application
|
||||||
{
|
{
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-ios</TargetFramework>
|
<TargetFramework>net10.0-ios</TargetFramework>
|
||||||
|
<GenerateXcodeProject>true</GenerateXcodeProject>
|
||||||
|
|
||||||
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
|
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
|
||||||
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
|
<!-- <TargetFrameworks>$(TargetFrameworks);net10.0-tizen</TargetFrameworks> -->
|
||||||
|
|
||||||
<!-- Note for MacCatalyst:
|
<!-- Note for MacCatalyst:
|
||||||
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
|
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
|
||||||
@@ -13,7 +15,7 @@
|
|||||||
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
|
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
|
||||||
|
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>Bimix.UI.Mobile</RootNamespace>
|
<RootNamespace>BimAI.UI.Mobile</RootNamespace>
|
||||||
<UseMaui>true</UseMaui>
|
<UseMaui>true</UseMaui>
|
||||||
<SingleProject>true</SingleProject>
|
<SingleProject>true</SingleProject>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
@@ -21,10 +23,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<!-- Display name -->
|
<!-- Display name -->
|
||||||
<ApplicationTitle>Bimix.UI.Mobile</ApplicationTitle>
|
<ApplicationTitle>BimAI</ApplicationTitle>
|
||||||
|
|
||||||
<!-- App Identifier -->
|
<!-- App Identifier -->
|
||||||
<ApplicationId>com.companyname.bimix.ui.mobile</ApplicationId>
|
<ApplicationId></ApplicationId>
|
||||||
|
|
||||||
<!-- Versions -->
|
<!-- Versions -->
|
||||||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
|
||||||
@@ -38,6 +40,13 @@
|
|||||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
|
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Platform)' == 'iPhone'">
|
||||||
|
<ApplicationId></ApplicationId>
|
||||||
|
<CodesignKey>Apple Development: Michal Zielinski (2F35ZHMBTB)</CodesignKey>
|
||||||
|
<CodesignProvision>bimai-local</CodesignProvision>
|
||||||
|
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- App Icon -->
|
<!-- App Icon -->
|
||||||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>
|
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>
|
||||||
@@ -56,20 +65,26 @@
|
|||||||
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
|
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
|
||||||
|
|
||||||
<!-- Dodaj pliki wwwroot jako MAUI assets -->
|
<!-- Dodaj pliki wwwroot jako MAUI assets -->
|
||||||
<MauiAsset Include="wwwroot\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
|
<MauiAsset Include="wwwroot\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
|
||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
|
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
|
||||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
|
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1"/>
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0"/>
|
||||||
<PackageReference Include="MudBlazor" Version="8.8.0"/>
|
<PackageReference Include="MudBlazor" Version="8.8.0"/>
|
||||||
|
<PackageReference Include="ZXing.Net.MAUI" Version="0.4.0"/>
|
||||||
|
<PackageReference Include="ZXing.Net.MAUI.Controls" Version="0.4.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Bimix.UI.Shared\Bimix.UI.Shared.csproj"/>
|
<ProjectReference Include="..\BimAI.UI.Shared\BimAI.UI.Shared.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Bimix.UI.Mobile;
|
namespace BimAI.UI.Mobile;
|
||||||
|
|
||||||
public partial class MainPage : ContentPage
|
public partial class MainPage : ContentPage
|
||||||
{
|
{
|
||||||
67
BimAI.UI.Mobile/MauiProgram.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using BimAI.UI.Mobile.Services;
|
||||||
|
using BimAI.UI.Shared.Extensions;
|
||||||
|
using BimAI.UI.Shared.Interfaces;
|
||||||
|
using BimAI.UI.Shared.Services;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Maui.Controls.Hosting;
|
||||||
|
using Microsoft.Maui.Devices;
|
||||||
|
using Microsoft.Maui.Hosting;
|
||||||
|
using MudBlazor.Services;
|
||||||
|
using ZXing.Net.Maui.Controls;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Mobile;
|
||||||
|
|
||||||
|
public static class MauiProgram
|
||||||
|
{
|
||||||
|
public static MauiApp CreateMauiApp()
|
||||||
|
{
|
||||||
|
var builder = MauiApp.CreateBuilder();
|
||||||
|
builder
|
||||||
|
.UseMauiApp<App>()
|
||||||
|
.UseBarcodeReader()
|
||||||
|
.ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); });
|
||||||
|
|
||||||
|
builder.Configuration
|
||||||
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||||||
|
.AddJsonFile($"appsettings.Development.json", optional: true, reloadOnChange: false)
|
||||||
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
builder.Services.AddMauiBlazorWebView();
|
||||||
|
builder.Services.AddMudServices();
|
||||||
|
|
||||||
|
if (DeviceInfo.Platform == DevicePlatform.iOS)
|
||||||
|
{
|
||||||
|
builder.Services.AddSingleton<IScannerService, ScannerService>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.Services.AddSingleton<IScannerService, NoOpScannerService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Services.AddScoped<AuthService>();
|
||||||
|
|
||||||
|
var baseUrl = GetApiBaseUrl();
|
||||||
|
builder.Services.AddSharedServices(baseUrl);
|
||||||
|
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||||
|
builder.Logging.AddDebug();
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Debug);
|
||||||
|
#endif
|
||||||
|
return builder.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetApiBaseUrl()
|
||||||
|
{
|
||||||
|
#if IOS
|
||||||
|
// iOS symulator
|
||||||
|
return "http://192.168.29.140:7142/";
|
||||||
|
#else
|
||||||
|
return "https://localhost:7142/";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 228 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
140
BimAI.UI.Mobile/Services/ScannerService.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
using BimAI.UI.Shared.Interfaces;
|
||||||
|
using ZXing.Net.Maui;
|
||||||
|
using ZXing.Net.Maui.Controls;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Mobile.Services;
|
||||||
|
|
||||||
|
public class ScannerService : IScannerService
|
||||||
|
{
|
||||||
|
public bool IsAvailable => true;
|
||||||
|
|
||||||
|
public async Task<string?> ScanBarcodeAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!IsAvailable)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var hasPermission = await RequestCameraPermissionsAsync();
|
||||||
|
if (!hasPermission)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var tcs = new TaskCompletionSource<string?>();
|
||||||
|
|
||||||
|
await MainThread.InvokeOnMainThreadAsync(async () =>
|
||||||
|
{
|
||||||
|
var scanner = new CameraBarcodeReaderView
|
||||||
|
{
|
||||||
|
Options = new BarcodeReaderOptions
|
||||||
|
{
|
||||||
|
Formats = BarcodeFormats.OneDimensional | BarcodeFormats.TwoDimensional,
|
||||||
|
AutoRotate = true,
|
||||||
|
Multiple = false
|
||||||
|
},
|
||||||
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
||||||
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
||||||
|
BackgroundColor = Colors.Black
|
||||||
|
};
|
||||||
|
|
||||||
|
scanner.BarcodesDetected += async (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Results?.Any() == true)
|
||||||
|
{
|
||||||
|
var barcode = e.Results.First();
|
||||||
|
|
||||||
|
// Wykonaj operacje UI na głównym wątku
|
||||||
|
await MainThread.InvokeOnMainThreadAsync(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Microsoft.Maui.Controls.Application.Current?.MainPage?.Navigation.PopModalAsync()!;
|
||||||
|
tcs.TrySetResult(barcode.Value);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Error closing modal: {ex.Message}");
|
||||||
|
tcs.TrySetException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var cancelButton = new Button
|
||||||
|
{
|
||||||
|
Text = "Anuluj",
|
||||||
|
BackgroundColor = Colors.Red,
|
||||||
|
TextColor = Colors.White,
|
||||||
|
Margin = new Thickness(20),
|
||||||
|
HorizontalOptions = LayoutOptions.Center
|
||||||
|
};
|
||||||
|
|
||||||
|
cancelButton.Clicked += async (sender, e) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Microsoft.Maui.Controls.Application.Current?.MainPage?.Navigation.PopModalAsync()!;
|
||||||
|
tcs.TrySetResult(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Error closing modal: {ex.Message}");
|
||||||
|
tcs.TrySetException(ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var stackLayout = new StackLayout
|
||||||
|
{
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new Label
|
||||||
|
{
|
||||||
|
Text = "Skieruj kamerę na kod kreskowy",
|
||||||
|
HorizontalOptions = LayoutOptions.Center,
|
||||||
|
VerticalOptions = LayoutOptions.Start,
|
||||||
|
Margin = new Thickness(20),
|
||||||
|
FontSize = 18,
|
||||||
|
TextColor = Colors.White
|
||||||
|
},
|
||||||
|
scanner,
|
||||||
|
cancelButton
|
||||||
|
},
|
||||||
|
BackgroundColor = Colors.Black,
|
||||||
|
Spacing = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var scannerPage = new ContentPage
|
||||||
|
{
|
||||||
|
Title = "Skanuj kod",
|
||||||
|
Content = stackLayout,
|
||||||
|
BackgroundColor = Colors.Black
|
||||||
|
};
|
||||||
|
|
||||||
|
await Microsoft.Maui.Controls.Application.Current?.MainPage?.Navigation.PushModalAsync(scannerPage)!;
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = await tcs.Task;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Scanner returned: {result}");
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Scanner error: {e.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> RequestCameraPermissionsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var status = await Permissions.RequestAsync<Permissions.Camera>();
|
||||||
|
return status == PermissionStatus.Granted;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Permission error: {e.Message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
BimAI.UI.Mobile/appsettings.Development.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"GoogleAuth": {
|
||||||
|
"ClientId": "1037727384847-t1l2au6du34kdckamro81guklk17cjah.apps.googleusercontent.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
BimAI.UI.Mobile/appsettings.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"GoogleAuth": {
|
||||||
|
"ClientId": "1037727384847-t1l2au6du34kdckamro81guklk17cjah.apps.googleusercontent.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -12,17 +12,19 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.17" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="10.0.0-rc.1.25451.107" />
|
||||||
<PackageReference Include="MudBlazor" Version="8.8.0" />
|
<PackageReference Include="MudBlazor" Version="8.8.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="10.0.0-rc.1.25451.107" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0-rc.1.25451.107" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Bimix.Domain\Bimix.Domain.csproj" />
|
<ProjectReference Include="..\BimAI.Domain\BimAI.Domain.csproj" />
|
||||||
<ProjectReference Include="..\Bimix.Application\Bimix.Application.csproj" />
|
<ProjectReference Include="..\BimAI.Application\BimAI.Application.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="wwwroot\" />
|
<Folder Include="wwwroot\images\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
42
BimAI.UI.Shared/Components/AuthGuard.razor
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
@using BimAI.UI.Shared.Services
|
||||||
|
@inject AuthService AuthService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
|
||||||
|
@if (_isLoading)
|
||||||
|
{
|
||||||
|
<div class="d-flex justify-center align-center" style="height: 100vh;">
|
||||||
|
<MudProgressCircular Indeterminate="true" Size="Size.Large" />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (_isAuthenticated)
|
||||||
|
{
|
||||||
|
@ChildContent
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public RenderFragment? ChildContent { get; set; }
|
||||||
|
|
||||||
|
private bool _isLoading = true;
|
||||||
|
private bool _isAuthenticated = false;
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AuthGuard: Checking authentication...");
|
||||||
|
|
||||||
|
_isAuthenticated = await AuthService.CheckAuthenticationAsync();
|
||||||
|
_isLoading = false;
|
||||||
|
|
||||||
|
Console.WriteLine($"AuthGuard: isAuthenticated={_isAuthenticated}");
|
||||||
|
|
||||||
|
if (!_isAuthenticated)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AuthGuard: Redirecting to /login");
|
||||||
|
Navigation.NavigateTo("/login", replace: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
160
BimAI.UI.Shared/Components/InvoiceListComponent.razor
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
@using MudBlazor.Internal
|
||||||
|
@using System.Data
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Lista Faktur</MudText>
|
||||||
|
|
||||||
|
<MudExpansionPanels Class="mb-4">
|
||||||
|
<MudExpansionPanel Icon="@Icons.Material.Filled.FilterList"
|
||||||
|
Text="Filtry"
|
||||||
|
Expanded="true">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Search"
|
||||||
|
Label="Szukaj"
|
||||||
|
Placeholder="Numer dokumentu, klient..."
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchInvoices"
|
||||||
|
Clearable="true" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.DocumentNo"
|
||||||
|
Label="Numer dokumentu"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchInvoices"
|
||||||
|
Clearable="true" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Type"
|
||||||
|
Label="Typ dokumentu"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchInvoices"
|
||||||
|
Clearable="true" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.ClientName"
|
||||||
|
Label="Nazwa klienta"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchInvoices"
|
||||||
|
Clearable="true" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudDatePicker @bind-Date="filterRequest.RegisterDateFrom"
|
||||||
|
Label="Data rejestracji od"
|
||||||
|
DateFormat="dd.MM.yyyy"
|
||||||
|
Editable="true"
|
||||||
|
Clearable="true"
|
||||||
|
Immediate="true"
|
||||||
|
@bind-Date:after="OnFilterChanged" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudDatePicker @bind-Date="filterRequest.RegisterDateTo"
|
||||||
|
Label="Data rejestracji do"
|
||||||
|
DateFormat="d.MM.yyyy"
|
||||||
|
Editable="true"
|
||||||
|
Clearable="true"
|
||||||
|
Immediate="true"
|
||||||
|
@bind-Date:after="OnFilterChanged" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudDatePicker @bind-Date="filterRequest.SellDateFrom"
|
||||||
|
Label="Data sprzedaży od"
|
||||||
|
DateFormat="d.MM.yyyy"
|
||||||
|
Editable="true"
|
||||||
|
Clearable="true"
|
||||||
|
Immediate="true"
|
||||||
|
@bind-Date:after="OnFilterChanged" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudDatePicker @bind-Date="filterRequest.SellDateTo"
|
||||||
|
Label="Data sprzedaży do"
|
||||||
|
DateFormat="d.MM.yyyy"
|
||||||
|
Editable="true"
|
||||||
|
Clearable="true"
|
||||||
|
Immediate="true"
|
||||||
|
@bind-Date:after="OnFilterChanged" />
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudButton Variant="Variant.Outlined"
|
||||||
|
OnClick="ClearFilters"
|
||||||
|
StartIcon="Icons.Material.Filled.Clear">
|
||||||
|
Wyczyść filtry
|
||||||
|
</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudExpansionPanel>
|
||||||
|
</MudExpansionPanels>
|
||||||
|
|
||||||
|
|
||||||
|
<MudDivider Class="my-4"></MudDivider>
|
||||||
|
|
||||||
|
<MudTable Items="invoices.Items"
|
||||||
|
Dense="true"
|
||||||
|
Hover="true"
|
||||||
|
Loading="isLoading"
|
||||||
|
LoadingProgressColor="Color.Info">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Numer dokumentu</MudTh>
|
||||||
|
<MudTh>Typ</MudTh>
|
||||||
|
<MudTh>Klient</MudTh>
|
||||||
|
<MudTh>Data rejestracji</MudTh>
|
||||||
|
<MudTh>Data sprzedaży</MudTh>
|
||||||
|
<MudTh>Wartość brutto</MudTh>
|
||||||
|
<MudTh>Akcje</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd DataLabel="Numer dokumentu">@context.DocumentNo</MudTd>
|
||||||
|
<MudTd DataLabel="Typ">@context.Type</MudTd>
|
||||||
|
<MudTd DataLabel="Klient">@context.ClientName</MudTd>
|
||||||
|
<MudTd DataLabel="Data rejestracji">@context.RegisterDate.ToShortDateString()</MudTd>
|
||||||
|
<MudTd DataLabel="Data sprzedaży">@context.SellDate.ToShortDateString()</MudTd>
|
||||||
|
<MudTd DataLabel="Wartość brutto">@context.TotalBrutto.ToString("C2")</MudTd>
|
||||||
|
<MudTd DataLabel="Akcje">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Visibility"
|
||||||
|
Size="Size.Small"
|
||||||
|
OnClick="() => ViewInvoice(context.Id)"/>
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
||||||
|
Size="Size.Small"
|
||||||
|
OnClick="() => EditInvoice(context.Id)"/>
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||||
|
Size="Size.Small"
|
||||||
|
Color="Color.Error"
|
||||||
|
OnClick="() => DeleteInvoice(context.Id)"/>
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
<NoRecordsContent>
|
||||||
|
<MudText>Brak faktur do wyświetlenia</MudText>
|
||||||
|
</NoRecordsContent>
|
||||||
|
<LoadingContent>
|
||||||
|
Ładowanie...
|
||||||
|
</LoadingContent>
|
||||||
|
</MudTable>
|
||||||
|
|
||||||
|
@if (invoices.TotalCount > 0)
|
||||||
|
{
|
||||||
|
<MudGrid Class="mt-4" AlignItems="Center">
|
||||||
|
<MudItem xs="12" sm="6">
|
||||||
|
<MudText Typo="Typo.body2">
|
||||||
|
Wyniki @((invoices.Page - 1) * invoices.PageSize + 1) - @Math.Min(invoices.Page * invoices.PageSize, invoices.TotalCount)
|
||||||
|
z @invoices.TotalCount
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" sm="6" Class="d-flex justify-end">
|
||||||
|
<MudPagination Count="invoices.TotalPages"
|
||||||
|
Selected="invoices.Page"
|
||||||
|
SelectedChanged="OnPageChanged"
|
||||||
|
ShowFirstButton="true"
|
||||||
|
ShowLastButton="true"/>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
}
|
||||||
85
BimAI.UI.Shared/Components/InvoiceListComponent.razor.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using BimAI.UI.Shared.Services;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Components;
|
||||||
|
|
||||||
|
public partial class InvoiceListComponent : ComponentBase
|
||||||
|
{
|
||||||
|
[Inject] private InvoiceService InvoiceService { get; set; } = default!;
|
||||||
|
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
||||||
|
|
||||||
|
private PagedResult<InvoiceDto> invoices = new();
|
||||||
|
private InvoiceFilterRequest filterRequest = new();
|
||||||
|
private bool isLoading = false;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await LoadInvoices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadInvoices()
|
||||||
|
{
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await InvoiceService.GetInvoiceAsync(filterRequest);
|
||||||
|
invoices = result ?? new PagedResult<InvoiceDto>();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading invoices failed: {ex.Message}");
|
||||||
|
Console.WriteLine($"Stack trace: {ex.StackTrace}");
|
||||||
|
Snackbar.Add($"Błąd podczas ładowania faktur: {ex.Message}", Severity.Error);
|
||||||
|
invoices = new PagedResult<InvoiceDto>();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SearchInvoices()
|
||||||
|
{
|
||||||
|
filterRequest.Page = 1;
|
||||||
|
await LoadInvoices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnPageChanged(int page)
|
||||||
|
{
|
||||||
|
filterRequest.Page = page;
|
||||||
|
await LoadInvoices();
|
||||||
|
}
|
||||||
|
private async Task OnFilterChanged()
|
||||||
|
{
|
||||||
|
filterRequest.Page = 1;
|
||||||
|
await SearchInvoices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ClearFilters()
|
||||||
|
{
|
||||||
|
filterRequest = new InvoiceFilterRequest();
|
||||||
|
await LoadInvoices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ViewInvoice(Guid invoiceId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Console.WriteLine($"Zobacz fakturę: {invoiceId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task EditInvoice(Guid invoiceId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Console.WriteLine($"Edytuj fakturę: {invoiceId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteInvoice(Guid invoiceId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Console.WriteLine($"Usuń fakturę: {invoiceId}");
|
||||||
|
}
|
||||||
|
}
|
||||||
142
BimAI.UI.Shared/Components/LoginCard.razor
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
|
||||||
|
@using BimAI.UI.Shared.Services
|
||||||
|
@using Microsoft.Extensions.Configuration
|
||||||
|
@inject IJSRuntime JS
|
||||||
|
@inject IConfiguration Configuration
|
||||||
|
@inject AuthService AuthService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
|
<MudCard Class="login-card" Elevation="8">
|
||||||
|
<MudCardContent Class="pa-8 d-flex flex-column align-center">
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Witaj w BimAI</MudText>
|
||||||
|
<MudText Typo="Typo.body1" Class="mb-6 text-center">
|
||||||
|
Zaloguj się używając konta Google
|
||||||
|
</MudText>
|
||||||
|
|
||||||
|
<MudButton
|
||||||
|
Variant="Variant.Filled"
|
||||||
|
StartIcon="@Icons.Custom.Brands.Google"
|
||||||
|
Size="Size.Large"
|
||||||
|
OnClick="HandleGoogleSignIn"
|
||||||
|
Disabled="@_isLoading">
|
||||||
|
@if (_isLoading)
|
||||||
|
{
|
||||||
|
<MudProgressCircular Class="mr-3" Size="Size.Small" Indeterminate="true"></MudProgressCircular>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span>Zaloguj z Google</span>
|
||||||
|
}
|
||||||
|
</MudButton>
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||||
|
{
|
||||||
|
<MudAlert Severity="Severity.Error" Class="mt-4">
|
||||||
|
@_errorMessage
|
||||||
|
</MudAlert>
|
||||||
|
}
|
||||||
|
</MudCardContent>
|
||||||
|
</MudCard>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private bool _isLoading = false;
|
||||||
|
private string _errorMessage = string.Empty;
|
||||||
|
private static LoginCard? _instance;
|
||||||
|
private bool _isInitialized = false;
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
await InitializeGoogleSignIn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task InitializeGoogleSignIn()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_isInitialized) return;
|
||||||
|
|
||||||
|
var clientId = Configuration["GoogleAuth:ClientId"];
|
||||||
|
if (string.IsNullOrEmpty(clientId))
|
||||||
|
{
|
||||||
|
throw new Exception("Google ClientId is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await JS.InvokeVoidAsync("initGoogleSignIn", clientId);
|
||||||
|
_isInitialized = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_errorMessage = "Błąd inicjalizacji Google Sign-In.";
|
||||||
|
Console.Error.WriteLine($"Google Sign-In initialization error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleGoogleSignIn()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_isLoading = true;
|
||||||
|
_errorMessage = string.Empty;
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
await JS.InvokeVoidAsync("requestGoogleSignIn");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_errorMessage = "Błąd podczas logowania. Spróbuj ponownie";
|
||||||
|
_isLoading = false;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JSInvokable]
|
||||||
|
public static async Task OnGoogleSignInSuccess(string accessToken, string fullName, string email, string avatarUrl)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Google Sign-In Success: {email}");
|
||||||
|
|
||||||
|
if (_instance != null)
|
||||||
|
{
|
||||||
|
var userInfo = new UserInfo
|
||||||
|
{
|
||||||
|
FullName = fullName,
|
||||||
|
Email = email,
|
||||||
|
AvatarUrl = avatarUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
await _instance.AuthService.SetAuthenticationAsync(accessToken, userInfo);
|
||||||
|
|
||||||
|
_instance._isLoading = false;
|
||||||
|
_instance._errorMessage = string.Empty;
|
||||||
|
|
||||||
|
_instance.NavigationManager.NavigateTo("/dashboard", replace: true);
|
||||||
|
|
||||||
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JSInvokable]
|
||||||
|
public static async Task OnGoogleSignInError(string error)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Google SignIn Error: {error}");
|
||||||
|
|
||||||
|
if (_instance != null)
|
||||||
|
{
|
||||||
|
_instance._isLoading = false;
|
||||||
|
_instance._errorMessage = "Błąd logowania Google. Spróbuj ponownie";
|
||||||
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.login-card {
|
||||||
|
max-width: 400px;
|
||||||
|
width: 100%;
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
124
BimAI.UI.Shared/Components/ProductListComponent.razor
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
@using MudBlazor.Internal
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-4">Lista Produktów</MudText>
|
||||||
|
|
||||||
|
<MudExpansionPanels Class="mb-4">
|
||||||
|
<MudExpansionPanel Icon="@Icons.Material.Filled.FilterList"
|
||||||
|
Text="Filtry"
|
||||||
|
Expanded="true">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Search"
|
||||||
|
Label="Szukaj"
|
||||||
|
Placeholder="Nazwa, Kod, EAN..."
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchProducts"
|
||||||
|
Clearable="true"/>
|
||||||
|
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Name"
|
||||||
|
Label="Nazwa produktu"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchProducts"
|
||||||
|
Clearable="true"/>
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Code"
|
||||||
|
Label="Kod produktu"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchProducts"
|
||||||
|
Clearable="true"/>
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<div style="display: flex; gap: 8px; align-items: flex-end;">
|
||||||
|
<div style="flex: 1;">
|
||||||
|
<MudTextField @bind-Value="filterRequest.Ean"
|
||||||
|
Label="EAN"
|
||||||
|
Immediate="true"
|
||||||
|
DebounceInterval="500"
|
||||||
|
OnDebounceIntervalElapsed="SearchProducts"
|
||||||
|
Clearable="true"/>
|
||||||
|
</div>
|
||||||
|
@if (ScannerService.IsAvailable)
|
||||||
|
{
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.CameraAlt"
|
||||||
|
Color="Color.Primary"
|
||||||
|
OnClick="OnScannerClick"
|
||||||
|
Variant="Variant.Filled"
|
||||||
|
Size="Size.Medium"
|
||||||
|
Title="Skanuj kod EAN"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</MudItem>
|
||||||
|
|
||||||
|
<MudItem xs="12" sm="6" md="4">
|
||||||
|
<MudButton Variant="Variant.Outlined"
|
||||||
|
OnClick="ClearFilters"
|
||||||
|
StartIcon="Icons.Material.Filled.Clear">
|
||||||
|
Wyczyść filtry
|
||||||
|
</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudExpansionPanel>
|
||||||
|
</MudExpansionPanels>
|
||||||
|
|
||||||
|
<MudDivider Class="my-4"></MudDivider>
|
||||||
|
|
||||||
|
<MudTable Items="products.Items"
|
||||||
|
Dense="true"
|
||||||
|
Hover="true"
|
||||||
|
Loading="isLoading"
|
||||||
|
LoadingProgressColor="Color.Info">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Nazwa</MudTh>
|
||||||
|
<MudTh>Kod</MudTh>
|
||||||
|
<MudTh>EAN</MudTh>
|
||||||
|
<MudTh>Akcje</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd DataLabel="Nazwa">@context.Name</MudTd>
|
||||||
|
<MudTd DataLabel="Kod">@context.Code.Trim()</MudTd>
|
||||||
|
<MudTd DataLabel="EAN"></MudTd>
|
||||||
|
<MudTd DataLabel="Akcje">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
||||||
|
Size="Size.Small"
|
||||||
|
OnClick="() => EditProduct(context.Id)"/>
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||||
|
Size="Size.Small"
|
||||||
|
Color="Color.Error"
|
||||||
|
OnClick="() => DeleteProduct(context.Id)"/>
|
||||||
|
</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
<NoRecordsContent>
|
||||||
|
<MudText>Brak produktów do wyświetlenia</MudText>
|
||||||
|
</NoRecordsContent>
|
||||||
|
<LoadingContent>
|
||||||
|
Ładowanie...
|
||||||
|
</LoadingContent>
|
||||||
|
</MudTable>
|
||||||
|
|
||||||
|
@if (products.TotalCount > 0)
|
||||||
|
{
|
||||||
|
<MudGrid Class="mt-4" AlignItems="Center.Center">
|
||||||
|
<MudItem xs="12" sm="6">
|
||||||
|
<MudText Typo="Typo.body2">
|
||||||
|
Wyniki @((products.Page - 1) * products.PageSize + 1) - @Math.Min(products.Page * products.PageSize, products.TotalCount)
|
||||||
|
z @products.TotalCount
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" sm="6" Class="d-flex justify-end">
|
||||||
|
<MudPagination Count="products.TotalPages"
|
||||||
|
Selected="products.Page"
|
||||||
|
SelectedChanged="OnPageChanged"
|
||||||
|
ShowFirstButton="true"
|
||||||
|
ShowLastButton="true"/>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
}
|
||||||
104
BimAI.UI.Shared/Components/ProductListComponent.razor.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using BimAI.UI.Shared.Interfaces;
|
||||||
|
using BimAI.UI.Shared.Services;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Components;
|
||||||
|
|
||||||
|
public partial class ProductListComponent : ComponentBase
|
||||||
|
{
|
||||||
|
[Inject] private ProductService ProductService { get; set; } = default!;
|
||||||
|
[Inject] private IScannerService ScannerService { get; set; } = default!;
|
||||||
|
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
||||||
|
|
||||||
|
|
||||||
|
private PagedResult<ProductDto> products = new();
|
||||||
|
private ProductFilterRequest filterRequest = new();
|
||||||
|
private bool isLoading = false;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await LoadProducts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadProducts()
|
||||||
|
{
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
products = await ProductService.GetProductsAsync(filterRequest);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading products failed: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SearchProducts()
|
||||||
|
{
|
||||||
|
filterRequest.Page = 1;
|
||||||
|
await LoadProducts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnPageChanged(int page)
|
||||||
|
{
|
||||||
|
filterRequest.Page = page;
|
||||||
|
await LoadProducts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ClearFilters()
|
||||||
|
{
|
||||||
|
filterRequest = new ProductFilterRequest();
|
||||||
|
await LoadProducts();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task EditProduct(Guid productId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Console.WriteLine($"Edytuj produkt: {productId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteProduct(Guid productId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Console.WriteLine($"Usuń produkt: {productId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetScannerIcon()
|
||||||
|
{
|
||||||
|
return ScannerService.IsAvailable ? Icons.Material.Filled.CameraAlt : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnScannerClick()
|
||||||
|
{
|
||||||
|
if (!ScannerService.IsAvailable)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Skaner nie jest dostępny na tej platformie", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var scannedCode = await ScannerService.ScanBarcodeAsync();
|
||||||
|
if (!string.IsNullOrEmpty(scannedCode))
|
||||||
|
{
|
||||||
|
filterRequest.Ean = scannedCode;
|
||||||
|
await SearchProducts();
|
||||||
|
Snackbar.Add($"Zeskanowano kod: {scannedCode}", Severity.Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Scanner error: {ex.Message}");
|
||||||
|
Snackbar.Add("Błąd podczas skanowania", Severity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
BimAI.UI.Shared/EmptyLayout.razor
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<MudThemeProvider/>
|
||||||
|
<MudDialogProvider/>
|
||||||
|
<MudSnackbarProvider/>
|
||||||
|
|
||||||
|
|
||||||
|
@Body
|
||||||
23
BimAI.UI.Shared/Extensions/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using BimAI.UI.Shared.Services;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Extensions;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddSharedServices(this IServiceCollection services, string apiBaseUrl)
|
||||||
|
{
|
||||||
|
services.AddHttpClient<ProductService>(client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri(apiBaseUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddHttpClient<InvoiceService>(client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri(apiBaseUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
BimAI.UI.Shared/Interfaces/IScannerService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace BimAI.UI.Shared.Interfaces;
|
||||||
|
|
||||||
|
public interface IScannerService
|
||||||
|
{
|
||||||
|
bool IsAvailable { get; }
|
||||||
|
Task<bool> RequestCameraPermissionsAsync();
|
||||||
|
Task<string?> ScanBarcodeAsync();
|
||||||
|
|
||||||
|
}
|
||||||
71
BimAI.UI.Shared/MainLayout.razor
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
@using MudBlazor
|
||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<AuthGuard>
|
||||||
|
<MudThemeProvider/>
|
||||||
|
<MudDialogProvider/>
|
||||||
|
<MudSnackbarProvider/>
|
||||||
|
<MudPopoverProvider />
|
||||||
|
|
||||||
|
<MudLayout>
|
||||||
|
<MudBreakpointProvider OnBreakpointChanged="OnBreakpointChanged"></MudBreakpointProvider>
|
||||||
|
<MudAppBar Elevation="0">
|
||||||
|
<MudIconButton
|
||||||
|
Icon="@Icons.Material.Filled.Menu"
|
||||||
|
Color="Color.Inherit"
|
||||||
|
Edge="Edge.Start"
|
||||||
|
OnClick="ToggleDrawer"
|
||||||
|
Class="mud-hidden-md-up"/>
|
||||||
|
<MudSpacer/>
|
||||||
|
<MudText Typo="Typo.h6">BimAI</MudText>
|
||||||
|
</MudAppBar>
|
||||||
|
|
||||||
|
<MudDrawer @bind-Open="_drawerOpen"
|
||||||
|
Anchor="Anchor.Start"
|
||||||
|
Variant="@_drawerVariant"
|
||||||
|
Elevation="1"
|
||||||
|
ClipMode="DrawerClipMode.Always"
|
||||||
|
Class="mud-width-250">
|
||||||
|
<MudNavMenu>
|
||||||
|
<MudNavLink Href="/dashboard" Icon="@Icons.Material.Filled.Dashboard">Dashboard</MudNavLink>
|
||||||
|
<MudNavLink Href="/products" Icon="@Icons.Material.Filled.Inventory">Products</MudNavLink>
|
||||||
|
<MudNavLink Href="/invoices" Icon="@Icons.Material.Filled.FilePresent">Invoices</MudNavLink>
|
||||||
|
</MudNavMenu>
|
||||||
|
</MudDrawer>
|
||||||
|
|
||||||
|
<MudMainContent>
|
||||||
|
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge" Class="my-4">
|
||||||
|
@Body
|
||||||
|
</MudContainer>
|
||||||
|
</MudMainContent>
|
||||||
|
</MudLayout>
|
||||||
|
</AuthGuard>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
private bool _drawerOpen = true;
|
||||||
|
private DrawerVariant _drawerVariant = DrawerVariant.Persistent;
|
||||||
|
|
||||||
|
void ToggleDrawer()
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ToogleDrawer clickkk {DateTime.Now}");
|
||||||
|
_drawerOpen = !_drawerOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBreakpointChanged(Breakpoint breakpoint)
|
||||||
|
{
|
||||||
|
if (breakpoint < Breakpoint.Md)
|
||||||
|
{
|
||||||
|
_drawerVariant = DrawerVariant.Temporary;
|
||||||
|
_drawerOpen = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_drawerVariant = DrawerVariant.Persistent;
|
||||||
|
_drawerOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
BimAI.UI.Shared/Pages/InvoiceListPage.razor
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@page "/invoices"
|
||||||
|
@using BimAI.UI.Shared.Components
|
||||||
|
|
||||||
|
<PageTitle>Faktury</PageTitle>
|
||||||
|
|
||||||
|
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge">
|
||||||
|
<InvoiceListComponent />
|
||||||
|
</MudContainer>
|
||||||
46
BimAI.UI.Shared/Pages/LoginPage.razor
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
@page "/login"
|
||||||
|
@layout EmptyLayout
|
||||||
|
|
||||||
|
<div class="login-page">
|
||||||
|
<div class="login-container">
|
||||||
|
<LoginCard />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: 100% !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
height: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-page {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url('_content/BimAI.UI.Shared/images/login-background.jpg') no-repeat center;
|
||||||
|
background-size: cover;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-container {
|
||||||
|
padding: 20px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 450px;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
8
BimAI.UI.Shared/Pages/ProductListPage.razor
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@page "/products"
|
||||||
|
@using BimAI.UI.Shared.Components
|
||||||
|
|
||||||
|
<PageTitle>Produkty</PageTitle>
|
||||||
|
|
||||||
|
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge">
|
||||||
|
<ProductListComponent />
|
||||||
|
</MudContainer>
|
||||||
113
BimAI.UI.Shared/Services/AuthService.cs
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Services;
|
||||||
|
|
||||||
|
public class UserInfo
|
||||||
|
{
|
||||||
|
public string FullName { get; set; } = string.Empty;
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
public string AvatarUrl { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
public class AuthService
|
||||||
|
{
|
||||||
|
private readonly IJSRuntime _jsRuntime;
|
||||||
|
private bool? _isAuthenticated;
|
||||||
|
private UserInfo? _userInfo = null;
|
||||||
|
|
||||||
|
public event Action<bool>? AuthenticationStateChanged;
|
||||||
|
|
||||||
|
public AuthService(IJSRuntime jsRuntime)
|
||||||
|
{
|
||||||
|
_jsRuntime = jsRuntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAuthenticated => _isAuthenticated ?? false;
|
||||||
|
public UserInfo? CurrentUser => _userInfo;
|
||||||
|
|
||||||
|
public async Task<bool> CheckAuthenticationAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var token = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", "google_token");
|
||||||
|
var userInfoJson = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", "user_info");
|
||||||
|
|
||||||
|
_isAuthenticated = !string.IsNullOrEmpty(token);
|
||||||
|
|
||||||
|
if (_isAuthenticated.Value && !string.IsNullOrEmpty(userInfoJson))
|
||||||
|
{
|
||||||
|
_userInfo = JsonSerializer.Deserialize<UserInfo>(userInfoJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"AuthService.CheckAuthentication: token={(!string.IsNullOrEmpty(token) ? "EXISTS" : "NULL")}, isAuth={_isAuthenticated}");
|
||||||
|
|
||||||
|
return _isAuthenticated.Value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"AuthService.CheckAuthentication ERROR: {ex.Message}");
|
||||||
|
_isAuthenticated = false;
|
||||||
|
_userInfo = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SetAuthenticationAsync(string token, UserInfo? userInfo = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "google_token", token);
|
||||||
|
|
||||||
|
if (userInfo != null)
|
||||||
|
{
|
||||||
|
_userInfo = userInfo;
|
||||||
|
var userInfoJson = JsonSerializer.Serialize(userInfo);
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "user_info", userInfoJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
_isAuthenticated = true;
|
||||||
|
Console.WriteLine($"AuthService.SetAuthentication: token saved, user={_userInfo?.Email}");
|
||||||
|
AuthenticationStateChanged?.Invoke(true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"AuthService.SetAuthentication ERROR: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ClearAuthenticationAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", "google_token");
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", "user_info");
|
||||||
|
_isAuthenticated = false;
|
||||||
|
_userInfo = null;
|
||||||
|
Console.WriteLine($"AuthService.ClearAuthentication: token and user ingfo removed");
|
||||||
|
AuthenticationStateChanged?.Invoke(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"AuthService.ClearAuthentication ERROR: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string?> GetTokenAsync()
|
||||||
|
{
|
||||||
|
if (_isAuthenticated != true)
|
||||||
|
{
|
||||||
|
await CheckAuthenticationAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isAuthenticated != true) return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", "google_token");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
BimAI.UI.Shared/Services/GoogleAuthConfig.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace BimAI.UI.Shared.Services;
|
||||||
|
|
||||||
|
// TODO it's a good place for this file?
|
||||||
|
public class GoogleAuthConfig
|
||||||
|
{
|
||||||
|
public string ClientId { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
73
BimAI.UI.Shared/Services/InvoiceService.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Services;
|
||||||
|
|
||||||
|
public class InvoiceService(HttpClient httpClient)
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient = httpClient;
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
public async Task<PagedResult<InvoiceDto>> GetInvoiceAsync(InvoiceFilterRequest request)
|
||||||
|
{
|
||||||
|
var queryParams = new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
["page"] = request.Page.ToString(),
|
||||||
|
["pageSize"] = request.PageSize.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Search))
|
||||||
|
{
|
||||||
|
queryParams["search"] = request.Search;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.ClientName))
|
||||||
|
{
|
||||||
|
queryParams["clientName"] = request.ClientName;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Type))
|
||||||
|
{
|
||||||
|
queryParams["type"] = request.Type;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.DocumentNo))
|
||||||
|
{
|
||||||
|
queryParams["documentNo"] = request.DocumentNo;
|
||||||
|
}
|
||||||
|
if (request.RegisterDateFrom.HasValue)
|
||||||
|
{
|
||||||
|
queryParams["registerDateFrom"] = request.RegisterDateFrom.Value.ToString("yyyy-MM-dd");;
|
||||||
|
}
|
||||||
|
if (request.RegisterDateTo.HasValue)
|
||||||
|
{
|
||||||
|
queryParams["registerDateTo"] = request.RegisterDateTo.Value.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
if (request.SellDateFrom.HasValue)
|
||||||
|
{
|
||||||
|
queryParams["sellDateFrom"] = request.SellDateFrom.Value.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
if (request.SellDateTo.HasValue)
|
||||||
|
{
|
||||||
|
queryParams["sellDateTo"] = request.SellDateTo.Value.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
var uri = QueryHelpers.AddQueryString("api/invoice", queryParams);
|
||||||
|
|
||||||
|
var response = await _httpClient.GetAsync(uri);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var errorContent = await response.Content.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
var result = JsonSerializer.Deserialize<PagedResult<InvoiceDto>>(json, _jsonOptions);
|
||||||
|
|
||||||
|
return result ?? new PagedResult<InvoiceDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
BimAI.UI.Shared/Services/NoOpScannerService.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using BimAI.UI.Shared.Interfaces;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Services;
|
||||||
|
|
||||||
|
public class NoOpScannerService : IScannerService
|
||||||
|
{
|
||||||
|
public bool IsAvailable => false;
|
||||||
|
public Task<string?> ScanBarcodeAsync()
|
||||||
|
{
|
||||||
|
return Task.FromResult<string?>(null);
|
||||||
|
}
|
||||||
|
public Task<bool> RequestCameraPermissionsAsync()
|
||||||
|
{
|
||||||
|
return Task.FromResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
52
BimAI.UI.Shared/Services/ProductService.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using BimAI.Application.DTOModels;
|
||||||
|
using BimAI.Application.DTOModels.Common;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace BimAI.UI.Shared.Services;
|
||||||
|
|
||||||
|
public class ProductService(HttpClient httpClient)
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient = httpClient;
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
public async Task<PagedResult<ProductDto>> GetProductsAsync(ProductFilterRequest request)
|
||||||
|
{
|
||||||
|
var queryParams = new Dictionary<string, string?>
|
||||||
|
{
|
||||||
|
["page"] = request.Page.ToString(),
|
||||||
|
["pageSize"] = request.PageSize.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Search))
|
||||||
|
{
|
||||||
|
queryParams["search"] = request.Search;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Name))
|
||||||
|
{
|
||||||
|
queryParams["name"] = request.Name;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Code))
|
||||||
|
{
|
||||||
|
queryParams["code"] = request.Code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.Ean))
|
||||||
|
{
|
||||||
|
queryParams["ean"] = request.Ean;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uri = QueryHelpers.AddQueryString("api/products", queryParams);
|
||||||
|
var response = await _httpClient.GetAsync(uri);
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
var result = JsonSerializer.Deserialize<PagedResult<ProductDto>>(json, _jsonOptions);
|
||||||
|
|
||||||
|
return result ?? new PagedResult<ProductDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
@using System.Net.Http
|
@using System.Net.Http
|
||||||
@using System.Net.Http.Json
|
@using System.Net.Http.Json
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using Bimix.UI.Web
|
@using BimAI.UI.Shared
|
||||||
@using Bimix.UI.Web.Components
|
@using MudBlazor@using BimAI.Application.DTOModels
|
||||||
@using Bimix.UI.Shared
|
@using BimAI.Application.DTOModels.Common
|
||||||
@using Bimix.UI.Shared.Components
|
@using BimAI.UI.Shared.Components
|
||||||
@using MudBlazor
|
|
||||||
BIN
BimAI.UI.Shared/wwwroot/images/login-background.jpg
Normal file
|
After Width: | Height: | Size: 965 KiB |
119
BimAI.UI.Shared/wwwroot/js/auth.js
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
let googleClient = null;
|
||||||
|
let isSigningIn = false;
|
||||||
|
|
||||||
|
function waitForGoogleApi() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (window.google?.accounts?.oauth2) {
|
||||||
|
resolve(window.google);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxAttempts = 20;
|
||||||
|
let attempts = 0;
|
||||||
|
|
||||||
|
const checkGoogle = setInterval(() => {
|
||||||
|
attempts++;
|
||||||
|
if (window.google?.accounts?.oauth2) {
|
||||||
|
clearInterval(checkGoogle);
|
||||||
|
resolve(window.google);
|
||||||
|
} else if (attempts >= maxAttempts) {
|
||||||
|
clearInterval(checkGoogle);
|
||||||
|
reject(new Error('Google OAuth2 API failed to load within the timeout period'));
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAuthError(error, context = '') {
|
||||||
|
const errorMessage = error?.message || error?.type || error?.toString() || 'Unknown error';
|
||||||
|
const fullError = `${context}: ${errorMessage}`;
|
||||||
|
console.error('Google Auth Error:', { context, error, fullError });
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError', fullError);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUserInfo(accessToken) {
|
||||||
|
const response = await fetch('https://www.googleapis.com/oauth2/v3/userinfo', {
|
||||||
|
headers: { 'Authorization': `Bearer ${accessToken}` }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
console.error('Failed to fetch user info:', errorText);
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
`Failed to fetch user info: HTTP ${response.status}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.initGoogleSignIn = async function(clientId) {
|
||||||
|
if (googleClient) {
|
||||||
|
return googleClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const google = await waitForGoogleApi();
|
||||||
|
|
||||||
|
googleClient = google.accounts.oauth2.initTokenClient({
|
||||||
|
client_id: clientId,
|
||||||
|
scope: 'email profile',
|
||||||
|
callback: async (tokenResponse) => {
|
||||||
|
try {
|
||||||
|
if (tokenResponse.error) {
|
||||||
|
console.error('Token response error:', tokenResponse.error);
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
tokenResponse.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userInfo = await fetchUserInfo(tokenResponse.access_token);
|
||||||
|
if (!userInfo) return;
|
||||||
|
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInSuccess',
|
||||||
|
tokenResponse.access_token,
|
||||||
|
userInfo.name || '',
|
||||||
|
userInfo.email || '',
|
||||||
|
userInfo.picture || ''
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Callback error:', error);
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
error.message || 'Unknown callback error');
|
||||||
|
} finally {
|
||||||
|
isSigningIn = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error_callback: async (error) => {
|
||||||
|
console.error('OAuth flow error:', error);
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
error.type || 'OAuth flow error');
|
||||||
|
isSigningIn = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return googleClient;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Initiaxcrun xctrace list deviceslization error:', error);
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
error.message || 'Failed to initialize Google Sign-In');
|
||||||
|
isSigningIn = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.requestGoogleSignIn = async function() {
|
||||||
|
if (isSigningIn) {
|
||||||
|
console.log('Sign-in already in progress');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!googleClient) {
|
||||||
|
console.error('Google Sign-In not initialized');
|
||||||
|
await DotNet.invokeMethodAsync('BimAI.UI.Shared', 'OnGoogleSignInError',
|
||||||
|
'Google Sign-In not initialized. Call initGoogleSignIn first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isSigningIn = true;
|
||||||
|
googleClient.requestAccessToken();
|
||||||
|
};
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Bimix.UI.Shared\Bimix.UI.Shared.csproj" />
|
<ProjectReference Include="..\BimAI.UI.Shared\BimAI.UI.Shared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -8,13 +8,13 @@
|
|||||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
||||||
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||||
<link href="Bimix.UI.Web.styles.css" rel="stylesheet" />
|
<link href="BimAI.UI.Web.styles.css" rel="stylesheet" />
|
||||||
|
<script src="https://accounts.google.com/gsi/client" async defer></script>
|
||||||
<HeadOutlet />
|
<HeadOutlet />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<Bimix.UI.Shared.Components.Routes @rendermode="InteractiveServer" />
|
<BimAI.UI.Shared.Components.Routes @rendermode="InteractiveServer" />
|
||||||
|
|
||||||
|
|
||||||
<div id="blazor-error-ui">
|
<div id="blazor-error-ui">
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
<script src="_framework/blazor.web.js"></script>
|
<script src="_framework/blazor.web.js"></script>
|
||||||
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
||||||
|
<script src="_content/BimAI.UI.Shared/js/auth.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||