Compare commits
No commits in common. "master" and "fix-orders-issues" have entirely different histories.
master
...
fix-orders
1822 changed files with 60349 additions and 108296 deletions
|
|
@ -1,6 +0,0 @@
|
|||
# Browsers that we support
|
||||
|
||||
last 3 version
|
||||
> 0.3%
|
||||
not dead # no browsers without security updates
|
||||
not Firefox < 100
|
||||
|
|
@ -1,11 +1,2 @@
|
|||
.git/
|
||||
.gitlab/
|
||||
.gitlab-ci.yml
|
||||
.git
|
||||
*.md
|
||||
.vscode/
|
||||
auth.json
|
||||
Dockerfile
|
||||
manifest.yaml
|
||||
node_modules/
|
||||
production-resources.yaml
|
||||
.env.example
|
||||
|
|
|
|||
|
|
@ -3,33 +3,13 @@ root = true
|
|||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{php,json}]
|
||||
indent_size = 4
|
||||
|
||||
[*.blade.php]
|
||||
indent_size = 2
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[{compose,docker-compose}.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[*.scss]
|
||||
indent_size = 2
|
||||
quote_type = single
|
||||
|
||||
[*.css]
|
||||
indent_size = 2
|
||||
quote_type = single
|
||||
|
||||
[*.vue]
|
||||
indent_size = 2
|
||||
|
|
|
|||
33
.env.example
33
.env.example
|
|
@ -3,7 +3,6 @@ APP_ENV=local
|
|||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
APP_CURRENCY=EUR
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_LEVEL=debug
|
||||
|
|
@ -16,24 +15,22 @@ DB_USERNAME=root
|
|||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_STORE=file
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
MAIL_MAILER=log
|
||||
MAIL_SCHEME=null
|
||||
MAIL_HOST=127.0.0.1
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_USERNAME=
|
||||
MAIL_PASSWORD=
|
||||
MAIL_ENCRYPTION=
|
||||
MAIL_FROM_ADDRESS=
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
MAIL_TO_CONTACT=
|
||||
MAIL_TO_REGATE=
|
||||
MAIL_LIST_SERVICEWEB=
|
||||
MAIL_LIST_INVALIDINCO=
|
||||
|
||||
# CRM
|
||||
CRM_ENDPOINT=
|
||||
|
|
@ -51,15 +48,3 @@ MATOMO_SITE_ID=
|
|||
UWIL_ADMIN_SECURE_CIDR_LIST=""
|
||||
# - LIST SEPARATED WITH ',' (Optional)
|
||||
UWIL_ADMIN_SECURE_CIDR_PROJECT_ALLOWED_LIST=""
|
||||
|
||||
# Arcadia API
|
||||
ARCADIA_API_ENDPOINT=
|
||||
ARCADIA_API_APIKEY=
|
||||
ARCADIA_API_SECRET=
|
||||
ARCADIA_API_IGNORE_SELF_SIGNED_CERT=false
|
||||
|
||||
# Serial Caster
|
||||
SERIAL_CASTER_SEED=12345
|
||||
|
||||
# LDC
|
||||
LDC_HEADQUARTERS_PHONE_RECEPTION="02 43 62 70 00"
|
||||
|
|
|
|||
14
.gitattributes
vendored
14
.gitattributes
vendored
|
|
@ -1,11 +1,5 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
* text=auto
|
||||
*.css linguist-vendored
|
||||
*.scss linguist-vendored
|
||||
*.js linguist-vendored
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
|
|
|||
53
.gitignore
vendored
53
.gitignore
vendored
|
|
@ -1,51 +1,22 @@
|
|||
.env
|
||||
.env.testing
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
.stylelintcache
|
||||
/.fleet
|
||||
/.idea
|
||||
/.phpunit.cache
|
||||
/.vscode
|
||||
/node_modules
|
||||
/bootstrap/cache
|
||||
/public/build
|
||||
/public/cache
|
||||
/public/hot
|
||||
/public/sitemap.xml
|
||||
/public/storage
|
||||
/public/images/content
|
||||
/public/images/gammes
|
||||
/public/images/produits
|
||||
/public/images/slides
|
||||
/public/b-o/
|
||||
/public/mix-manifest.json
|
||||
/storage/*.key
|
||||
/vendor
|
||||
coverage/
|
||||
auth.json
|
||||
docker-compose.override.yml
|
||||
.env
|
||||
.env.backup
|
||||
.env.dev
|
||||
.env.prod
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
auth.json
|
||||
.npmrc
|
||||
js.save
|
||||
phpstan-report.xml
|
||||
|
||||
# Ignore public favicon
|
||||
/public/android-chrome-192x192.png
|
||||
/public/android-chrome-512x512.png
|
||||
/public/apple-touch-icon.png
|
||||
/public/browserconfig.xml
|
||||
/public/browserconfig.xml
|
||||
/public/favicon-16x16.png
|
||||
/public/favicon-32x32.png
|
||||
/public/favicon.ico
|
||||
/public/mstile-150x150.png
|
||||
/public/safari-pinned-tab.svg
|
||||
/public/site.webmanifest
|
||||
/public/files
|
||||
|
||||
develop
|
||||
_ide_helper.php
|
||||
.phpstorm.meta.php
|
||||
phpstan-report.xml
|
||||
|
||||
// Ignore PHPUnit cache files
|
||||
cache
|
||||
|
|
|
|||
347
.gitlab-ci.yml
347
.gitlab-ci.yml
|
|
@ -1,328 +1,23 @@
|
|||
stages:
|
||||
- install
|
||||
- lint
|
||||
- test
|
||||
- security
|
||||
- build
|
||||
- deploy
|
||||
|
||||
include:
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "security/composer.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "build/composer.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "build/docker-multistage.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "test/test.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "deploy/deploy.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "lint/lint7.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "security/security7.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "build/build7.3.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "test/test.yml"
|
||||
- project: "ldc-web/shared-ci"
|
||||
ref: "main"
|
||||
file: "deploy/deploy.yml"
|
||||
|
||||
# * LINT --------------------------------------------------------------------
|
||||
|
||||
.php-lint-base: &php-lint-base
|
||||
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
||||
variables:
|
||||
COMPOSER_CACHE_DIR: ".composer-cache"
|
||||
cache:
|
||||
key:
|
||||
files:
|
||||
- composer.lock
|
||||
prefix: "composer"
|
||||
policy: pull
|
||||
paths:
|
||||
- .composer-cache/
|
||||
- vendor/
|
||||
before_script:
|
||||
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
||||
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "develop"
|
||||
|
||||
parallel-lint:
|
||||
<<: *php-lint-base
|
||||
stage: lint
|
||||
script:
|
||||
- vendor/bin/parallel-lint --exclude vendor --exclude storage --exclude bootstrap --exclude node_modules .
|
||||
allow_failure: false
|
||||
|
||||
pint:
|
||||
<<: *php-lint-base
|
||||
stage: lint
|
||||
script:
|
||||
- vendor/bin/pint --test
|
||||
allow_failure: false
|
||||
|
||||
phpcs:
|
||||
<<: *php-lint-base
|
||||
stage: lint
|
||||
script:
|
||||
- vendor/bin/phpcs --standard=phpcs.xml --extensions=php --ignore=vendor/*,storage/*,bootstrap/*,node_modules/* --report=junit --report-file=phpcs-report.xml
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'phpcs'
|
||||
paths:
|
||||
- phpcs-report.xml
|
||||
reports:
|
||||
junit: phpcs-report.xml
|
||||
allow_failure: false
|
||||
|
||||
phpstan:
|
||||
<<: *php-lint-base
|
||||
stage: lint
|
||||
variables:
|
||||
PHP_MEMORY_LIMIT: "512M"
|
||||
COMPOSER_CACHE_DIR: ".composer-cache"
|
||||
script:
|
||||
- php -d memory_limit=512M vendor/bin/phpstan --error-format=junit > phpstan-report.xml
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'phpstan'
|
||||
paths:
|
||||
- phpstan-report.xml
|
||||
reports:
|
||||
junit: phpstan-report.xml
|
||||
allow_failure: false
|
||||
|
||||
eslint:
|
||||
stage: lint
|
||||
image: oven/bun:1
|
||||
variables:
|
||||
BUN_INSTALL_CACHE_DIR: ".bun-cache"
|
||||
cache:
|
||||
key:
|
||||
files:
|
||||
- bun.lock
|
||||
prefix: "bun"
|
||||
policy: pull
|
||||
paths:
|
||||
- .bun-cache/
|
||||
before_script:
|
||||
- echo "@ldc-web:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/" >> .npmrc
|
||||
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc
|
||||
- echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- bun install --no-save
|
||||
script:
|
||||
- bun run eslint-ci --quiet --output-file=eslint-junit.xml
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'eslint'
|
||||
paths:
|
||||
- eslint-junit.xml
|
||||
reports:
|
||||
junit: eslint-junit.xml
|
||||
allow_failure: false
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "develop"
|
||||
|
||||
stylelint:
|
||||
stage: lint
|
||||
image: oven/bun:1
|
||||
variables:
|
||||
BUN_INSTALL_CACHE_DIR: ".bun-cache"
|
||||
cache:
|
||||
key:
|
||||
files:
|
||||
- bun.lock
|
||||
prefix: "bun"
|
||||
policy: pull
|
||||
paths:
|
||||
- .bun-cache/
|
||||
before_script:
|
||||
- echo "@ldc-web:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/" >> .npmrc
|
||||
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc
|
||||
- echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- bun install --no-save
|
||||
script:
|
||||
- bun run stylelint-ci --quiet --output-file=stylelint-junit.xml
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'stylelint'
|
||||
paths:
|
||||
- stylelint-junit.xml
|
||||
reports:
|
||||
junit: stylelint-junit.xml
|
||||
allow_failure: false
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "develop"
|
||||
|
||||
# * TESTS -------------------------------------------------------------------
|
||||
|
||||
bun-build-test:
|
||||
stage: test
|
||||
image: oven/bun:1
|
||||
variables:
|
||||
BUN_INSTALL_CACHE_DIR: ".bun-cache"
|
||||
cache:
|
||||
key:
|
||||
files:
|
||||
- bun.lock
|
||||
prefix: "bun"
|
||||
policy: pull
|
||||
paths:
|
||||
- .bun-cache/
|
||||
before_script:
|
||||
- echo "@ldc-web:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/" >> .npmrc
|
||||
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc
|
||||
- echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- bun install --no-save
|
||||
script:
|
||||
- timeout 300 bun run prod
|
||||
artifacts:
|
||||
expose_as: 'front-build-test'
|
||||
paths:
|
||||
- public/build/manifest.json
|
||||
allow_failure: false
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_TAG != null
|
||||
|
||||
tests_front:
|
||||
stage: test
|
||||
image: oven/bun:1
|
||||
variables:
|
||||
BUN_INSTALL_CACHE_DIR: ".bun-cache"
|
||||
cache:
|
||||
key:
|
||||
files:
|
||||
- bun.lock
|
||||
prefix: "bun"
|
||||
policy: pull
|
||||
paths:
|
||||
- .bun-cache/
|
||||
before_script:
|
||||
- echo "@ldc-web:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/" >> .npmrc
|
||||
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc
|
||||
- echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- bun install --no-save
|
||||
script:
|
||||
- bun run test:unit
|
||||
artifacts:
|
||||
when: always
|
||||
expose_as: 'vitest'
|
||||
paths:
|
||||
- coverage/junit-vitest.xml
|
||||
reports:
|
||||
junit: coverage/junit-vitest.xml
|
||||
allow_failure: false
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_TAG != null
|
||||
|
||||
tests_laravel:
|
||||
stage: test
|
||||
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
||||
allow_failure: false
|
||||
variables:
|
||||
COMPOSER_CACHE_DIR: ".composer-cache"
|
||||
# MYSQL SERVICE VARS
|
||||
MYSQL_DATABASE: testing_db
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
|
||||
# LARAVEL VARS
|
||||
DB_CONNECTION: mysql
|
||||
DB_HOST: mysql
|
||||
DB_PORT: 3306
|
||||
DB_DATABASE: testing_db
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: password
|
||||
cache:
|
||||
- key:
|
||||
files:
|
||||
- composer.lock
|
||||
prefix: "composer"
|
||||
policy: pull
|
||||
paths:
|
||||
- .composer-cache/
|
||||
- vendor/
|
||||
services:
|
||||
- name: mysql:8.0
|
||||
alias: mysql
|
||||
before_script:
|
||||
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
||||
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
|
||||
script:
|
||||
- cp .env.example .env
|
||||
- php artisan key:generate
|
||||
- php -r "while(true){try{new PDO('mysql:host=mysql;dbname=testing_db','root','password');break;}catch(Exception){sleep(1);}}"
|
||||
- php artisan config:clear
|
||||
- php artisan test --coverage --colors=never --log-junit=coverage/junit.xml --coverage-cobertura=coverage/cobertura.xml --coverage-html=coverage/html
|
||||
after_script:
|
||||
- if [ "$CI_JOB_STATUS" == "failed" ]; then cat storage/logs/laravel.log; fi
|
||||
artifacts:
|
||||
when: always
|
||||
expose_as: 'coverage'
|
||||
paths:
|
||||
- coverage/html/
|
||||
reports:
|
||||
junit: coverage/junit.xml
|
||||
coverage_report:
|
||||
coverage_format: cobertura
|
||||
path: coverage/cobertura.xml
|
||||
coverage: '/^\s*Total:\s*([\d\.]+)%/'
|
||||
needs:
|
||||
- job: bun-build-test
|
||||
optional: false
|
||||
artifacts: true
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_TAG != null
|
||||
|
||||
# * SECURITY ----------------------------------------------------------------
|
||||
|
||||
bun-security:
|
||||
stage: security
|
||||
image: oven/bun:1
|
||||
before_script:
|
||||
- echo "@ldc-web:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/" >> .npmrc
|
||||
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
- echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc
|
||||
- echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${CI_DEPLOY_PASSWORD}" >> .npmrc
|
||||
script:
|
||||
- bun audit --json > bun-security-checker-report.json
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'bun-security-checker'
|
||||
paths:
|
||||
- bun-security-checker-report.json
|
||||
allow_failure: true
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_TAG != null
|
||||
|
||||
# * BUILD -------------------------------------------------------------------
|
||||
|
||||
npm-build:
|
||||
stage: build
|
||||
script:
|
||||
- echo "Frontend is built directly within Docker multi-stage build"
|
||||
|
||||
npm-security:
|
||||
stage: security
|
||||
script:
|
||||
- echo "Npm security would run bun security"
|
||||
dependencies:
|
||||
- bun-security
|
||||
needs:
|
||||
- job: bun-security
|
||||
optional: true
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
- if: $CI_COMMIT_BRANCH == "trunk" || $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_TAG != null
|
||||
stages:
|
||||
- lint
|
||||
- security
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@
|
|||
|
||||
|
||||
## Étapes pour la reproduction du bug
|
||||
*
|
||||
*
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -5,5 +5,9 @@ php:
|
|||
finder:
|
||||
not-name:
|
||||
- index.php
|
||||
js: true
|
||||
- server.php
|
||||
js:
|
||||
finder:
|
||||
not-name:
|
||||
- webpack.mix.js
|
||||
css: true
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
{
|
||||
"extends": [
|
||||
"stylelint-config-standard-scss",
|
||||
"stylelint-config-sass-guidelines",
|
||||
"stylelint-config-idiomatic-order"
|
||||
],
|
||||
"plugins": [
|
||||
"stylelint-scss"
|
||||
],
|
||||
"files": [
|
||||
"**/*.css",
|
||||
"**/*.scss"
|
||||
],
|
||||
"ignoreFiles": [
|
||||
"**/vendor/*.css",
|
||||
"**/vendor/**/*.css",
|
||||
"**/vendor/*.scss",
|
||||
"**/vendor/**/*.scss",
|
||||
"**/vendor/*.sass",
|
||||
"**/vendor/**/*.sass",
|
||||
"**/vendor/*.less",
|
||||
"**/vendor/**/*.less"
|
||||
],
|
||||
"customSyntax": "postcss-scss",
|
||||
"rules": {
|
||||
"declaration-property-value-no-unknown": true,
|
||||
"selector-max-id": null,
|
||||
"color-no-invalid-hex": true,
|
||||
"order/properties-alphabetical-order": null,
|
||||
"max-nesting-depth": 5,
|
||||
"selector-max-compound-selectors": 5,
|
||||
"scss/double-slash-comment-empty-line-before": [
|
||||
"always",
|
||||
{
|
||||
"ignore": [
|
||||
"between-comments",
|
||||
"stylelint-commands",
|
||||
"inside-block"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
95
.vscode/settings.json
vendored
95
.vscode/settings.json
vendored
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#920c7f",
|
||||
"activityBar.activeBorder": "#e7e7e7",
|
||||
"activityBar.activeBorder": "#1a1d02",
|
||||
"activityBar.background": "#920c7f",
|
||||
"activityBar.foreground": "#e7e7e7",
|
||||
"activityBar.inactiveForeground": "#e7e7e799",
|
||||
|
|
@ -11,100 +11,13 @@
|
|||
"statusBar.background": "#630856",
|
||||
"statusBar.foreground": "#e7e7e7",
|
||||
"statusBarItem.hoverBackground": "#920c7f",
|
||||
"statusBarItem.remoteBackground": "#66760a",
|
||||
"statusBarItem.remoteBackground": "#630856",
|
||||
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||
"titleBar.activeBackground": "#630856",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#63085699",
|
||||
"titleBar.inactiveForeground": "#e7e7e799",
|
||||
"commandCenter.border": "#e7e7e799",
|
||||
"activityBarTop.activeBackground": "#920c7f",
|
||||
"activityBarTop.activeBorder": "#e7e7e7",
|
||||
"activityBarTop.background": "#920c7f",
|
||||
"activityBarTop.foreground": "#e7e7e7",
|
||||
"activityBarTop.inactiveForeground": "#e7e7e799",
|
||||
"commandCenter.foreground": "#e7e7e7",
|
||||
"statusBar.debuggingBackground": "#630856",
|
||||
"statusBar.debuggingForeground": "#e7e7e7",
|
||||
"statusBar.inactiveBackground": "#630856"
|
||||
"commandCenter.border": "#e7e7e799"
|
||||
},
|
||||
"peacock.color": "#630856",
|
||||
"peacock.remoteColor": "#630856",
|
||||
// "php.validate.executablePath": "/usr/local/bin/php85",
|
||||
// "php.executablePath": "/usr/local/bin/php85",
|
||||
"intelephense.environment.phpVersion": "8.5.0",
|
||||
"intelephense.environment.includePaths": [
|
||||
"./.intellipest",
|
||||
"./vendor/pestphp",
|
||||
"./vendor/phpunit/phpunit",
|
||||
"./vendor/laravel"
|
||||
],
|
||||
"phpstan.binCommand": [
|
||||
"${workspaceFolder}/vendor/bin/phpstan"
|
||||
],
|
||||
"laravel-pint.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"eslint.validate": ["javascript", "typescript", "html", "vue"],
|
||||
"[html]": {
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnPaste": true,
|
||||
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "always"
|
||||
}
|
||||
},
|
||||
"[blade]": {
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": false
|
||||
},
|
||||
"[javascript]": {
|
||||
"editor.autoIndent": "full",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "always"
|
||||
},
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||
"editor.detectIndentation": false,
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"[scss]": {
|
||||
"editor.defaultFormatter": "stylelint.vscode-stylelint",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.stylelint": "always"
|
||||
}
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.autoIndent": "full",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "always"
|
||||
},
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||
"editor.detectIndentation": false,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnSaveMode": "file"
|
||||
},
|
||||
"[php]": {
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnSaveMode": "file"
|
||||
},
|
||||
"[vue]": {
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "always"
|
||||
}
|
||||
},
|
||||
"conventionalCommits.scopes": [
|
||||
"migration"
|
||||
],
|
||||
"emeraldwalk.runonsave": {
|
||||
"autoClearConsole": false,
|
||||
"commands": [
|
||||
{
|
||||
"match": "\\.php$",
|
||||
"isAsync": true,
|
||||
"cmd": "${workspaceFolder}/vendor/bin/pint ${file}"
|
||||
}
|
||||
]
|
||||
},
|
||||
// "LaravelExtraIntellisense.phpCommand": "docker exec -w /app/srcs -t boutique-cnc-sable-$(whoami)-apache-php-1 php -r \"{code}\"",
|
||||
// "LaravelExtraIntellisense.basePathForCode": "/app/srcs"
|
||||
"peacock.remoteColor": "#630856"
|
||||
}
|
||||
|
|
|
|||
68
CHANGELOG.md
68
CHANGELOG.md
|
|
@ -1,71 +1,3 @@
|
|||
# (2026-04-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* :bug: delete ldcweb:statuschecker from the kernel 898104d
|
||||
* :bug: error on removeFromCart dc8fa4d
|
||||
* :bug: hide brands for unpublished products a5dbb9e
|
||||
* :bug: set blade directives function in public #88 e7db2d4, closes #88
|
||||
* :bug: update promotion filtering system 0692ec7
|
||||
* :bug: use blade directives helper to prevent blade files from being cached #76 #77 ae54ee5, closes #76 #77
|
||||
* :bug: user->id null on SalarieExportJob + add public holiday with cron + condition on public holiday's calendar 79d9061
|
||||
* :chart_with_upwards_trend: update dashboard statistics #52 f454d35, closes #52
|
||||
* addToCart policy was broken in product #86 + homepage #85 7150dc1, closes #86 #85
|
||||
* Clean and fix cookie notice implementation 683e7fd
|
||||
* Display the correct count of employee in the dashboard c07ff0d
|
||||
* feedback on user basket a3b4a4b
|
||||
* Fix check on salarie and customer relation 0366644
|
||||
* fixed variable name for previous commit - #96 f91a7d0, closes #96
|
||||
* hide prices in products.index <hen the user isn't logged in - #96 ab9fce5, closes #96
|
||||
* prevent division by zero in membership rate calculation f27ed8f
|
||||
* Remove piece of :poop: 2687f58
|
||||
* rename route in sitemap 6328623
|
||||
* reset view cache when updating settings f1bb958
|
||||
* RM console.log e5e44bb
|
||||
* Update matricule format 8ee5a94
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* :poop: Update Matricule format on employees import and order export f156dd6
|
||||
* :poop: Update SalarieSite Enum and Salarie Magasin model method 895843e
|
||||
* :sparkles: add new product filter on food products no art in back-end #53 e900b85, closes #53
|
||||
* :sparkles: adding multiple brands 79b9b9b
|
||||
* :sparkles: Closes #46 3a3d993, closes #46
|
||||
* :sparkles: re-add the stat before the date result on the dashbaord 8118d5a
|
||||
* :sparkles: send an order reminder email b3d4d69
|
||||
* 💬 add wording 31dac9b
|
||||
* 🗃 add new field to show slide only for connected customers #87 fcd0a79, closes #87
|
||||
* Add Laravel K8S 4fb9363
|
||||
* Add missing newsletters folder ed5b2e0
|
||||
* added admin secure fa3b38a
|
||||
* added boolean to show old price on discounts - #95 06785a3, closes #95
|
||||
* Authorize all BO roles for user import - ts-2165 e7baad6
|
||||
* Clean and add CICD for K8S migration 9333185
|
||||
* export file optimization e83b77d
|
||||
* Issue #49 feedback ba6380f, closes #49
|
||||
* Issue #52 feedback f6e06ec, closes #52
|
||||
* Issue #55 feedback bab3bef, closes #55
|
||||
* Make the fu**ing Salarie import works again c332696
|
||||
* Make the fu**ing Salarie import works again 7f53f2a
|
||||
* move uploads file in storage/app/public instead of public/ be69807
|
||||
* re-order products with a select system like support-web - #94 f9e0448, closes #94
|
||||
* Replace Regate EAI order transfert by email 184da02
|
||||
* show only brands with min 1 product - #91 6e7bbe0, closes #91
|
||||
* Update queue connection in manifest a93d191
|
||||
* Update rules c49ca99
|
||||
* update store link in fo navbar #92 2d9c55e, closes #92
|
||||
* Update uploads files folder in controllers 43fc273
|
||||
* updated slider to 25/75 ratio - #83 7c1c154, closes #83
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* Revert "npm audit fix --force to solve all vulnerabilities" 02cfc19
|
||||
* Revert "PHPCS correction 1" 3e9428d
|
||||
|
||||
|
||||
## 07-10-2022
|
||||
* Nouvelle UX (mise à jour et ajout de composants vue, inplémentation de l'intégration dans des blades)
|
||||
|
||||
|
|
|
|||
53
Dockerfile
53
Dockerfile
|
|
@ -1,52 +1,5 @@
|
|||
ARG PHP_8_5_TAG=latest
|
||||
|
||||
FROM composer:2.9 AS vendor
|
||||
|
||||
ARG GITLAB_USER
|
||||
ARG GITLAB_PASSWORD
|
||||
|
||||
COPY database/ database/
|
||||
|
||||
COPY composer.json composer.json
|
||||
COPY composer.lock composer.lock
|
||||
|
||||
RUN composer config gitlab-token.lab.s-web.fr "${GITLAB_USER}" "${GITLAB_PASSWORD}"
|
||||
RUN composer install \
|
||||
--ignore-platform-reqs \
|
||||
--no-interaction \
|
||||
--no-plugins \
|
||||
--no-scripts \
|
||||
--no-dev \
|
||||
--prefer-dist
|
||||
|
||||
FROM oven/bun:1.4.4-alpine AS frontend
|
||||
|
||||
ARG GITLAB_PASSWORD
|
||||
|
||||
RUN mkdir -p /app/public/build
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json bun.lock* tsconfig.json vite.config.ts vite.config.js .stylelintrc.json /app/
|
||||
COPY resources/ /app/resources/
|
||||
COPY --from=vendor /app/vendor/ /app/vendor/
|
||||
|
||||
RUN echo "@ldc-web:registry=https://lab.s-web.fr/api/v4/packages/npm/" >> .npmrc && \
|
||||
echo "//lab.s-web.fr/api/v4/packages/npm/:_authToken=${GITLAB_PASSWORD}" >> .npmrc && \
|
||||
echo "@uwil:registry=https://lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/" >> .npmrc && \
|
||||
echo "//lab.s-web.fr/api/v4/groups/ldc-web/-/packages/npm/:_authToken=${GITLAB_PASSWORD}" >> .npmrc
|
||||
|
||||
RUN bun install --frozen-lockfile && bun run prod
|
||||
|
||||
ARG PHP_8_5_TAG
|
||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/uwil-production-8.5:${PHP_8_5_TAG}
|
||||
|
||||
ARG USER=www-data
|
||||
|
||||
COPY --chown=${USER}:${USER} . /app/srcs
|
||||
COPY --chown=${USER}:${USER} ./resources/favicon/ /app/srcs/public/
|
||||
COPY --from=vendor --chown=${USER}:${USER} /app/vendor/ /app/srcs/vendor/
|
||||
COPY --from=frontend --chown=${USER}:${USER} /app/public/build/ /app/srcs/public/build/
|
||||
|
||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-7.3:latest
|
||||
COPY --chown=www-data:www-data . /app/srcs
|
||||
USER root
|
||||
RUN chmod -R 755 /app/srcs/storage
|
||||
USER ${USER}
|
||||
USER www-data
|
||||
|
|
|
|||
81
README.md
81
README.md
|
|
@ -1,80 +1,37 @@
|
|||
# Boutique Click N Collect Sablé
|
||||
## Boutique Click N Collect Sablé
|
||||
|
||||
## Table of contents
|
||||
|
||||
- [Boutique Click N Collect Sablé](#boutique-click-n-collect-sablé)
|
||||
- [Table of contents](#table-of-contents)
|
||||
- [Frameworks, Platforms and Libraries](#frameworks-platforms-and-libraries)
|
||||
- [Installation](#installation)
|
||||
- [Tests](#tests)
|
||||
- [Deployment](#deployment)
|
||||
- [Available Commands](#available-commands)
|
||||
- [Changelog](#changelog)
|
||||
- [Architecture](#architecture)
|
||||
- [Règles d'Or (Verrouillées par les tests)](#règles-dor-verrouillées-par-les-tests)
|
||||
|
||||
## Frameworks, Platforms and Libraries
|
||||
<!-- https://github.com/Ileriayo/markdown-badges -->
|
||||
[](https://sass-lang.com/)
|
||||
[](https://www.typescriptlang.org/)
|
||||
[](https://vite.dev/)
|
||||
[](https://www.php.net/)
|
||||
[](https://laravel.com/docs/master)
|
||||
[](https://vuejs.org/)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
vi .env
|
||||
```
|
||||
composer install
|
||||
php artisan storage:link
|
||||
npm i
|
||||
npm run prod
|
||||
cd ./ressources/views/front/
|
||||
mkdir <theme-folder>
|
||||
cd <theme-folder>
|
||||
git clone <theme-repo> .
|
||||
cd ./../../../../
|
||||
npm install && npm run prod
|
||||
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
cp .env.example .env.testing
|
||||
vi .env.testing
|
||||
composer install
|
||||
php artisan storage:link
|
||||
composer run test
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
```bash
|
||||
## Production
|
||||
Put every min in PROD :
|
||||
```php
|
||||
php artisan schedule:run
|
||||
```
|
||||
|
||||
## Available Commands
|
||||
|
||||
```bash
|
||||
php artisan ldcweb:admin-secure-sync
|
||||
```
|
||||
ldcweb:admin-secure-sync
|
||||
```
|
||||
|
||||
**Créer un utilisateur :**
|
||||
## Back-Office
|
||||
|
||||
```bash
|
||||
Création de compte
|
||||
|
||||
```
|
||||
php artisan create:admin
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
See the [CHANGELOG.md](CHANGELOG.md) file for details.
|
||||
|
||||
## Architecture
|
||||
|
||||
Ce projet suit les principes de **l'Architecture Hexagonale (Ports et Adapteurs)** et du **Domain-Driven Design (DDD)**.
|
||||
L'objectif est d'isoler au maximum la logique métier de l'infrastructure (framework Laravel, base de données, requêtes réseau) pour avoir un code robuste, pérenne et facile à tester.
|
||||
|
||||
### Règles d'Or (Verrouillées par les tests)
|
||||
|
||||
Afin de faciliter l'onboarding et d'assurer que l'architecture ne dérive pas, **Pest Arch** et **PHPStan (Level 9)** garantissent les principes suivants à chaque commit :
|
||||
|
||||
1. **Isolation totale du Domaine (Le Cœur)** : Le code dans `domain/` ne doit **jamais** dépendre du Framework (`Illuminate\`), de `App\`, ou de `Infrastructure\`. Il ne dépend que de PHP natif.
|
||||
2. **Inversion des Dépendances** : L'Application et l'Infrastructure dépendent du Domaine, et jamais l'inverse. Le domaine expose des `Ports` (Interfaces) que l'infrastructure implémente via ses `Adapters`.
|
||||
3. **Entités et Objets-Valeurs Purs** : Le domaine manipule ses propres Entités et `ValueObjects` validés et typés fortement. L'utilisation directe des modèles Eloquent est strictement interdite dans le domaine.
|
||||
4. **Conventions de Nommage** : Chaque composant a une place et un suffixe stricts : `*Service`, `*Repository`, `*Exception`, `*Dto`. Les tests échoueront si la convention n'est pas respectée.
|
||||
URL : /bo
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
# Règles Métiers du projet
|
||||
|
||||
Les règles reposent sur le code de la partie **Domaine**.
|
||||
|
||||
## 1. Planification des Retraits
|
||||
|
||||
La sélection du retrait se fait désormais sur une journée complète et non plus par tranches horaires via `PickupSchedulingService`.
|
||||
|
||||
- **Jour de retrait standard** : Uniquement le **Vendredi** (`PICKUP_DAY = WeekDay::Friday`).
|
||||
- **Heure de clôture (Cutoff)** : **Lundi à 14h00** de la même semaine (`CUTOFF_DAY = Monday`, `CUTOFF_HOUR = 14`).
|
||||
- *Comportement* : Une commande validée avant Lundi 14h00 est préparée pour le vendredi en cours. Passé ce délai, le premier jour disponible bascule automatiquement sur le vendredi de la semaine suivante.
|
||||
- **Gestion des Exceptions** :
|
||||
- Les fermetures et jours fériés sont gérés via des `ShopPickupException`.
|
||||
- Une exception peut **fermer le retrait**, ou proposer un **jour de remplacement**. Ce jour de remplacement peut posséder sa propre limite de validation (`orderDeadlineAt`).
|
||||
- Une tâche planifiée `UpsertShopsPickupExceptionsUsingApiForYear` est lancée pour provisionner les jours fériés de l'année pour toutes les boutiques
|
||||
|
||||
## 2. Limites de Montants
|
||||
|
||||
Les montants pouvant être commandés sont gérés par un service dédié `CustomerOrderLimitPolicy`
|
||||
|
||||
- **Plafond par commande** : **200€ max** (`maxOrderAmountCents = 20000`). Lève une `OrderLimitExceededException`.
|
||||
- **Plafond hebdomadaire** : **200€ max par client** sur l'ensemble de la semaine (`maxWeeklyAmountCents = 20000`). Lève une `WeeklyLimitExceededException`.
|
||||
|
||||
## 3. Disponibilité des Produits
|
||||
|
||||
Elle est géré par le service `ProductAvailabilityService`.
|
||||
|
||||
- **Conditions d'ajout au panier** :
|
||||
|
||||
- Le produit est actif (`status = true`).
|
||||
- Il est éligible INCO (`hasInco = true`).
|
||||
- La date actuelle est supérieure ou égale à `orderable_start` (si défini).
|
||||
- La date actuelle est inférieure à `orderable_end` (si défini).
|
||||
61
RGPD.md
61
RGPD.md
|
|
@ -1,61 +0,0 @@
|
|||
# RGPD
|
||||
|
||||
## Site
|
||||
|
||||
|
||||
### En base de données
|
||||
|
||||
| Table | Colonne | Contenu | Utilisation |
|
||||
| ----------- | -------------------------- | ----------------------------------------------- | -------------------------------------------------------- |
|
||||
| customers | email | Adresse email | Identifiant du client |
|
||||
| customers | hashcode | Code unique de l'utilisateur en CRM | Identifiant du client en CRM |
|
||||
| customers | created_at | Date | Suivi d'activité |
|
||||
| customers | updated_at | Date | Suivi d'activité |
|
||||
| customers | last_login_at | Date | Suivi de la dernière connexion au compte client |
|
||||
| --- | --- | --- | --- |
|
||||
| orders | employee.matricule | Matricule de l'employé | Identifiant unique de l'employé lié à la commande |
|
||||
| orders | employee.firstname | Prénom de l'employé | Affichage et personnalisation de la commande |
|
||||
| orders | employee.lastname | Nom de l'employé | Affichage et personnalisation de la commande |
|
||||
| orders | employee.facility | Établissement de l'employé | Localisation de l'employé pour la gestion de la commande |
|
||||
| orders | employee.site | Site de l'employé | Localisation du site de l'employé |
|
||||
| orders | employee.service | Service de l'employé | Service d'appartenance de l'employé |
|
||||
| orders | delivery_address.name | Nom du lieu de livraison | Identification du contact ou lieu de livraison |
|
||||
| orders | delivery_address.address | Adresse de livraison | Expédition et livraison de la commande |
|
||||
| orders | delivery_address.postcode | Code postal de livraison | Routage de la livraison |
|
||||
| orders | delivery_address.city | Ville de livraison | Routage de la livraison |
|
||||
| orders | delivery_address.phone | Téléphone de contact pour la livraison | Contact en cas de problème de livraison |
|
||||
| orders | delivery_address.latitude | Latitude de l'adresse de livraison | Géolocalisation pour optimiser la livraison |
|
||||
| orders | delivery_address.longitude | Longitude de l'adresse de livraison | Géolocalisation pour optimiser la livraison |
|
||||
| orders | employee_matricule | Matricule de l'employé (colonne virtuelle) | Indexation et recherche rapide des commandes par employé |
|
||||
| --- | --- | --- | --- |
|
||||
| order_lines | product_id | Identifiant du produit présent dans la commande | Détail de la commande |
|
||||
| order_lines | quantité | Quantité du produit présent dans la commande | Détail de la commande |
|
||||
| --- | --- | --- | --- |
|
||||
| employees | customer_id | Identifiant client | Permet de relier un salarié à un compte client du site |
|
||||
| employees | matricule | Matricule | Matricule du salarié |
|
||||
| employees | nom | Nom | Nom du salarié |
|
||||
| employees | prenom | Prénom | Prénom du salarié |
|
||||
| employees | start_date | Date de début du contrat | Activation du compte |
|
||||
| employees | end_date | Date de fin du contrat | Désactivation du compte |
|
||||
| employees | etablissement | Identifiant établissement | Localiser l'employé pour le dépôt de la commande |
|
||||
| employees | site | Identifiant site | Localiser l'employé pour le dépôt de la commande |
|
||||
| employees | service | Identifiant service | Localiser l'employé pour le dépôt de la commande |
|
||||
| --- | --- | --- | --- |
|
||||
| users | first_name | Prénom | Affichage à différents endroits du BO |
|
||||
| users | last_name | Nom | Affichage à différents endroits du BO |
|
||||
| users | email | Adresse mail | Identifiant, sert à la connexion au BO |
|
||||
|
||||
### Formulaire de contact (marketing)
|
||||
|
||||
| Donnée | Contenu |
|
||||
| -------------- | -------------------------------- |
|
||||
| Nom | Nom de la personne |
|
||||
| Prénom | Prénom de la personne |
|
||||
| Adresse E-mail | Adresse email de la personne |
|
||||
| Pièce jointe | Photo renseignée par la personne |
|
||||
|
||||
## Cookies
|
||||
|
||||
| Service | Utilité |
|
||||
| ------- | ----------------- |
|
||||
| Matomo | Mesure d'audience |
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Auth;
|
||||
|
||||
use App\Exceptions\Crm\CrmAuthenticationFailedException;
|
||||
use App\Exceptions\Crm\CrmCustomerNotActivatedException;
|
||||
use App\Exceptions\CrmServiceException;
|
||||
use App\Models\Customer;
|
||||
use App\Services\CrmService;
|
||||
use Domain\Models\ValueObjects\CrmCustomer;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Illuminate\Auth\EloquentUserProvider;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Contracts\Auth\UserProvider;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class CrmUserProvider extends EloquentUserProvider implements UserProvider
|
||||
{
|
||||
private ?CrmCustomer $crmCustomer = null;
|
||||
|
||||
/**
|
||||
* @param class-string<\Illuminate\Contracts\Auth\Authenticatable&\Illuminate\Database\Eloquent\Model> $model
|
||||
*/
|
||||
public function __construct(
|
||||
Hasher $hasher,
|
||||
string $model,
|
||||
private readonly CrmService $crmService
|
||||
) {
|
||||
parent::__construct($hasher, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* The model to use, specified in auth config guard.
|
||||
*
|
||||
* @var class-string<\App\Models\Customer>
|
||||
*/
|
||||
private $usedModel = Customer::class;
|
||||
|
||||
/**
|
||||
* Retrieve a user by the given credentials.
|
||||
*
|
||||
* @param array<string, mixed> $credentials
|
||||
*
|
||||
* @throws \RuntimeException If connection to server fails.
|
||||
* @throws \LDC\LDCCRM\Exceptions\CrmException On CRM call error.
|
||||
* @throws \Exception On CRM call error.
|
||||
*/
|
||||
#[\Override]
|
||||
public function retrieveByCredentials(array $credentials): ?Authenticatable
|
||||
{
|
||||
$model = parent::retrieveByCredentials($credentials);
|
||||
$result = $this->crmService->getCustomerFromEmail(Arr::string($credentials, 'email'));
|
||||
|
||||
if ($result instanceof CrmServiceException) {
|
||||
report($result);
|
||||
throw ValidationException::withMessages([
|
||||
\trans('An error has occurred. Please try again later'),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->crmCustomer = $result;
|
||||
|
||||
if ($this->crmCustomer instanceof CrmCustomer && $model === null) {
|
||||
$model = $this->createLocalCustomer($this->crmCustomer);
|
||||
}
|
||||
|
||||
return $this->crmCustomer !== null ? $model : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a user against the given credentials.
|
||||
*
|
||||
* @param array<string, mixed> $credentials
|
||||
*
|
||||
* @throws \RuntimeException If model provided is not a Customer or connection to server fails.
|
||||
* @throws \LDC\LDCCRM\Exceptions\CrmException On CRM call error.
|
||||
* @throws \Exception On CRM call error.
|
||||
*/
|
||||
#[\Override]
|
||||
public function validateCredentials(Authenticatable $model, array $credentials): bool
|
||||
{
|
||||
if ($model::class !== $this->usedModel) {
|
||||
throw new UnexpectedValueException("Cannot authenticate any thing else than '{$this->usedModel}'");
|
||||
}
|
||||
|
||||
if (! in_array(MustVerifyEmail::class, \class_implements($model))) {
|
||||
throw new UnexpectedValueException("Model '{$this->usedModel}' should implement 'MustVerifyEmail'");
|
||||
}
|
||||
/** @var \Illuminate\Contracts\Auth\Authenticatable&\Illuminate\Contracts\Auth\MustVerifyEmail $model */
|
||||
$requestEmail = Arr::string($credentials, 'email');
|
||||
$requestPassword = Arr::string($credentials, 'password');
|
||||
|
||||
try {
|
||||
$this->crmService->login(
|
||||
$requestEmail,
|
||||
$requestPassword
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (CrmCustomerNotActivatedException) {
|
||||
$model->sendEmailVerificationNotification();
|
||||
|
||||
return true;
|
||||
} catch (CrmAuthenticationFailedException) {
|
||||
return false;
|
||||
} catch (CrmServiceException $e) {
|
||||
report($e);
|
||||
throw ValidationException::withMessages([
|
||||
trans('An error has occurred. Please try again later'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $credentials */
|
||||
#[\Override]
|
||||
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false): void
|
||||
{
|
||||
// No hashing.
|
||||
}
|
||||
|
||||
private function createLocalCustomer(CrmCustomer $crmCustomer): Model & Authenticatable
|
||||
{
|
||||
$email = $crmCustomer->email ?
|
||||
new Email($crmCustomer->email) :
|
||||
throw new UnexpectedValueException('Email is required ti create a customer');
|
||||
|
||||
$hashcode = $crmCustomer->hashcode ?
|
||||
$crmCustomer->hashcode :
|
||||
throw new UnexpectedValueException('Hashcode is required to create a customer');
|
||||
|
||||
/** @var \App\Models\Customer&\Illuminate\Contracts\Auth\Authenticatable $model */
|
||||
$model = $this->usedModel::query()
|
||||
->where('email', $crmCustomer->email)
|
||||
->firstOrNew();
|
||||
|
||||
$model->email = $email;
|
||||
$model->hashcode = CrmHashcode::fromString($hashcode);
|
||||
$model->saveOrFail();
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\Code;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<Code,Code> */
|
||||
class CodeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): Code
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('Code must be a string.');
|
||||
}
|
||||
|
||||
return new Code($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
|
||||
if (! $value instanceof Code) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of Code.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
|
||||
/** @implements CastsAttributes<CrmHashcode, CrmHashcode|string> */
|
||||
class CrmHashcodeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, $value, array $attributes): CrmHashcode
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('CrmHashcode must be a string.');
|
||||
}
|
||||
|
||||
$uuid = Uuid::fromString($value);
|
||||
|
||||
return new CrmHashcode($uuid);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, $value, array $attributes): string
|
||||
{
|
||||
if ($value === null) {
|
||||
throw new \InvalidArgumentException('CrmHashcode cannot be null.');
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = new CrmHashcode(Uuid::fromString($value));
|
||||
}
|
||||
|
||||
if (! ($value instanceof CrmHashcode)) {
|
||||
throw new \InvalidArgumentException('The given value is not an instance of CrmHashcode.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\DeliveryAddress;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/** @implements CastsAttributes<DeliveryAddress,DeliveryAddress> */
|
||||
class DeliveryAddressCast implements CastsAttributes
|
||||
{
|
||||
private const string DEFAULT_STRING = 'Non renseigné';
|
||||
|
||||
private const string DEFAULT_POSTCODE = '00000';
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): DeliveryAddress
|
||||
{
|
||||
if ($value === null) {
|
||||
return new DeliveryAddress(
|
||||
name: self::DEFAULT_STRING,
|
||||
address: self::DEFAULT_STRING,
|
||||
postcode: self::DEFAULT_POSTCODE,
|
||||
city: self::DEFAULT_STRING,
|
||||
);
|
||||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
||||
return new DeliveryAddress(
|
||||
name: Arr::string($data, 'name', self::DEFAULT_STRING),
|
||||
address: Arr::string($data, 'address', self::DEFAULT_STRING),
|
||||
postcode: Arr::string($data, 'postcode', self::DEFAULT_POSTCODE),
|
||||
city: Arr::string($data, 'city', self::DEFAULT_STRING),
|
||||
phone: ! empty(Arr::get($data, 'phone')) ?
|
||||
Arr::string($data, 'phone') : null,
|
||||
latitude: ! empty(Arr::get($data, 'latitude')) ?
|
||||
Arr::string($data, 'latitude') : null,
|
||||
longitude: ! empty(Arr::get($data, 'longitude')) ?
|
||||
Arr::string($data, 'longitude') : null,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (! $value instanceof DeliveryAddress) {
|
||||
throw new \InvalidArgumentException('The value must be an instance of DeliveryAddress.');
|
||||
}
|
||||
|
||||
return json_encode($value->toArray(), JSON_UNESCAPED_UNICODE) ?:
|
||||
throw new \InvalidArgumentException('Cannot encode DeliveryAddress to JSON.');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
|
||||
/** @implements CastsAttributes<DiscountValue, DiscountValue> */
|
||||
class DiscountValueCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): DiscountValue
|
||||
{
|
||||
$typeRaw = $attributes['type'] ?? null;
|
||||
|
||||
if ($typeRaw === null || (! is_int($typeRaw) && ! is_string($typeRaw))) {
|
||||
throw new \UnexpectedValueException('The discount type attribute is missing to cast the value.');
|
||||
}
|
||||
|
||||
if ($value === null || (! is_int($value) && ! (is_string($value) && ctype_digit($value)))) {
|
||||
throw new \UnexpectedValueException('The discount value must be an integer or a numeric string.');
|
||||
}
|
||||
|
||||
$type = DiscountType::tryFrom((int) $typeRaw);
|
||||
|
||||
if ($type === null) {
|
||||
throw new \UnexpectedValueException("Unknown discount type raw value: {$typeRaw}");
|
||||
}
|
||||
|
||||
// Instanciation selon le type
|
||||
if ($type === DiscountType::PERCENT) {
|
||||
return DiscountValue::fromPercentage(intval($value));
|
||||
}
|
||||
|
||||
return DiscountValue::fromAmount(
|
||||
new Money($value, resolve(Currency::class))
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): int
|
||||
{
|
||||
if ($value === null) {
|
||||
throw new \InvalidArgumentException('The value cannot be null.');
|
||||
}
|
||||
|
||||
if (! ($value instanceof DiscountValue)) {
|
||||
throw new \InvalidArgumentException('The value must be an instance of DiscountValue.');
|
||||
}
|
||||
|
||||
$discountValue = $value->value();
|
||||
|
||||
if ($discountValue instanceof Money) {
|
||||
return (int) $discountValue->getAmount();
|
||||
}
|
||||
|
||||
return $discountValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<Email,Email> */
|
||||
class EmailCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, $value, array $attributes): Email
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('Email must be a string.');
|
||||
}
|
||||
|
||||
return new Email($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, $value, array $attributes): string
|
||||
{
|
||||
if ($value === null) {
|
||||
throw new \InvalidArgumentException('Email cannot be null.');
|
||||
}
|
||||
|
||||
if (! ($value instanceof Email)) {
|
||||
throw new \InvalidArgumentException('The given value is not an instance of Email.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @implements CastsAttributes<array<int, string>, array<mixed>|string|null>
|
||||
*/
|
||||
class EmployeeSitesCast implements CastsAttributes
|
||||
{
|
||||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return string[]
|
||||
*/
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
$value = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
if (! is_array($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sites = [];
|
||||
foreach ($value as $item) {
|
||||
if (is_string($item)) {
|
||||
$sites[] = $item;
|
||||
} elseif (is_scalar($item) || $item instanceof \Stringable) {
|
||||
$sites[] = (string) $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $sites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if ($value === null) {
|
||||
return (string) json_encode([]);
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
$value = is_array($decoded) ? $decoded : [$value];
|
||||
}
|
||||
|
||||
if (! is_array($value)) {
|
||||
throw new \UnexpectedValueException('Employee sites must be an array, string or null.');
|
||||
}
|
||||
|
||||
$sites = [];
|
||||
foreach ($value as $item) {
|
||||
if (is_string($item)) {
|
||||
$sites[] = $item;
|
||||
} elseif (is_scalar($item) || $item instanceof \Stringable) {
|
||||
$sites[] = (string) $item;
|
||||
} else {
|
||||
throw new \UnexpectedValueException('Each employee site must be convertable to string.');
|
||||
}
|
||||
}
|
||||
|
||||
return (string) json_encode($sites);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<Matricule,Matricule> */
|
||||
class MatriculeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): Matricule
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('Matricule must be a string.');
|
||||
}
|
||||
|
||||
return new Matricule($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (! $value instanceof Matricule) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of Matricule.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
|
||||
/** @implements CastsAttributes<Money,Money> */
|
||||
class MoneyCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): Money
|
||||
{
|
||||
$currency = $this->getCurrency();
|
||||
|
||||
if (! is_numeric($value)) {
|
||||
throw new \InvalidArgumentException('The given value is not numeric.');
|
||||
}
|
||||
|
||||
if (! is_string($value) && ! is_int($value)) {
|
||||
throw new \InvalidArgumentException('The given value must be a string or integer.');
|
||||
}
|
||||
|
||||
return new Money($value, $currency);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if ($value instanceof Money) {
|
||||
return $value->getAmount();
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('The given value is not an instance of Money.');
|
||||
}
|
||||
|
||||
protected function getCurrency(): Currency
|
||||
{
|
||||
return resolve(Currency::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\NutritionalValues;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/** @implements CastsAttributes<NutritionalValues|null,NutritionalValues|null> */
|
||||
class NutritionalValuesCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): NutritionalValues
|
||||
{
|
||||
return new NutritionalValues(
|
||||
refWeightG: $this->getFloatOrNull($attributes, 'nv_ref_weight_g'),
|
||||
kj: $this->getFloatOrNull($attributes, 'nv_kj'),
|
||||
kcal: $this->getFloatOrNull($attributes, 'nv_kcal'),
|
||||
fatG: $this->getFloatOrNull($attributes, 'nv_fat_g'),
|
||||
satFatG: $this->getFloatOrNull($attributes, 'nv_sat_fat_g'),
|
||||
carbG: $this->getFloatOrNull($attributes, 'nv_carb_g'),
|
||||
sugarG: $this->getFloatOrNull($attributes, 'nv_sugar_g'),
|
||||
fiberG: $this->getFloatOrNull($attributes, 'nv_fiber_g'),
|
||||
proteinG: $this->getFloatOrNull($attributes, 'nv_protein_g'),
|
||||
saltG: $this->getFloatOrNull($attributes, 'nv_salt_g'),
|
||||
servingSizeG: $this->getFloatOrNull($attributes, 'nv_serving_size_g'),
|
||||
servingKj: $this->getFloatOrNull($attributes, 'nv_serving_kj'),
|
||||
servingKcal: $this->getFloatOrNull($attributes, 'nv_serving_kcal'),
|
||||
servingFatG: $this->getFloatOrNull($attributes, 'nv_serving_fat_g'),
|
||||
servingSatFatG: $this->getFloatOrNull($attributes, 'nv_serving_sat_fat_g'),
|
||||
servingCarbG: $this->getFloatOrNull($attributes, 'nv_serving_carb_g'),
|
||||
servingSugarG: $this->getFloatOrNull($attributes, 'nv_serving_sugar_g'),
|
||||
servingFiberG: $this->getFloatOrNull($attributes, 'nv_serving_fiber_g'),
|
||||
servingProteinG: $this->getFloatOrNull($attributes, 'nv_serving_protein_g'),
|
||||
servingSaltG: $this->getFloatOrNull($attributes, 'nv_serving_salt_g'),
|
||||
dailyEnergy: $this->getFloatOrNull($attributes, 'nv_daily_energy'),
|
||||
dailyFat: $this->getFloatOrNull($attributes, 'nv_daily_fat'),
|
||||
dailySatFat: $this->getFloatOrNull($attributes, 'nv_daily_sat_fat'),
|
||||
dailyCarb: $this->getFloatOrNull($attributes, 'nv_daily_carb'),
|
||||
dailySugar: $this->getFloatOrNull($attributes, 'nv_daily_sugar'),
|
||||
dailyFiber: $this->getFloatOrNull($attributes, 'nv_daily_fiber'),
|
||||
dailyProtein: $this->getFloatOrNull($attributes, 'nv_daily_protein'),
|
||||
dailySalt: $this->getFloatOrNull($attributes, 'nv_daily_salt'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): array
|
||||
{
|
||||
if ($value === null) {
|
||||
return new NutritionalValues()->toArray();
|
||||
}
|
||||
|
||||
if (! $value instanceof NutritionalValues) {
|
||||
throw new \InvalidArgumentException('The given value is not a NutritionalValues instance.');
|
||||
}
|
||||
|
||||
return $value->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function getFloatOrNull(array $attributes, string $key): ?float
|
||||
{
|
||||
$value = Arr::get($attributes, $key);
|
||||
|
||||
if ((is_string($value) && ctype_digit($value)) || is_float($value)) {
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
throw_if(
|
||||
$value !== null,
|
||||
\InvalidArgumentException::class,
|
||||
"Expected `{$key}` to be numeric of null"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\OrderEmployee;
|
||||
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
||||
use Domain\Models\ValueObjects\ShopperServiceCode;
|
||||
use Domain\Models\ValueObjects\ShopperSiteCode;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/** @implements CastsAttributes<OrderEmployee|null,OrderEmployee|null> */
|
||||
class OrderEmployeeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): ?OrderEmployee
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
||||
return new OrderEmployee(
|
||||
matricule: new Matricule(Arr::string($data, 'matricule')),
|
||||
firstname: Arr::string($data, 'firstname'),
|
||||
lastname: Arr::string($data, 'lastname'),
|
||||
facility: new ShopperEstablishmentCode(Arr::string($data, 'facility')),
|
||||
site: new ShopperSiteCode(Arr::string($data, 'site')),
|
||||
service: new ShopperServiceCode(Arr::string($data, 'service')),
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): ?string
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $value instanceof OrderEmployee) {
|
||||
throw new \InvalidArgumentException('The given value is not an instance of OrderEmployee.');
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'matricule' => $value->matricule->value,
|
||||
'firstname' => $value->firstname,
|
||||
'lastname' => $value->lastname,
|
||||
'facility' => $value->facility->value,
|
||||
'site' => $value->site->value,
|
||||
'service' => $value->service->value,
|
||||
], JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Enums\ProductBrand;
|
||||
use Domain\Enums\TaxRate;
|
||||
use Domain\Enums\Units\OrderUnit;
|
||||
use Domain\Models\ValueObjects\Entities\ProductId;
|
||||
use Domain\Models\ValueObjects\IncoId;
|
||||
use Domain\Models\ValueObjects\OrderLineProduct;
|
||||
use Domain\Models\ValueObjects\ProductWeight;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Uid\Uuid as SymfonyUuid;
|
||||
|
||||
/**
|
||||
* @implements CastsAttributes<OrderLineProduct,OrderLineProduct>
|
||||
*/
|
||||
class OrderLineProductCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): OrderLineProduct
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new \InvalidArgumentException('The value cannot be null.');
|
||||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
||||
$taxRate = Arr::get($data, 'tax_rate');
|
||||
$taxRate = is_numeric($taxRate) ? (float) $taxRate : null;
|
||||
|
||||
if (is_null($taxRate)) {
|
||||
throw new \InvalidArgumentException('The tax rate cannot be null.');
|
||||
}
|
||||
|
||||
return new OrderLineProduct(
|
||||
incoId: new IncoId(Arr::integer($data, 'inco_id')),
|
||||
originalId: new ProductId(Uuid::fromString(
|
||||
SymfonyUuid::fromString(Arr::string($data, 'original_id'))->toRfc4122()
|
||||
)),
|
||||
name: Arr::string($data, 'name'),
|
||||
weight: new ProductWeight(
|
||||
value: Arr::integer($data, 'weight'),
|
||||
isVariable: Arr::boolean($data, 'weight_variable'),
|
||||
),
|
||||
brand: ProductBrand::from(Arr::string($data, 'brand')),
|
||||
orderUnit: OrderUnit::from(Arr::string($data, 'order_unit')),
|
||||
price: new MoneyCast()->get($model, 'price', Arr::get($data, 'price'), []),
|
||||
discountedPrice: new MoneyCast()->get($model, 'discounted_price', Arr::get($data, 'discounted_price'), []),
|
||||
priceKgTtc: new MoneyCast()->get($model, 'price_kg_ttc', Arr::get($data, 'price_kg_ttc'), []),
|
||||
taxRate: TaxRate::fromPercent($taxRate),
|
||||
picture: is_string($picture = Arr::get($data, 'picture')) ? $picture : null,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
|
||||
if (! ($value instanceof OrderLineProduct)) {
|
||||
throw new \InvalidArgumentException('The given value is not an instance of OrderLineProduct.');
|
||||
}
|
||||
|
||||
/** @var OrderLineProduct $value */
|
||||
|
||||
return json_encode([
|
||||
'inco_id' => $value->incoId->value,
|
||||
'original_id' => $value->originalId->value,
|
||||
'name' => $value->name,
|
||||
'weight' => $value->weight->value,
|
||||
'weight_variable' => $value->weight->isVariable,
|
||||
'brand' => $value->brand->value,
|
||||
'order_unit' => $value->orderUnit->value,
|
||||
'price' => new MoneyCast()->set(
|
||||
$model,
|
||||
'price',
|
||||
$value->price,
|
||||
[]
|
||||
),
|
||||
'discounted_price' => new MoneyCast()->set(
|
||||
$model,
|
||||
'discounted_price',
|
||||
$value->discountedPrice,
|
||||
[]
|
||||
),
|
||||
'price_kg_ttc' => new MoneyCast()->set(
|
||||
$model,
|
||||
'price_kg_ttc',
|
||||
$value->priceKgTtc,
|
||||
[]
|
||||
),
|
||||
'tax_rate' => $value->taxRate->percent(),
|
||||
'picture' => $value->picture,
|
||||
], \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\OrderReference;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
|
||||
/**
|
||||
* @implements CastsAttributes<OrderReference,OrderReference>
|
||||
*/
|
||||
class OrderReferenceCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get($model, string $key, $value, array $attributes): OrderReference
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('OrderReference cannot be null.');
|
||||
}
|
||||
|
||||
return OrderReference::fromString($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set($model, string $key, $value, array $attributes): string
|
||||
{
|
||||
if (! $value instanceof OrderReference) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of OrderReference.');
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<ShopperEstablishmentCode, ShopperEstablishmentCode|string> */
|
||||
class ShopperEstablishmentCodeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): ShopperEstablishmentCode
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('ShopperEstablishmentCode must be a string.');
|
||||
}
|
||||
|
||||
return new ShopperEstablishmentCode($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = new ShopperEstablishmentCode($value);
|
||||
}
|
||||
|
||||
if (! $value instanceof ShopperEstablishmentCode) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of ShopperEstablishmentCode.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\ShopperServiceCode;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<ShopperServiceCode, ShopperServiceCode|string> */
|
||||
class ShopperServiceCodeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): ShopperServiceCode
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('ShopperServiceCode must be a string.');
|
||||
}
|
||||
|
||||
return new ShopperServiceCode($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = new ShopperServiceCode($value);
|
||||
}
|
||||
|
||||
if (! $value instanceof ShopperServiceCode) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of ShopperServiceCode.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Domain\Models\ValueObjects\ShopperSiteCode;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/** @implements CastsAttributes<ShopperSiteCode, ShopperSiteCode|string> */
|
||||
class ShopperSiteCodeCast implements CastsAttributes
|
||||
{
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): ShopperSiteCode
|
||||
{
|
||||
if ($value === null || ! is_string($value)) {
|
||||
throw new \UnexpectedValueException('ShopperSiteCode must be a string.');
|
||||
}
|
||||
|
||||
return new ShopperSiteCode($value);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = new ShopperSiteCode($value);
|
||||
}
|
||||
|
||||
if (! $value instanceof ShopperSiteCode) {
|
||||
throw new \UnexpectedValueException('The given value is not an instance of ShopperSiteCode.');
|
||||
}
|
||||
|
||||
return $value->value;
|
||||
}
|
||||
}
|
||||
35
app/Console/Commands/GetPublicHolidayNextYear.php
Normal file
35
app/Console/Commands/GetPublicHolidayNextYear.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\GetPublicHolidayForNextYear;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GetPublicHolidayNextYear extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uwil:get-public-holiday {year?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'fetch the public holiday for a specific year or by default for the next year';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$year = $this->argument('year');
|
||||
(new GetPublicHolidayForNextYear($year))->handle();
|
||||
$this->info("Les jours fériés de l'année " . ($year ?? (now()->year + 1)) . " ont été récupéré.");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
#[Description('Send a test mail')]
|
||||
#[Signature('uwil:app:mail-test
|
||||
{email : the email to send the test mail to}')]
|
||||
class MailTest extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Validator::make($this->arguments(), [
|
||||
'email' => ['required', 'email:rfc,strict'],
|
||||
])->validate();
|
||||
|
||||
Mail::raw('This is a test mail', function ($message): void {
|
||||
$message->to($this->argument('email'));
|
||||
$message->subject('Test mail');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Contracts\ActionInputEmpty;
|
||||
use App\Contracts\Executor;
|
||||
use App\Cqs\Actions\ProductIncos\SynchronizeProductIncosWithArcadiaApi;
|
||||
use App\Jobs\FetchAndUpsertArcadiaProductIncos;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Description('Synchronize all product INCO sheets with Arcadia API')]
|
||||
#[Signature('uwil:incos:sync {--queue : Dispatch the synchronization job to the queue}')]
|
||||
class SyncProductIncosCommand extends Command
|
||||
{
|
||||
public function handle(
|
||||
Executor $executor,
|
||||
SynchronizeProductIncosWithArcadiaApi $action
|
||||
): int {
|
||||
if ($this->option('queue')) {
|
||||
$this->info('Dispatching FetchAndUpsertArcadiaProductIncos job to queue...');
|
||||
FetchAndUpsertArcadiaProductIncos::dispatch();
|
||||
$this->info('Job dispatched.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info('Starting synchronous INCO synchronization with Arcadia API...');
|
||||
/** @var int $count */
|
||||
$count = $executor->execute($action, new ActionInputEmpty());
|
||||
$this->info("Successfully synchronized {$count} INCO sheets.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Contracts\Executor;
|
||||
use App\Cqs\Actions\Employee\ImportEmployees;
|
||||
use App\Cqs\Actions\Employee\ImportEmployeesInput;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Description('Synchronize all employees from a CSV file with Arcadia API')]
|
||||
#[Signature('uwil:employees:upsert {file : The CSV file to import}')]
|
||||
class UpsertEmployeesFormFile extends Command
|
||||
{
|
||||
public function handle(
|
||||
Executor $executor,
|
||||
ImportEmployees $action
|
||||
): int {
|
||||
$file = $this->argument('file');
|
||||
|
||||
if (! file_exists($file)) {
|
||||
$this->error("File not found: {$file}");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('Starting synchronous employee import from CSV...');
|
||||
|
||||
$stream = new \SplFileObject($file, 'r');
|
||||
|
||||
if (! $stream->isReadable()) {
|
||||
$this->error("Failed to open file: {$file}");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$importResult = $executor->execute($action, new ImportEmployeesInput($stream));
|
||||
|
||||
$this->info("Successfully inserted {$importResult->insertedCount} employees.");
|
||||
$this->info("Successfully updated {$importResult->updatedCount} employees.");
|
||||
|
||||
if (! empty($importResult->errors)) {
|
||||
$this->error('Errors occurred during import:');
|
||||
foreach ($importResult->errors as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\UpsertShopsPickupExceptionsUsingApiForYear;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Description('fetch the public holiday for a specific year or by default for the next year')]
|
||||
#[Signature('uwil:upsert-shops-hollydays {year?}')]
|
||||
class UpsertPublicHolydaysOnShopsPickupExceptions extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$year = $this->argument('year');
|
||||
|
||||
if (is_numeric($year) === false) {
|
||||
$this->error('The year must be a number');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info('Fetching hollidays upsert shops exceptions using Api');
|
||||
dispatch(new UpsertShopsPickupExceptionsUsingApiForYear(intval($year)));
|
||||
|
||||
$this->info('Done');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +1,39 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Domain\Enums\UserRole;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
#[Description('creates an admin user upon password entry')]
|
||||
#[Signature('uwil:user:create')]
|
||||
class UserCreate extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function handle(): int
|
||||
protected $signature = 'user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'creates an admin user upon password entry';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$firstname = $this->askString('What is the firstname?', 'Equipe');
|
||||
$lastname = $this->askString('What is the lastname?', 'Web');
|
||||
$email = $this->askEmail('What is the email?', 'equipe.web@ldc.fr');
|
||||
$pwd = $this->askPassword('What is the password?');
|
||||
$role = $this->askRole();
|
||||
$firstname = $this->ask('What is the firstname?', 'Equipe');
|
||||
$lastname = $this->ask('What is the lastname?', 'Web');
|
||||
$email = $this->ask('What is the email?', 'equipe.web@ldc.fr');
|
||||
$pwd = $this->secret('What is the password?');
|
||||
$role = $this->ask('What is the role? (1 = SuperAdmin, 2 = Admin)', 2);
|
||||
|
||||
$user = new User();
|
||||
$user->firstname = $firstname;
|
||||
|
|
@ -39,101 +45,5 @@ class UserCreate extends Command
|
|||
$user->save();
|
||||
|
||||
$this->info('User created.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function askString(
|
||||
string $wants,
|
||||
?string $default
|
||||
): string {
|
||||
$response = $this->ask($wants, $default);
|
||||
$response = is_string($response) ? $response : '';
|
||||
$strlen = mb_strlen(trim($response));
|
||||
|
||||
if ($strlen >= 3 && $strlen <= 255) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->warn('Answer has to be between 3 and 255 chars');
|
||||
|
||||
return $this->askString($wants, $default);
|
||||
}
|
||||
|
||||
private function askEmail(
|
||||
string $wants,
|
||||
?string $default
|
||||
): string {
|
||||
$response = $this->ask($wants, $default);
|
||||
$response = is_string($response) ? $response : '';
|
||||
$validator = Validator::make([
|
||||
'email' => $response,
|
||||
], [
|
||||
'email' => ['required', 'email:rfc,strict,spoof', 'unique:users,email'],
|
||||
]);
|
||||
|
||||
if ($validator->passes()) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->warn($validator->messages()->first('email'));
|
||||
|
||||
return $this->askEmail($wants, $default);
|
||||
}
|
||||
|
||||
private function askPassword(
|
||||
string $wants
|
||||
): string {
|
||||
$response = $this->secret($wants);
|
||||
$responseConfirmed = $this->secret("Confirm : {$wants}");
|
||||
$response = is_string($response) ? $response : '';
|
||||
$responseConfirmed = is_string($responseConfirmed) ? $responseConfirmed : '';
|
||||
$validator = Validator::make([
|
||||
'password' => $response,
|
||||
'password_confirmation' => $responseConfirmed,
|
||||
], [
|
||||
'password' => ['required', 'confirmed', Password::min(8)->letters()->mixedCase()->numbers()->symbols()],
|
||||
]);
|
||||
|
||||
if ($validator->passes()) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->warn($validator->messages()->first('password'));
|
||||
|
||||
return $this->askPassword($wants);
|
||||
}
|
||||
|
||||
private function askRole(): UserRole
|
||||
{
|
||||
$role = null;
|
||||
$possibles = collect(UserRole::cases())
|
||||
->map(fn ($role) => $this->roleToString($role))
|
||||
->all();
|
||||
|
||||
$response = Arr::wrap(
|
||||
$this->choice(
|
||||
question: 'What is the role ?',
|
||||
choices: $possibles,
|
||||
default: $this->roleToString(UserRole::Admin),
|
||||
multiple: false
|
||||
)
|
||||
);
|
||||
$role = UserRole::tryFrom(
|
||||
intval(mb_strcut((string) $response[0], 0, 1))
|
||||
);
|
||||
|
||||
if (! is_null($role)) {
|
||||
return $role;
|
||||
}
|
||||
|
||||
$this->warn('Need a valid role, try again');
|
||||
|
||||
return $this->askRole();
|
||||
}
|
||||
|
||||
private function roleToString(UserRole $role): string
|
||||
{
|
||||
return "{$role->value()} : {$role->label()}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
37
app/Console/Commands/XmlIncoReader.php
Normal file
37
app/Console/Commands/XmlIncoReader.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\XmlIncoReader as JobsXmlIncoReader;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class XmlIncoReader extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'xml:inco';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run the XmlIncoReaderJob manually';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Running the Job, this could take some time.');
|
||||
$job = new JobsXmlIncoReader();
|
||||
$job->console = $this;
|
||||
$job->handle();
|
||||
$this->info('Job completed');
|
||||
}
|
||||
}
|
||||
44
app/Console/Kernel.php
Normal file
44
app/Console/Kernel.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\GetPublicHolidayForNextYear;
|
||||
use App\Jobs\SendReminderMail;
|
||||
use App\Jobs\XmlIncoReader as JobsXmlIncoReader;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(JobsXmlIncoReader::class)->name('xml-inco-reader')->onOneServer()->dailyAt('15:00');
|
||||
$schedule->job(SendReminderMail::class)->onOneServer()->dailyAt('10:00');
|
||||
$schedule->job(GetPublicHolidayForNextYear::class)->onOneServer()->yearlyOn(11, 1, '7:30');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
/**
|
||||
* @template TInput of \App\Contracts\ActionInput
|
||||
* @template TResult
|
||||
*/
|
||||
interface Action
|
||||
{
|
||||
/**
|
||||
* @param TInput $input
|
||||
* @return TResult
|
||||
*/
|
||||
public function __invoke(ActionInput $input);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
interface ActionInput
|
||||
{
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
final class ActionInputEmpty implements ActionInput
|
||||
{
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Directories;
|
||||
|
||||
use App\Contracts\Directory;
|
||||
use App\Models\Customer;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/** @extends Directory<\Ramsey\Uuid\UuidInterface, \App\Models\Customer> */
|
||||
interface CustomerDirectory extends Directory
|
||||
{
|
||||
public function find(UuidInterface $id): ?Customer;
|
||||
|
||||
public function getCustomerByEmail(Email $email): ?Customer;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Directories;
|
||||
|
||||
use App\Contracts\Directory;
|
||||
use App\Models\Employee;
|
||||
use Carbon\CarbonInterface;
|
||||
|
||||
/** @extends Directory<int, \App\Models\Employee> */
|
||||
interface EmployeeDirectory extends Directory
|
||||
{
|
||||
public function find(int $id): ?Employee;
|
||||
|
||||
public function countActiveEmployees(): int;
|
||||
|
||||
public function countActiveRegisteredEmployees(): int;
|
||||
|
||||
public function countActiveEmployeesWithin(CarbonInterface $start, CarbonInterface $end): int;
|
||||
|
||||
public function countActiveRegisteredEmployeesWithin(CarbonInterface $start, CarbonInterface $end): int;
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Directories;
|
||||
|
||||
use App\Contracts\Directory;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use Carbon\CarbonInterface;
|
||||
use Domain\Enums\OrderStatus;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator as PaginationLengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Shared\Pagination\Pagination;
|
||||
|
||||
/** @extends Directory<\Ramsey\Uuid\UuidInterface, \App\Models\Order> */
|
||||
interface OrderDirectory extends Directory
|
||||
{
|
||||
public function find(UuidInterface $id): ?Order;
|
||||
|
||||
/** @return \Illuminate\Pagination\LengthAwarePaginator<int,Order> */
|
||||
public function getPaginatedOrdersOf(
|
||||
Customer $customer,
|
||||
Pagination $pagination,
|
||||
bool $orderByDate = false
|
||||
): PaginationLengthAwarePaginator;
|
||||
|
||||
public function findOf(Customer $customer, UuidInterface $id): ?Order;
|
||||
|
||||
/** @return Collection<int,Order>*/
|
||||
public function getValidatedOrders(CarbonInterface $start, CarbonInterface $end): Collection;
|
||||
|
||||
/** @return Collection<int,Order> */
|
||||
public function getOrdersByStatus(OrderStatus $status, CarbonInterface $start, CarbonInterface $end): Collection;
|
||||
|
||||
public function getNbActiveClients(CarbonInterface $start, CarbonInterface $end): int;
|
||||
|
||||
public function getNbCmdWith7DayDelay(CarbonInterface $start, CarbonInterface $end): int;
|
||||
|
||||
public function getNbCmdWith14DayDelay(CarbonInterface $start, CarbonInterface $end): int;
|
||||
|
||||
public function getCaHt(CarbonInterface $start, CarbonInterface $end): float;
|
||||
|
||||
public function getCaTtc(CarbonInterface $start, CarbonInterface $end): float;
|
||||
|
||||
public function getTotalQuantity(CarbonInterface $start, CarbonInterface $end): int;
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
/**
|
||||
* @template TEntity
|
||||
* @template TId
|
||||
*
|
||||
* @method TEntity|null find(TId $id)
|
||||
*/
|
||||
interface Directory
|
||||
{
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
interface Executor
|
||||
{
|
||||
/**
|
||||
* @template TInputAction of \App\Contracts\ActionInput
|
||||
* @template TInputQuery of \App\Contracts\QueryInput
|
||||
* @template TResult
|
||||
*
|
||||
* @param \App\Contracts\Query<TInputQuery,TResult>|\App\Contracts\Action<TInputAction,TResult> $executable
|
||||
* @param TInputAction|TInputQuery $input
|
||||
* @return TResult
|
||||
*/
|
||||
public function execute(Action | Query $executable, ActionInput | QueryInput $input): mixed;
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
/**
|
||||
* @template TInput of \App\Contracts\QueryInput
|
||||
* @template TResult
|
||||
*/
|
||||
interface Query
|
||||
{
|
||||
/**
|
||||
* @param TInput $input
|
||||
* @return TResult
|
||||
*/
|
||||
public function __invoke(QueryInput $input);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
interface QueryInput
|
||||
{
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
final class QueryInputEmpty implements QueryInput
|
||||
{
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Repositories;
|
||||
|
||||
use App\Contracts\Repository;
|
||||
use App\Models\Employee;
|
||||
use Domain\Models\ValueObjects\Code;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Illuminate\Support\Collection;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/**
|
||||
* @extends Repository<Employee, UuidInterface>
|
||||
*/
|
||||
interface EmployeeRepository extends Repository
|
||||
{
|
||||
public function find(UuidInterface $id): ?Employee;
|
||||
|
||||
public function persist(Employee $employee): void;
|
||||
|
||||
public function delete(Employee $employee): void;
|
||||
|
||||
/** @return array<array-key, Employee> */
|
||||
public function getAll(): array;
|
||||
|
||||
public function findByMatriculeAndCode(Matricule $matricule, Code $code): ?Employee;
|
||||
|
||||
public function findByMatricule(Matricule $matricule): ?Employee;
|
||||
|
||||
/**
|
||||
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $matricules
|
||||
* @return array<int, Employee>
|
||||
*/
|
||||
public function getWhereMatriculeIn(array | Collection $matricules): array;
|
||||
|
||||
/**
|
||||
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $matricules
|
||||
* @return array<string, Employee>
|
||||
*/
|
||||
public function getWithCustomerWhereMatriculeIn(array | Collection $matricules): array;
|
||||
|
||||
/**
|
||||
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $excludedMatricules
|
||||
* @return array<int, Employee>
|
||||
*/
|
||||
public function getWithCustomerWhereMatriculeNotIn(array | Collection $excludedMatricules): array;
|
||||
|
||||
public function getMostRecentSyncDate(): ?\DateTimeInterface;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Repositories;
|
||||
|
||||
use App\Contracts\Repository;
|
||||
use App\Models\Order;
|
||||
use Carbon\CarbonInterface;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/**
|
||||
* @extends Repository<Order, UuidInterface>
|
||||
*/
|
||||
interface OrderRepository extends Repository
|
||||
{
|
||||
public function find(UuidInterface $id): ?Order;
|
||||
|
||||
public function persist(Order $order): void;
|
||||
|
||||
public function delete(Order $order): void;
|
||||
|
||||
/** @return array<array-key, Order> */
|
||||
public function getAll(): array;
|
||||
|
||||
/** @return array<array-key, Order> */
|
||||
public function getValidatedOrdersForPickupDay(CarbonInterface $pickupDay): array;
|
||||
|
||||
public function hasValidatedOrderForPickupDay(Matricule $matricule, CarbonInterface $pickupDay): bool;
|
||||
|
||||
/** @return array<array-key, Order> */
|
||||
public function getOrdersWithLinesAndShopForPickupDay(CarbonInterface $pickupDay): array;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts\Repositories;
|
||||
|
||||
use App\Contracts\Repository;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* @extends Repository<User, int>
|
||||
*/
|
||||
interface UserRepository extends Repository
|
||||
{
|
||||
public function find(int $id): ?User;
|
||||
|
||||
public function persist(User $user): void;
|
||||
|
||||
public function delete(User $user): void;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
/**
|
||||
* @template TModel of \Illuminate\Database\Eloquent\Model
|
||||
* @template TId of \Ramsey\Uuid\UuidInterface|int
|
||||
*
|
||||
* @method TModel|null find(TId $id)
|
||||
* @method void persist(TModel $model)
|
||||
* @method void delete(TModel $model)
|
||||
*/
|
||||
interface Repository
|
||||
{
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Services\BasketService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Basket\AddToBasketInput, void>
|
||||
*/
|
||||
final class AddToBasket implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BasketService $basketService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isInstanceOf($input, AddToBasketInput::class);
|
||||
|
||||
$this->basketService->add(
|
||||
$input->productId,
|
||||
$input->qty
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\Entities\ProductId;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class AddToBasketInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public ProductId $productId,
|
||||
public int $qty,
|
||||
) {
|
||||
Assert::greaterThan($qty, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Contracts\ActionInputEmpty;
|
||||
use Domain\Services\BasketService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Contracts\ActionInputEmpty, void>
|
||||
*/
|
||||
final class EmptyBasket implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BasketService $basketService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isInstanceOf(
|
||||
$input,
|
||||
ActionInputEmpty::class
|
||||
);
|
||||
|
||||
$this->basketService->empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Services\BasketService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Basket\RemoveQuantityFromBasketInput|\App\Cqs\Actions\Basket\RemoveProductFromBasketInput, void>
|
||||
*/
|
||||
final class RemoveFromBasket implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BasketService $basketService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isInstanceOfAny(
|
||||
$input,
|
||||
[
|
||||
RemoveQuantityFromBasketInput::class,
|
||||
RemoveProductFromBasketInput::class,
|
||||
]
|
||||
);
|
||||
|
||||
if ($input instanceof RemoveQuantityFromBasketInput) {
|
||||
$this->basketService->remove(
|
||||
$input->productId,
|
||||
$input->qty
|
||||
);
|
||||
} elseif ($input instanceof RemoveProductFromBasketInput) {
|
||||
$this->basketService->removeLine(
|
||||
$input->productId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\Entities\ProductId;
|
||||
|
||||
final readonly class RemoveProductFromBasketInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public ProductId $productId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Basket;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\Entities\ProductId;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class RemoveQuantityFromBasketInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public ProductId $productId,
|
||||
public int $qty,
|
||||
) {
|
||||
Assert::greaterThan($qty, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithOrder;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use SortDirection;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Common\ChangeModelOrderInput, bool>
|
||||
*/
|
||||
final class ChangeModelOrder implements Action
|
||||
{
|
||||
private const int MAX_ORDER_VALUE = 4294967295;
|
||||
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Common\ChangeModelOrderInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): bool
|
||||
{
|
||||
Assert::isInstanceOf($input, ChangeModelOrderInput::class);
|
||||
|
||||
$model = $input->model;
|
||||
$goUp = $input->direction === SortDirection::Ascending;
|
||||
$currentOrder = $model->getOrder();
|
||||
|
||||
$usesSoftDeletes = in_array(SoftDeletes::class, class_uses_recursive($model), true)
|
||||
|| method_exists($model, 'trashed');
|
||||
|
||||
/** @var Builder<Model&ModelWithOrder> $baseQuery */
|
||||
$baseQuery = $usesSoftDeletes
|
||||
// @phpstan-ignore method.notFound (withTrashed)
|
||||
? $model::query()->withTrashed()
|
||||
: $model::query();
|
||||
|
||||
/** @var (Model&ModelWithOrder)|null $adjacentModel */
|
||||
$adjacentModel = $baseQuery
|
||||
->where('order', $goUp ? '<' : '>', $currentOrder)
|
||||
->orderBy('order', $goUp ? SortDirection::Descending : SortDirection::Ascending)
|
||||
->first();
|
||||
|
||||
if ($adjacentModel === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->permuteModelOrders($model, $adjacentModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function permuteModelOrders(Model & ModelWithOrder $model1, Model & ModelWithOrder $model2): void
|
||||
{
|
||||
$order1 = $model1->getOrder();
|
||||
$order2 = $model2->getOrder();
|
||||
|
||||
// Deactivate timestamps to avoid updating updated_at
|
||||
$model1->timestamps = false;
|
||||
$model2->timestamps = false;
|
||||
|
||||
$model1->setOrder(self::MAX_ORDER_VALUE);
|
||||
$model1->saveQuietly();
|
||||
|
||||
$model2->setOrder($order1);
|
||||
$model2->saveQuietly();
|
||||
|
||||
$model1->setOrder($order2);
|
||||
$model1->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithOrder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use SortDirection;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ChangeModelOrderInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Model & ModelWithOrder $model,
|
||||
public SortDirection $direction,
|
||||
) {
|
||||
Assert::isInstanceOf($this->model, Model::class);
|
||||
Assert::isInstanceOf($this->model, ModelWithOrder::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithOrder;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Common\ChangeModelOrderPositionInput, bool>
|
||||
*/
|
||||
final class ChangeModelOrderPosition implements Action
|
||||
{
|
||||
private const int MAX_ORDER_VALUE = 4294967295;
|
||||
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Common\ChangeModelOrderPositionInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): bool
|
||||
{
|
||||
Assert::isInstanceOf($input, ChangeModelOrderPositionInput::class);
|
||||
|
||||
$model = $input->model;
|
||||
$currentOrder = $model->getOrder();
|
||||
$targetOrder = $input->targetOrder;
|
||||
|
||||
if ($currentOrder === $targetOrder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$usesSoftDeletes = in_array(SoftDeletes::class, class_uses_recursive($model), true)
|
||||
|| method_exists($model, 'trashed');
|
||||
|
||||
/** @var Builder<Model&ModelWithOrder> $baseQuery */
|
||||
$baseQuery = $usesSoftDeletes
|
||||
// @phpstan-ignore method.notFound (withTrashed)
|
||||
? $model::query()->withTrashed()
|
||||
: $model::query();
|
||||
|
||||
/** @var int|null $maxOrder */
|
||||
$maxOrder = (clone $baseQuery)->max('order');
|
||||
if ($maxOrder !== null && $targetOrder > $maxOrder) {
|
||||
$targetOrder = (int) $maxOrder;
|
||||
}
|
||||
|
||||
if ($currentOrder === $targetOrder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Deactivate timestamps
|
||||
$model->timestamps = false;
|
||||
|
||||
// Step 1: Temporarily park the moving model at MAX_ORDER_VALUE
|
||||
$model->setOrder(self::MAX_ORDER_VALUE);
|
||||
$model->saveQuietly();
|
||||
|
||||
if ($targetOrder < $currentOrder) {
|
||||
// Moving UP
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<int, Model&ModelWithOrder> $itemsToShift */
|
||||
$itemsToShift = (clone $baseQuery)
|
||||
->where('order', '>=', $targetOrder)
|
||||
->where('order', '<', $currentOrder)
|
||||
->whereKeyNot($model->getKey())
|
||||
->orderBy('order', 'desc')
|
||||
->get();
|
||||
|
||||
foreach ($itemsToShift as $item) {
|
||||
$item->timestamps = false;
|
||||
$item->setOrder($item->getOrder() + 1);
|
||||
$item->saveQuietly();
|
||||
}
|
||||
} else {
|
||||
// Moving DOWN
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<int, Model&ModelWithOrder> $itemsToShift */
|
||||
$itemsToShift = (clone $baseQuery)
|
||||
->where('order', '>', $currentOrder)
|
||||
->where('order', '<=', $targetOrder)
|
||||
->whereKeyNot($model->getKey())
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
|
||||
foreach ($itemsToShift as $item) {
|
||||
$item->timestamps = false;
|
||||
$item->setOrder($item->getOrder() - 1);
|
||||
$item->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Set the moving model to the target order
|
||||
$model->setOrder($targetOrder);
|
||||
$model->saveQuietly();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithOrder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ChangeModelOrderPositionInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Model & ModelWithOrder $model,
|
||||
public int $targetOrder,
|
||||
) {
|
||||
Assert::isInstanceOf($this->model, Model::class);
|
||||
Assert::isInstanceOf($this->model, ModelWithOrder::class);
|
||||
Assert::greaterThanEq($this->targetOrder, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Enums\MassActionType;
|
||||
use App\Interfaces\ModelWithStar;
|
||||
use App\Interfaces\ModelWithStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Common\ExecuteMassActionInput, int>
|
||||
*/
|
||||
final class ExecuteMassAction implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Common\ExecuteMassActionInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): int
|
||||
{
|
||||
Assert::isInstanceOf($input, ExecuteMassActionInput::class);
|
||||
|
||||
$this->assertModelMatchesInput($input);
|
||||
|
||||
return $this->updateModel($input);
|
||||
}
|
||||
|
||||
private function assertModelMatchesInput(ExecuteMassActionInput $input): void
|
||||
{
|
||||
$modelClass = $input->modelClass;
|
||||
switch ($input->action) {
|
||||
case MassActionType::Star:
|
||||
case MassActionType::Unstar:
|
||||
Assert::isAOf($modelClass, ModelWithStar::class);
|
||||
break;
|
||||
|
||||
case MassActionType::Publish:
|
||||
case MassActionType::Unpublish:
|
||||
Assert::isAOf($modelClass, ModelWithStatus::class);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \UnexpectedValueException('Unsupported mass action type: ' . $input->action->value);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateModel(ExecuteMassActionInput $input): int
|
||||
{
|
||||
$modelClass = $input->modelClass;
|
||||
/** @var class-string<Model> $modelClass */
|
||||
$model = new $modelClass();
|
||||
|
||||
$models = $modelClass::query()
|
||||
->whereIn($model->getKeyName(), $input->modelKeyList)
|
||||
->get();
|
||||
|
||||
$updated = 0;
|
||||
|
||||
foreach ($models as $foundModel) {
|
||||
if (! $foundModel instanceof Model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($input->action) {
|
||||
case MassActionType::Star:
|
||||
/** @var Model&ModelWithStar $foundModel */
|
||||
$foundModel->setStar(true);
|
||||
break;
|
||||
|
||||
case MassActionType::Unstar:
|
||||
/** @var Model&ModelWithStar $foundModel */
|
||||
$foundModel->setStar(false);
|
||||
break;
|
||||
|
||||
case MassActionType::Publish:
|
||||
/** @var Model&ModelWithStatus $foundModel */
|
||||
$foundModel->setStatus(true);
|
||||
break;
|
||||
|
||||
case MassActionType::Unpublish:
|
||||
/** @var Model&ModelWithStatus $foundModel */
|
||||
$foundModel->setStatus(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \UnexpectedValueException('Unsupported mass action type: ' . $input->action->value);
|
||||
}
|
||||
|
||||
$foundModel->saveOrFail();
|
||||
$updated++;
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Enums\MassActionType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ExecuteMassActionInput implements ActionInput
|
||||
{
|
||||
/**
|
||||
* @param class-string<Model> $modelClass
|
||||
* @param array<int|string> $modelKeyList
|
||||
*/
|
||||
public function __construct(
|
||||
public string $modelClass,
|
||||
public MassActionType $action,
|
||||
public array $modelKeyList,
|
||||
) {
|
||||
Assert::classExists($this->modelClass);
|
||||
Assert::isAOf($this->modelClass, Model::class);
|
||||
Assert::notEmpty($this->modelKeyList);
|
||||
Assert::allScalar($this->modelKeyList);
|
||||
|
||||
foreach ($this->modelKeyList as $modelKey) {
|
||||
Assert::stringNotEmpty((string) $modelKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithStar;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Common\ToggleModelStarInput, \Illuminate\Database\Eloquent\Model&\App\Interfaces\ModelWithStar>
|
||||
*/
|
||||
final class ToggleModelStar implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Common\ToggleModelStarInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): Model & ModelWithStar
|
||||
{
|
||||
Assert::isInstanceOf($input, ToggleModelStarInput::class);
|
||||
|
||||
$model = $input->model;
|
||||
$model->toggleStar();
|
||||
$model->saveOrFail();
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithStar;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ToggleModelStarInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Model & ModelWithStar $model,
|
||||
) {
|
||||
Assert::isInstanceOf($this->model, Model::class);
|
||||
Assert::isInstanceOf($this->model, ModelWithStar::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<
|
||||
* \App\Cqs\Actions\Common\ToggleModelStatusInput,
|
||||
* \Illuminate\Database\Eloquent\Model&\App\Interfaces\ModelWithStatus
|
||||
* >
|
||||
*/
|
||||
final class ToggleModelStatus implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Common\ToggleModelStatusInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): Model & ModelWithStatus
|
||||
{
|
||||
Assert::isInstanceOf($input, ToggleModelStatusInput::class);
|
||||
|
||||
$model = $input->model;
|
||||
$model->toggleStatus();
|
||||
$model->saveOrFail();
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Common;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Interfaces\ModelWithStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ToggleModelStatusInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Model & ModelWithStatus $model,
|
||||
) {
|
||||
Assert::isInstanceOf($this->model, Model::class);
|
||||
Assert::isInstanceOf($this->model, ModelWithStatus::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Services\CrmService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Crm\UnsubscribeFromNewsletterInput, \App\Cqs\Actions\Crm\UnsubscribeFromNewsletterOutput>
|
||||
*/
|
||||
final class UnsubscribeFromNewsletter implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CrmService $crmService
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): UnsubscribeFromNewsletterOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, UnsubscribeFromNewsletterInput::class);
|
||||
|
||||
try {
|
||||
$isUnsubscribed = $this->crmService->unsubscribeCustomer(
|
||||
$input->hashcode
|
||||
);
|
||||
|
||||
return $isUnsubscribed ? UnsubscribeFromNewsletterOutput::SUCCESS : UnsubscribeFromNewsletterOutput::FAILURE;
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return UnsubscribeFromNewsletterOutput::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
|
||||
final readonly class UnsubscribeFromNewsletterInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public CrmHashcode $hashcode
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
enum UnsubscribeFromNewsletterOutput
|
||||
{
|
||||
case SUCCESS;
|
||||
case INVALIDLINK;
|
||||
case FAILURE;
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Services\CrmService;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Crm\UpdateCustomerInput, \App\Cqs\Actions\Crm\UpdateCustomerOutput>
|
||||
*/
|
||||
final class UpdateCustomer implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AppCustomerAuthService $authService,
|
||||
private readonly CrmService $crmService
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): UpdateCustomerOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, UpdateCustomerInput::class);
|
||||
|
||||
$customer = $this->authService->getCustomerAsMandatory();
|
||||
|
||||
try {
|
||||
/** @var array{firstname:string,lastname:string,birth_date:string,phone?:string,address?:string,postcode:string,city:string,opt_in?:bool} $data */
|
||||
$data = [
|
||||
'firstname' => $input->firstname,
|
||||
'lastname' => $input->lastname,
|
||||
'birth_date' => $input->birthDate,
|
||||
'postcode' => $input->postcode,
|
||||
'city' => $input->city,
|
||||
'opt_in' => $input->optIn,
|
||||
];
|
||||
|
||||
if ($input->phone !== null) {
|
||||
$data['phone'] = $input->phone;
|
||||
}
|
||||
|
||||
if ($input->address !== null) {
|
||||
$data['address'] = $input->address;
|
||||
}
|
||||
|
||||
$result = $this->crmService->updateCustomerInfos(
|
||||
$customer,
|
||||
$data
|
||||
);
|
||||
|
||||
return new UpdateCustomerOutput($result);
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return new UpdateCustomerOutput(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
|
||||
final readonly class UpdateCustomerInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public string $firstname,
|
||||
public string $lastname,
|
||||
public string $birthDate,
|
||||
public ?string $phone,
|
||||
public ?string $address,
|
||||
public string $postcode,
|
||||
public string $city,
|
||||
public bool $optIn,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use Domain\Models\ValueObjects\CrmCustomer;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
final readonly class UpdateCustomerOutput
|
||||
{
|
||||
public function __construct(
|
||||
public CrmCustomer | ValidationException | false $result
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Services\CrmService;
|
||||
use Domain\Models\ValueObjects\CrmCustomer;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Crm\UpdateCustomerPasswordInput, \App\Cqs\Actions\Crm\UpdateCustomerPasswordOutput>
|
||||
*/
|
||||
final class UpdateCustomerPassword implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AppCustomerAuthService $authService,
|
||||
private readonly CrmService $crmService
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): UpdateCustomerPasswordOutput
|
||||
{
|
||||
Assert::isInstanceOf($input, UpdateCustomerPasswordInput::class);
|
||||
|
||||
$hashcode = $this->authService->getCustomerAsMandatory()->hashcode;
|
||||
|
||||
$crmCustomer = $this->crmService->getCustomerFromHashCode(
|
||||
$hashcode
|
||||
);
|
||||
|
||||
if ($crmCustomer instanceof CrmCustomer === false) {
|
||||
return new UpdateCustomerPasswordOutput(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->crmService->changePassword(
|
||||
$crmCustomer,
|
||||
$input->currentPassword,
|
||||
$input->newPassword,
|
||||
);
|
||||
|
||||
return new UpdateCustomerPasswordOutput($result);
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return new UpdateCustomerPasswordOutput(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class UpdateCustomerPasswordInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
#[\SensitiveParameter]
|
||||
public string $currentPassword,
|
||||
#[\SensitiveParameter]
|
||||
public string $newPassword,
|
||||
) {
|
||||
Assert::notEmpty($currentPassword);
|
||||
Assert::notEmpty($newPassword);
|
||||
Assert::notSame($currentPassword, $newPassword);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Crm;
|
||||
|
||||
use Domain\Models\ValueObjects\CrmCustomer;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
final readonly class UpdateCustomerPasswordOutput
|
||||
{
|
||||
public function __construct(
|
||||
public CrmCustomer | ValidationException | false $result
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Customers;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Contracts\Repositories\EmployeeRepository;
|
||||
use App\Exceptions\Crm\CrmCustomerExistsException;
|
||||
use App\Exceptions\CrmServiceException;
|
||||
use App\Models\Customer;
|
||||
use App\Services\CrmService;
|
||||
use Domain\Enums\Country;
|
||||
use Domain\Models\ValueObjects\CrmCustomer;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Customers\RegisterCustomerInput, \App\Models\Customer>
|
||||
*/
|
||||
final class RegisterCustomer implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AppCustomerAuthService $authService,
|
||||
private readonly CrmService $crmService,
|
||||
private readonly EmployeeRepository $employeeRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Customers\RegisterCustomerInput $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): Customer
|
||||
{
|
||||
Assert::isInstanceOf($input, RegisterCustomerInput::class);
|
||||
|
||||
// * Persist and associate Customer + Employee
|
||||
$customer = new Customer([
|
||||
'email' => $input->email,
|
||||
]);
|
||||
// * Temp hashcode to satisfy constraint
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->saveOrFail();
|
||||
|
||||
$employee = $this->employeeRepository->findByMatriculeAndCode(
|
||||
$input->matricule,
|
||||
$input->code
|
||||
);
|
||||
|
||||
if (! $employee) {
|
||||
throw new ModelNotFoundException('Employee not found');
|
||||
}
|
||||
|
||||
$employee->customer()->associate($customer);
|
||||
$employee->saveOrFail();
|
||||
|
||||
$crmCustomer = new CrmCustomer(
|
||||
hashcode: null,
|
||||
email: $input->email->value,
|
||||
password: $input->password,
|
||||
firstname: $input->firstname,
|
||||
lastname: $input->lastname,
|
||||
birthDate: $input->birthDate->format('Y-m-d'),
|
||||
phone: $input->phone?->value,
|
||||
address: $input->address,
|
||||
address2: null,
|
||||
city: $input->city,
|
||||
postcode: $input->postcode,
|
||||
country: Country::france,
|
||||
optIn: $input->optIn,
|
||||
status: false,
|
||||
lastConnection: null,
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $this->crmService->persist($crmCustomer);
|
||||
|
||||
if (! $result->hashcode) {
|
||||
throw new \UnexpectedValueException(
|
||||
'CRM did not return a hashcode for the created customer'
|
||||
);
|
||||
}
|
||||
|
||||
$customer->hashcode = CrmHashcode::fromString($result->hashcode);
|
||||
$customer->saveOrFail();
|
||||
|
||||
$customer->sendEmailVerificationNotification();
|
||||
|
||||
$this->authService->logIn($customer);
|
||||
|
||||
return $customer;
|
||||
} catch (CrmCustomerExistsException) {
|
||||
throw ValidationException::withMessages([
|
||||
'error' => trans('An account is already associated with this email address'),
|
||||
]);
|
||||
} catch (CrmServiceException $e) {
|
||||
report($e);
|
||||
throw ValidationException::withMessages([
|
||||
'error' => trans('An error has occurred. Please try again later'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Customers;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\Code;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\PhoneNumber;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class RegisterCustomerInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Matricule $matricule,
|
||||
public Code $code,
|
||||
public string $firstname,
|
||||
public string $lastname,
|
||||
public Email $email,
|
||||
public string $password,
|
||||
public \DateTimeImmutable $birthDate,
|
||||
public ?PhoneNumber $phone,
|
||||
public ?string $address,
|
||||
public string $postcode,
|
||||
public string $city,
|
||||
public bool $optIn = false,
|
||||
) {
|
||||
Assert::stringNotEmpty(trim($this->firstname));
|
||||
Assert::maxLength($this->firstname, 255);
|
||||
Assert::stringNotEmpty(trim($this->lastname));
|
||||
Assert::maxLength($this->lastname, 255);
|
||||
Assert::stringNotEmpty(trim($this->password));
|
||||
Assert::stringNotEmpty(trim($this->postcode));
|
||||
Assert::maxLength($this->postcode, 20);
|
||||
Assert::stringNotEmpty(trim($this->city));
|
||||
Assert::maxLength($this->city, 255);
|
||||
if ($this->address !== null) {
|
||||
Assert::maxLength($this->address, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Discount;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Discounts\CreateDiscountInput, \App\Models\Discount>
|
||||
*/
|
||||
final class CreateDiscount implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Discounts\CreateDiscountInput $input
|
||||
*/
|
||||
public function __invoke(ActionInput $input): Discount
|
||||
{
|
||||
Assert::isInstanceOf($input, CreateDiscountInput::class);
|
||||
|
||||
$discount = new Discount();
|
||||
$discount->type = $input->type;
|
||||
$discount->value = $input->value;
|
||||
$discount->is_old_price_displayed = $input->is_old_price_displayed;
|
||||
$discount->date_start = $input->period->start !== null ? Carbon::instance($input->period->start) : null;
|
||||
$discount->date_end = $input->period->end !== null ? Carbon::instance($input->period->end) : null;
|
||||
|
||||
$discount->saveOrFail();
|
||||
|
||||
$this->syncAssociatedProducts($discount, $input->associatedProductsIds);
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $productIdList
|
||||
*/
|
||||
private function syncAssociatedProducts(Discount $discount, array $productIdList): void
|
||||
{
|
||||
Product::query()
|
||||
->where('discount_id', $discount->id)
|
||||
->whereNotIn('id', $productIdList)
|
||||
->update(['discount_id' => null]);
|
||||
|
||||
if (! empty($productIdList)) {
|
||||
Product::query()
|
||||
->whereIn('id', $productIdList)
|
||||
->update(['discount_id' => $discount->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class CreateDiscountInput implements ActionInput
|
||||
{
|
||||
/**
|
||||
* @param array<string> $associatedProductsIds
|
||||
*/
|
||||
public function __construct(
|
||||
public DiscountType $type,
|
||||
public DiscountValue $value,
|
||||
public bool $is_old_price_displayed,
|
||||
public DatePeriod $period = new DatePeriod(),
|
||||
public array $associatedProductsIds = [],
|
||||
) {
|
||||
Assert::same($this->type, $this->value->type, 'The discount value type must match the discount type.');
|
||||
Assert::allString($this->associatedProductsIds);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Discounts\DeleteDiscountInput, bool>
|
||||
*/
|
||||
final class DeleteDiscount implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Discounts\DeleteDiscountInput $input
|
||||
*/
|
||||
public function __invoke(ActionInput $input): bool
|
||||
{
|
||||
Assert::isInstanceOf($input, DeleteDiscountInput::class);
|
||||
|
||||
return (bool) $input->discount->deleteOrFail();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Discount;
|
||||
|
||||
final readonly class DeleteDiscountInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Discount $discount,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Discount;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Discounts\UpdateDiscountInput, \App\Models\Discount>
|
||||
*/
|
||||
final class UpdateDiscount implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Discounts\UpdateDiscountInput $input
|
||||
*/
|
||||
public function __invoke(ActionInput $input): Discount
|
||||
{
|
||||
Assert::isInstanceOf($input, UpdateDiscountInput::class);
|
||||
|
||||
$discount = $input->discount;
|
||||
$discount->type = $input->type;
|
||||
$discount->value = $input->value;
|
||||
$discount->is_old_price_displayed = $input->is_old_price_displayed;
|
||||
$discount->date_start = $input->period->start !== null ? Carbon::instance($input->period->start) : null;
|
||||
$discount->date_end = $input->period->end !== null ? Carbon::instance($input->period->end) : null;
|
||||
|
||||
$discount->saveOrFail();
|
||||
|
||||
$this->syncAssociatedProducts($discount, $input->associatedProductsIds);
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $productIdList
|
||||
*/
|
||||
private function syncAssociatedProducts(Discount $discount, array $productIdList): void
|
||||
{
|
||||
Product::query()
|
||||
->where('discount_id', $discount->id)
|
||||
->whereNotIn('id', $productIdList)
|
||||
->update(['discount_id' => null]);
|
||||
|
||||
if (! empty($productIdList)) {
|
||||
Product::query()
|
||||
->whereIn('id', $productIdList)
|
||||
->update(['discount_id' => $discount->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Discounts;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Discount;
|
||||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class UpdateDiscountInput implements ActionInput
|
||||
{
|
||||
/**
|
||||
* @param array<string> $associatedProductsIds
|
||||
*/
|
||||
public function __construct(
|
||||
public Discount $discount,
|
||||
public DiscountType $type,
|
||||
public DiscountValue $value,
|
||||
public bool $is_old_price_displayed,
|
||||
public DatePeriod $period = new DatePeriod(),
|
||||
public array $associatedProductsIds = [],
|
||||
) {
|
||||
Assert::same($this->type, $this->value->type, 'The discount value type must match the discount type.');
|
||||
Assert::allString($this->associatedProductsIds);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Employee;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Services\ArcadiaEmployee;
|
||||
use App\Services\EmployeeCsvImportLineService as ServicesEmployeeCsvImportLine;
|
||||
use App\Services\EmployeeCsvReaderService;
|
||||
use App\Services\EmployeeUpsertService;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
||||
use Domain\Models\ValueObjects\ShopperServiceCode;
|
||||
use Domain\Models\ValueObjects\ShopperSiteCode;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Employee\ImportEmployeesInput, \App\Cqs\Actions\Employee\ImportEmployeesOutput>
|
||||
*/
|
||||
final class ImportEmployees implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly EmployeeCsvReaderService $employeeCsvReaderService,
|
||||
private readonly EmployeeUpsertService $employeeUpsertService,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @param \App\Cqs\Actions\Employee\ImportEmployeesInput $input */
|
||||
public function __invoke(ActionInput $input): ImportEmployeesOutput
|
||||
{
|
||||
Assert::isAOf($input, ImportEmployeesInput::class);
|
||||
|
||||
$csvLines = $this->employeeCsvReaderService->importEmployeesFromCsv($input->inputStream);
|
||||
|
||||
$this->logger->debug('Retrieved employees from CSV.', [
|
||||
'count' => count([...$csvLines]),
|
||||
]);
|
||||
|
||||
$csvErrors = array_filter(
|
||||
$csvLines,
|
||||
fn ($employee) => is_string($employee)
|
||||
);
|
||||
|
||||
$importedEmployees = array_map(
|
||||
fn (ServicesEmployeeCsvImportLine $csvLine) => $this->mapToArcadiaEmployee($csvLine),
|
||||
array_filter(
|
||||
$csvLines,
|
||||
fn ($employee) => $employee instanceof ServicesEmployeeCsvImportLine
|
||||
)
|
||||
);
|
||||
|
||||
$employees = array_filter(
|
||||
$importedEmployees,
|
||||
fn ($employee) => $employee instanceof ArcadiaEmployee
|
||||
);
|
||||
|
||||
$mappingErrors = array_filter(
|
||||
$importedEmployees,
|
||||
fn ($employee) => is_string($employee)
|
||||
);
|
||||
|
||||
$result = $this->employeeUpsertService->upsertEmployees($employees);
|
||||
|
||||
$totalInserted = $result->insertedCount;
|
||||
$totalUpdated = $result->updatedCount;
|
||||
$errors = array_values([
|
||||
...$csvErrors,
|
||||
...$mappingErrors,
|
||||
...$result->errors,
|
||||
]);
|
||||
|
||||
$this->logger->info('Employee synchronization completed successfully.', [
|
||||
'total_inserted' => $totalInserted,
|
||||
'total_updated' => $totalUpdated,
|
||||
'errors_count' => count($errors),
|
||||
]);
|
||||
|
||||
return new ImportEmployeesOutput(
|
||||
insertedCount: $totalInserted,
|
||||
updatedCount: $totalUpdated,
|
||||
errors: $errors,
|
||||
);
|
||||
}
|
||||
|
||||
private function mapToArcadiaEmployee(ServicesEmployeeCsvImportLine $csvLine): ArcadiaEmployee | string
|
||||
{
|
||||
try {
|
||||
return new ArcadiaEmployee(
|
||||
matricule: new Matricule($csvLine->matricule),
|
||||
lastname: $csvLine->lastName,
|
||||
firstname: $csvLine->firstName,
|
||||
startDate: $csvLine->startDate,
|
||||
endDate: $csvLine->endDate ?? $csvLine->expectedEndDate,
|
||||
etablissement: new ShopperEstablishmentCode($csvLine->establishment),
|
||||
site: new ShopperSiteCode($csvLine->site),
|
||||
service: new ShopperServiceCode($csvLine->service),
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
return "Matricule {$csvLine->matricule}: {$e->getMessage()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Employee;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
|
||||
final readonly class ImportEmployeesInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public \SplFileObject $inputStream
|
||||
) {
|
||||
if (! $inputStream->isReadable()) {
|
||||
throw new \InvalidArgumentException('Input stream must be readable.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Employee;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class ImportEmployeesOutput
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $errors
|
||||
*/
|
||||
public function __construct(
|
||||
public int $insertedCount,
|
||||
public int $updatedCount,
|
||||
public array $errors
|
||||
) {
|
||||
Assert::greaterThanEq($insertedCount, 0);
|
||||
Assert::greaterThanEq($updatedCount, 0);
|
||||
Assert::allString($errors);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Employee;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Contracts\ActionInputEmpty;
|
||||
use App\Contracts\Repositories\EmployeeRepository;
|
||||
use App\Services\EmployeeSyncService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Contracts\ActionInputEmpty, void>
|
||||
*/
|
||||
final class SynchronizeEmployeesWithArcadiaApi implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EmployeeRepository $employeeRepository,
|
||||
private readonly EmployeeSyncService $syncService
|
||||
) {
|
||||
}
|
||||
|
||||
/** @param \App\Contracts\ActionInputEmpty $input */
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isAOf($input, ActionInputEmpty::class);
|
||||
|
||||
$wasLastSyncedAt = $this->employeeRepository->getMostRecentSyncDate();
|
||||
|
||||
$this->syncService->synchronize($wasLastSyncedAt);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Faq;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Faqs\CreateFaqInput, \App\Models\Faq>
|
||||
*/
|
||||
final class CreateFaq implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Faqs\CreateFaqInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): Faq
|
||||
{
|
||||
Assert::isInstanceOf($input, CreateFaqInput::class);
|
||||
|
||||
$faq = new Faq();
|
||||
$faq->fill([
|
||||
'question' => $input->question,
|
||||
'answer' => $input->answer,
|
||||
]);
|
||||
$faq->saveOrFail();
|
||||
|
||||
return $faq;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class CreateFaqInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public string $question,
|
||||
public string $answer,
|
||||
) {
|
||||
Assert::stringNotEmpty(trim($this->question), 'Question cannot be empty.');
|
||||
Assert::minLength(trim($this->question), 4);
|
||||
Assert::maxLength($this->question, 255);
|
||||
Assert::stringNotEmpty(trim($this->answer), 'Answer cannot be empty.');
|
||||
Assert::minLength(trim($this->answer), 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Faqs\DeleteFaqInput, void>
|
||||
*/
|
||||
final class DeleteFaq implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Faqs\DeleteFaqInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): void
|
||||
{
|
||||
Assert::isInstanceOf($input, DeleteFaqInput::class);
|
||||
|
||||
$input->faq->deleteOrFail();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Faq;
|
||||
|
||||
final readonly class DeleteFaqInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Faq $faq,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Faq;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Faqs\UpdateFaqInput, \App\Models\Faq>
|
||||
*/
|
||||
final class UpdateFaq implements Action
|
||||
{
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Faqs\UpdateFaqInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): Faq
|
||||
{
|
||||
Assert::isInstanceOf($input, UpdateFaqInput::class);
|
||||
|
||||
$faq = $input->faq;
|
||||
$faq->fill([
|
||||
'question' => $input->question,
|
||||
'answer' => $input->answer,
|
||||
]);
|
||||
$faq->saveOrFail();
|
||||
|
||||
return $faq;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Faqs;
|
||||
|
||||
use App\Contracts\ActionInput;
|
||||
use App\Models\Faq;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class UpdateFaqInput implements ActionInput
|
||||
{
|
||||
public function __construct(
|
||||
public Faq $faq,
|
||||
public string $question,
|
||||
public string $answer,
|
||||
) {
|
||||
Assert::stringNotEmpty(trim($this->question), 'Question cannot be empty.');
|
||||
Assert::minLength(trim($this->question), 4);
|
||||
Assert::maxLength($this->question, 255);
|
||||
Assert::stringNotEmpty(trim($this->answer), 'Answer cannot be empty.');
|
||||
Assert::minLength(trim($this->answer), 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Cqs\Actions\Orders;
|
||||
|
||||
use App\Contracts\Action;
|
||||
use App\Contracts\ActionInput;
|
||||
use Domain\Models\ValueObjects\PickupTimeSlot;
|
||||
use Domain\Services\OrderTunnelService;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Action<\App\Cqs\Actions\Orders\ApplyPickTimeSlotInput, ?\Domain\Models\ValueObjects\PickupTimeSlot>
|
||||
*/
|
||||
final class ApplyPickTimeSlot implements Action
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrderTunnelService $orderTunnelService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Cqs\Actions\Orders\ApplyPickTimeSlotInput $input
|
||||
*/
|
||||
#[\Override]
|
||||
public function __invoke(ActionInput $input): ?PickupTimeSlot
|
||||
{
|
||||
Assert::isInstanceOf($input, ApplyPickTimeSlotInput::class);
|
||||
|
||||
$builder = $this->orderTunnelService->getBuilderFromBasketOrFail();
|
||||
$shop = $this->orderTunnelService->getShopForCustomer($input->shopperId);
|
||||
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
||||
|
||||
return $this->orderTunnelService->applyTimeSlot(
|
||||
$builder,
|
||||
$shop,
|
||||
$input->timeslot,
|
||||
$timeSlots
|
||||
);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue