Compare commits
339 commits
fix-orders
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eda60066b1 | ||
|
|
276be44fa4 | ||
|
|
3a1b34602c | ||
|
|
d016a66601 | ||
|
|
df885e3805 | ||
|
|
178f2e0bda | ||
|
|
b6c5660d5e | ||
|
|
f7ce006c58 | ||
|
|
aaf7d442b3 | ||
|
|
083357f746 | ||
|
|
552d220b69 | ||
|
|
87136fcc42 | ||
|
|
b2989b4967 | ||
|
|
454695928b | ||
|
|
74ab9b3041 | ||
|
|
7a2004637d | ||
|
|
2dacdbabd6 | ||
|
|
d0efb0f527 | ||
|
|
9d2c5323ae | ||
|
|
bd8e90b5e4 | ||
|
|
ef674986c2 | ||
|
|
d5ed718874 | ||
|
|
0d527654ae | ||
|
|
64d418dcc9 | ||
|
|
946342d975 | ||
|
|
081c7a3599 | ||
|
|
e9454f9dbb | ||
|
|
78466ec482 | ||
|
|
eca7a9adbf | ||
|
|
192e72f554 | ||
|
|
327defbee0 | ||
|
|
dd4f4ce253 | ||
|
|
fab265cd68 | ||
|
|
24c151cc99 | ||
|
|
e8a6ab07de | ||
|
|
cd7d5f5fe9 | ||
|
|
0e05779f89 | ||
|
|
28d6200136 | ||
|
|
c8f895c759 | ||
|
|
c40016bba1 | ||
|
|
71e0d65f31 | ||
|
|
da0c3afc14 | ||
|
|
e857a58d00 | ||
|
|
cfac370e2e | ||
|
|
08354b44b6 | ||
|
|
ed593c25b0 | ||
|
|
c52b13cc51 | ||
|
|
7b910c5af6 | ||
|
|
961829a0c7 | ||
|
|
36faed679e | ||
|
|
cef7a4e4b0 | ||
|
|
a87f5756b2 | ||
|
|
f174aa74cf | ||
|
|
0874259eba | ||
|
|
dfaa74be01 | ||
|
|
3ac3cbc7ff | ||
|
|
62363253ce | ||
|
|
16dfc32f73 | ||
|
|
65df9aa04e | ||
|
|
584fee7e69 | ||
|
|
5d36639705 | ||
|
|
8e42639134 | ||
|
|
a94d8a4b49 | ||
|
|
b9999caf8d | ||
|
|
4d6ff9b726 | ||
|
|
82697ed416 | ||
|
|
0d5958aae6 | ||
|
|
e66f3ce17d | ||
|
|
0edef37e50 | ||
|
|
eb72abb9d2 | ||
|
|
0ea946a2f6 | ||
|
|
8be89194e3 | ||
|
|
f882b431b7 | ||
|
|
889cc66c07 | ||
|
|
9d28162ec4 | ||
|
|
5ca0f4ddde | ||
|
|
db684cf35f | ||
|
|
7a5c91e55e | ||
|
|
e2263911f3 | ||
|
|
aef658645b | ||
|
|
1e1172b757 | ||
|
|
a15cc29a61 | ||
|
|
b31602b040 | ||
|
|
8d43d71370 | ||
|
|
020e2f8526 | ||
|
|
35306547c9 | ||
|
|
c5fe5987da | ||
|
|
4b0775b5ea | ||
|
|
7a6c154e5f | ||
|
|
769949b3c3 | ||
|
|
5a0cc6c519 | ||
|
|
99586179d7 | ||
|
|
87e66c1d13 | ||
|
|
b3dc0ff3c4 | ||
|
|
14ceb300cf | ||
|
|
44ffc4d34e | ||
|
|
b166fa01e1 | ||
|
|
f9ded6d01c | ||
|
|
4ff3daecab | ||
|
|
6388c2a085 | ||
|
|
1899fd1f0e | ||
|
|
46e9a873ab | ||
|
|
8e213e2e33 | ||
|
|
644b3f6c16 | ||
|
|
c7535d3d04 | ||
|
|
87bd150f6b | ||
|
|
b8a0f16efa | ||
|
|
283038e5f4 | ||
|
|
57e12e06b6 | ||
|
|
46a3ae4dc3 | ||
|
|
afdd6cd0a7 | ||
|
|
99822b5a51 | ||
|
|
aeb8addbb8 | ||
|
|
0ca572537c | ||
|
|
dd05d9166c | ||
|
|
c4e1bfa80a | ||
|
|
1cf15950c6 | ||
|
|
713c937890 | ||
|
|
91a82af969 | ||
|
|
b67ea17584 | ||
|
|
d8f419cd2c | ||
|
|
055ce2eb5d | ||
|
|
c1ab6ef066 | ||
|
|
53f86fce63 | ||
|
|
0a1bfc9aed | ||
|
|
fee9609907 | ||
|
|
cecd808a80 | ||
|
|
75646a5f49 | ||
|
|
81dc370134 | ||
|
|
ce28473860 | ||
|
|
bd0cb02389 | ||
|
|
534e14f2e8 | ||
|
|
146bbf57bf | ||
|
|
38de1011ee | ||
|
|
c8eba4a932 | ||
|
|
f29ef10a43 | ||
|
|
639a8459d2 | ||
|
|
abde0bd5b9 | ||
|
|
0f6dc42bf2 | ||
|
|
49666d5364 | ||
|
|
9f99e06b7d | ||
|
|
09a506ccca | ||
|
|
5201aa3a5a | ||
|
|
240885577d | ||
|
|
80716ab7f7 | ||
|
|
7d5912e396 | ||
|
|
2831ad972b | ||
|
|
fa5abe7470 | ||
|
|
85f3896337 | ||
|
|
bf087c3bff | ||
|
|
450399fd74 | ||
|
|
46e9c58ad2 | ||
|
|
232561cb83 | ||
|
|
a7354cb051 | ||
|
|
3e4732bcb4 | ||
|
|
f67a8c88c9 | ||
|
|
255590a4d0 | ||
|
|
eacb445b55 | ||
|
|
b51d409a88 | ||
|
|
169fe52a26 | ||
|
|
bd4efb4587 | ||
|
|
5229999365 | ||
|
|
48443e4f82 | ||
|
|
c3f4c29c1a | ||
|
|
353b899c3f | ||
|
|
8cbbefb20b | ||
|
|
87661b2a60 | ||
|
|
17f898e3f9 | ||
|
|
4165bfecb5 | ||
|
|
8a9210123f | ||
|
|
14647576df | ||
|
|
50df658d58 | ||
|
|
3de48c14fd | ||
|
|
ba99113776 | ||
|
|
62104ebe28 | ||
|
|
f0667b7d3e | ||
|
|
5a9480ab93 | ||
|
|
5492ffe217 | ||
|
|
bae633e312 | ||
|
|
ff831beb01 | ||
|
|
d29561fe64 | ||
|
|
ae520d543d | ||
|
|
9e4da0e287 | ||
|
|
15e729cbe2 | ||
|
|
da0b32c7ee | ||
|
|
9a334b5ed1 | ||
|
|
b31ea9cad0 | ||
|
|
e8ed520a38 | ||
|
|
d4db0cffc6 | ||
|
|
3c309dc356 | ||
|
|
bf3e7a93fd | ||
|
|
52588ae999 | ||
|
|
f84a1a7b8c | ||
|
|
30c4483ce9 | ||
|
|
e0c4b34ed8 | ||
|
|
8b96ce90be | ||
|
|
55ea4b55f3 | ||
|
|
3398aacc86 | ||
|
|
6b649a8e7d | ||
|
|
3b3997d547 | ||
|
|
e5df954cf8 | ||
|
|
9ebf712170 | ||
|
|
aad9586ca9 | ||
|
|
35feddfb3d | ||
|
|
d912d4b096 | ||
|
|
8dd54f8824 | ||
|
|
2ae317aad6 | ||
|
|
70600ea623 | ||
|
|
668151fdaf | ||
|
|
9aab392350 | ||
|
|
274432a472 | ||
|
|
0fef2cfc98 | ||
|
|
6dd9ef90ae | ||
|
|
55ae6553d8 | ||
|
|
f79f1e1494 | ||
|
|
85dc683ed9 | ||
|
|
26992f52ff | ||
|
|
9f1b4242b9 | ||
|
|
b2c1b6eb1d | ||
|
|
c997b37047 | ||
|
|
8430458882 | ||
|
|
8a5246b389 | ||
|
|
b171b4a280 | ||
|
|
ea2885115d | ||
|
|
e0bc673f41 | ||
|
|
ecc03eee72 | ||
|
|
dafb8bfdf5 | ||
|
|
16dbdbdad1 | ||
|
|
46b5413f07 | ||
|
|
b36d070db1 | ||
|
|
5037154108 | ||
|
|
e89856966d | ||
|
|
2aa4fa8aed | ||
|
|
42bdae01cc | ||
|
|
31d7a789c4 | ||
|
|
e2e2a357f7 | ||
|
|
1fd2a3a1d8 | ||
|
|
8f6006e209 | ||
|
|
797d1da1b2 | ||
|
|
3ac95cc6f8 | ||
|
|
c2dd9e79c5 | ||
|
|
6e10308f53 | ||
|
|
054d22cc0c | ||
|
|
98e580d327 | ||
|
|
209b7e0193 | ||
|
|
41ce20a86e | ||
|
|
e34218eb27 | ||
|
|
cf5db041db | ||
|
|
a9ef1b910a | ||
|
|
c116a202ab | ||
|
|
bc25ee6f3c | ||
|
|
a1ad396a0e | ||
|
|
418b4e1941 | ||
|
|
23682def0d | ||
|
|
30077e68ad | ||
|
|
4ce5488bae | ||
|
|
668aaba1ca | ||
|
|
29fa8a1b7d | ||
|
|
ad36fd4596 | ||
|
|
4676d3de67 | ||
|
|
9c9d67ad37 | ||
|
|
5a0b68496e | ||
|
|
18e2baa1a8 | ||
|
|
507078363b | ||
|
|
a32e410314 | ||
|
|
8db44cdd53 | ||
|
|
1da093ebd2 | ||
|
|
f0ff70eb0c | ||
|
|
205865f524 | ||
|
|
acdb3ad13e | ||
|
|
284f69ec97 | ||
|
|
e2ae396154 | ||
|
|
8ab2702129 | ||
|
|
d8d745dba9 | ||
|
|
6adab479e0 | ||
|
|
e6a54a8acb | ||
|
|
b66fc01013 | ||
|
|
1f97e35046 | ||
|
|
0da6a85ff8 | ||
|
|
ce81ccd7ec | ||
|
|
c5dcba92eb | ||
|
|
477b01247e | ||
|
|
c359f8d68c | ||
|
|
54752d5d05 | ||
|
|
ec14a31f72 | ||
|
|
7e28b8cd94 | ||
|
|
e79a62b6f3 | ||
|
|
3d9bb99381 | ||
|
|
1f6f2a47f2 | ||
|
|
05357b16ec | ||
|
|
ed5de2f115 | ||
|
|
2da418dd01 | ||
|
|
149edff185 | ||
|
|
d7308fbc36 | ||
|
|
bc32abb4f1 | ||
|
|
ae50117098 | ||
|
|
07715c0097 | ||
|
|
924e435ff4 | ||
|
|
58af50b5c5 | ||
|
|
53e5f47bcf | ||
|
|
c9b64d4fe5 | ||
|
|
90af1eb37e | ||
|
|
7125bf8ead | ||
|
|
e5f3ea4d04 | ||
|
|
772cd92f85 | ||
|
|
f8537635bc | ||
|
|
a3c7193e05 | ||
|
|
2740798612 | ||
|
|
f07fae78a2 | ||
|
|
eb91d4d17f | ||
|
|
5cad93d548 | ||
|
|
152bc58474 | ||
|
|
5d2d58cd7a | ||
|
|
6ff2257144 | ||
|
|
f352408c40 | ||
|
|
c7c2175625 | ||
|
|
2c63b95f86 | ||
|
|
d74badf9b8 | ||
|
|
43a33daa01 | ||
|
|
4f5be11730 | ||
|
|
ed77e6aef9 | ||
|
|
2cf1a2761a | ||
|
|
3c2f785441 | ||
|
|
7661bba6ca | ||
|
|
8db9c7dc4c | ||
|
|
9a8d7b400a | ||
|
|
60497326fe | ||
|
|
2c0961dcc3 | ||
|
|
1f32078053 | ||
|
|
38771721ea | ||
|
|
7ccd63db5f | ||
|
|
5758a1d40c | ||
|
|
28448a34a7 | ||
|
|
f984799a02 | ||
|
|
a94589fb13 | ||
|
|
24cfb976f6 | ||
|
|
931a79444b | ||
|
|
c287334426 | ||
|
|
7547491e46 |
1822 changed files with 108357 additions and 60410 deletions
6
.browserslistrc
Normal file
6
.browserslistrc
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Browsers that we support
|
||||||
|
|
||||||
|
last 3 version
|
||||||
|
> 0.3%
|
||||||
|
not dead # no browsers without security updates
|
||||||
|
not Firefox < 100
|
||||||
|
|
@ -1,2 +1,11 @@
|
||||||
.git
|
.git/
|
||||||
|
.gitlab/
|
||||||
|
.gitlab-ci.yml
|
||||||
*.md
|
*.md
|
||||||
|
.vscode/
|
||||||
|
auth.json
|
||||||
|
Dockerfile
|
||||||
|
manifest.yaml
|
||||||
|
node_modules/
|
||||||
|
production-resources.yaml
|
||||||
|
.env.example
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,33 @@ root = true
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{php,json}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.blade.php]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
[*.{yml,yaml}]
|
[*.{yml,yaml}]
|
||||||
indent_size = 2
|
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,6 +3,7 @@ APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
APP_CURRENCY=EUR
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=debug
|
||||||
|
|
@ -15,22 +16,24 @@ DB_USERNAME=root
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=file
|
CACHE_STORE=file
|
||||||
QUEUE_CONNECTION=sync
|
QUEUE_CONNECTION=sync
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
FILESYSTEM_DISK=local
|
||||||
MAIL_HOST=smtp.mailtrap.io
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_SCHEME=null
|
||||||
|
MAIL_HOST=127.0.0.1
|
||||||
MAIL_PORT=2525
|
MAIL_PORT=2525
|
||||||
MAIL_USERNAME=
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
MAIL_FROM_ADDRESS=
|
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
MAIL_LIST_SERVICEWEB=
|
MAIL_TO_CONTACT=
|
||||||
MAIL_LIST_INVALIDINCO=
|
MAIL_TO_REGATE=
|
||||||
|
|
||||||
# CRM
|
# CRM
|
||||||
CRM_ENDPOINT=
|
CRM_ENDPOINT=
|
||||||
|
|
@ -48,3 +51,15 @@ MATOMO_SITE_ID=
|
||||||
UWIL_ADMIN_SECURE_CIDR_LIST=""
|
UWIL_ADMIN_SECURE_CIDR_LIST=""
|
||||||
# - LIST SEPARATED WITH ',' (Optional)
|
# - LIST SEPARATED WITH ',' (Optional)
|
||||||
UWIL_ADMIN_SECURE_CIDR_PROJECT_ALLOWED_LIST=""
|
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,5 +1,11 @@
|
||||||
* text=auto
|
* text=auto eol=lf
|
||||||
*.css linguist-vendored
|
|
||||||
*.scss linguist-vendored
|
*.blade.php diff=html
|
||||||
*.js linguist-vendored
|
*.css diff=css
|
||||||
|
*.html diff=html
|
||||||
|
*.md diff=markdown
|
||||||
|
*.php diff=php
|
||||||
|
|
||||||
|
/.github export-ignore
|
||||||
CHANGELOG.md export-ignore
|
CHANGELOG.md export-ignore
|
||||||
|
.styleci.yml export-ignore
|
||||||
|
|
|
||||||
53
.gitignore
vendored
53
.gitignore
vendored
|
|
@ -1,22 +1,51 @@
|
||||||
|
.env
|
||||||
|
.env.testing
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpunit.result.cache
|
||||||
|
.stylelintcache
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.phpunit.cache
|
||||||
|
/.vscode
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/bootstrap/cache
|
||||||
|
/public/build
|
||||||
|
/public/cache
|
||||||
/public/hot
|
/public/hot
|
||||||
|
/public/sitemap.xml
|
||||||
/public/storage
|
/public/storage
|
||||||
/public/images/content
|
|
||||||
/public/images/gammes
|
|
||||||
/public/images/produits
|
|
||||||
/public/images/slides
|
|
||||||
/public/b-o/
|
|
||||||
/public/mix-manifest.json
|
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
/vendor
|
/vendor
|
||||||
.env
|
coverage/
|
||||||
.env.backup
|
auth.json
|
||||||
.env.dev
|
docker-compose.override.yml
|
||||||
.env.prod
|
|
||||||
.phpunit.result.cache
|
|
||||||
Homestead.json
|
Homestead.json
|
||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
auth.json
|
|
||||||
.npmrc
|
.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
|
||||||
|
|
|
||||||
349
.gitlab-ci.yml
349
.gitlab-ci.yml
|
|
@ -1,23 +1,328 @@
|
||||||
include:
|
|
||||||
- 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"
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- lint
|
- install
|
||||||
- security
|
- lint
|
||||||
- build
|
- test
|
||||||
- test
|
- security
|
||||||
- deploy
|
- 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"
|
||||||
|
|
||||||
|
# * 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
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,4 @@
|
||||||
|
|
||||||
|
|
||||||
## Étapes pour la reproduction du bug
|
## Étapes pour la reproduction du bug
|
||||||
*
|
*
|
||||||
|
|
|
||||||
1058
.intellipest/_pest-helper.php
Normal file
1058
.intellipest/_pest-helper.php
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -5,9 +5,5 @@ php:
|
||||||
finder:
|
finder:
|
||||||
not-name:
|
not-name:
|
||||||
- index.php
|
- index.php
|
||||||
- server.php
|
js: true
|
||||||
js:
|
|
||||||
finder:
|
|
||||||
not-name:
|
|
||||||
- webpack.mix.js
|
|
||||||
css: true
|
css: true
|
||||||
|
|
|
||||||
43
.stylelintrc.json
Normal file
43
.stylelintrc.json
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"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": {
|
"workbench.colorCustomizations": {
|
||||||
"activityBar.activeBackground": "#920c7f",
|
"activityBar.activeBackground": "#920c7f",
|
||||||
"activityBar.activeBorder": "#1a1d02",
|
"activityBar.activeBorder": "#e7e7e7",
|
||||||
"activityBar.background": "#920c7f",
|
"activityBar.background": "#920c7f",
|
||||||
"activityBar.foreground": "#e7e7e7",
|
"activityBar.foreground": "#e7e7e7",
|
||||||
"activityBar.inactiveForeground": "#e7e7e799",
|
"activityBar.inactiveForeground": "#e7e7e799",
|
||||||
|
|
@ -11,13 +11,100 @@
|
||||||
"statusBar.background": "#630856",
|
"statusBar.background": "#630856",
|
||||||
"statusBar.foreground": "#e7e7e7",
|
"statusBar.foreground": "#e7e7e7",
|
||||||
"statusBarItem.hoverBackground": "#920c7f",
|
"statusBarItem.hoverBackground": "#920c7f",
|
||||||
"statusBarItem.remoteBackground": "#630856",
|
"statusBarItem.remoteBackground": "#66760a",
|
||||||
"statusBarItem.remoteForeground": "#e7e7e7",
|
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||||
"titleBar.activeBackground": "#630856",
|
"titleBar.activeBackground": "#630856",
|
||||||
"titleBar.activeForeground": "#e7e7e7",
|
"titleBar.activeForeground": "#e7e7e7",
|
||||||
"titleBar.inactiveBackground": "#63085699",
|
"titleBar.inactiveBackground": "#63085699",
|
||||||
"titleBar.inactiveForeground": "#e7e7e799",
|
"titleBar.inactiveForeground": "#e7e7e799",
|
||||||
"commandCenter.border": "#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"
|
||||||
},
|
},
|
||||||
"peacock.remoteColor": "#630856"
|
"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"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
68
CHANGELOG.md
68
CHANGELOG.md
|
|
@ -1,3 +1,71 @@
|
||||||
|
# (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
|
## 07-10-2022
|
||||||
* Nouvelle UX (mise à jour et ajout de composants vue, inplémentation de l'intégration dans des blades)
|
* Nouvelle UX (mise à jour et ajout de composants vue, inplémentation de l'intégration dans des blades)
|
||||||
|
|
||||||
|
|
|
||||||
53
Dockerfile
53
Dockerfile
|
|
@ -1,5 +1,52 @@
|
||||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-7.3:latest
|
ARG PHP_8_5_TAG=latest
|
||||||
COPY --chown=www-data:www-data . /app/srcs
|
|
||||||
|
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/
|
||||||
|
|
||||||
USER root
|
USER root
|
||||||
RUN chmod -R 755 /app/srcs/storage
|
RUN chmod -R 755 /app/srcs/storage
|
||||||
USER www-data
|
USER ${USER}
|
||||||
|
|
|
||||||
81
README.md
81
README.md
|
|
@ -1,37 +1,80 @@
|
||||||
## 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
|
## Installation
|
||||||
|
|
||||||
```
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
vi .env
|
||||||
composer install
|
composer install
|
||||||
php artisan storage:link
|
php artisan storage:link
|
||||||
cd ./ressources/views/front/
|
npm i
|
||||||
mkdir <theme-folder>
|
npm run prod
|
||||||
cd <theme-folder>
|
|
||||||
git clone <theme-repo> .
|
|
||||||
cd ./../../../../
|
|
||||||
npm install && npm run prod
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Production
|
## Tests
|
||||||
Put every min in PROD :
|
|
||||||
```php
|
```bash
|
||||||
|
cp .env.example .env.testing
|
||||||
|
vi .env.testing
|
||||||
|
composer install
|
||||||
|
php artisan storage:link
|
||||||
|
composer run test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
```bash
|
||||||
php artisan schedule:run
|
php artisan schedule:run
|
||||||
```
|
```
|
||||||
|
|
||||||
## Available Commands
|
## Available Commands
|
||||||
```
|
|
||||||
ldcweb:admin-secure-sync
|
```bash
|
||||||
|
php artisan ldcweb:admin-secure-sync
|
||||||
```
|
```
|
||||||
|
|
||||||
## Back-Office
|
**Créer un utilisateur :**
|
||||||
|
|
||||||
Création de compte
|
```bash
|
||||||
|
|
||||||
```
|
|
||||||
php artisan create:admin
|
php artisan create:admin
|
||||||
```
|
```
|
||||||
|
|
||||||
URL : /bo
|
## 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.
|
||||||
|
|
|
||||||
33
REGLES METIERS.md
Normal file
33
REGLES METIERS.md
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
# 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
Normal file
61
RGPD.md
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
# 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 |
|
||||||
150
app/Auth/CrmUserProvider.php
Normal file
150
app/Auth/CrmUserProvider.php
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Casts/CodeCast.php
Normal file
34
app/Casts/CodeCast.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Casts/CrmHashcodeCast.php
Normal file
44
app/Casts/CrmHashcodeCast.php
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Casts/DeliveryAddressCast.php
Normal file
61
app/Casts/DeliveryAddressCast.php
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Casts/DiscountValueCast.php
Normal file
65
app/Casts/DiscountValueCast.php
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Casts/EmailCast.php
Normal file
37
app/Casts/EmailCast.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
81
app/Casts/EmployeeSitesCast.php
Normal file
81
app/Casts/EmployeeSitesCast.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Casts/MatriculeCast.php
Normal file
33
app/Casts/MatriculeCast.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/Casts/MoneyCast.php
Normal file
45
app/Casts/MoneyCast.php
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
88
app/Casts/NutritionalValuesCast.php
Normal file
88
app/Casts/NutritionalValuesCast.php
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
62
app/Casts/OrderEmployeeCast.php
Normal file
62
app/Casts/OrderEmployeeCast.php
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
105
app/Casts/OrderLineProductCast.php
Normal file
105
app/Casts/OrderLineProductCast.php
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Casts/OrderReferenceCast.php
Normal file
34
app/Casts/OrderReferenceCast.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Casts/ShopperEstablishmentCodeCast.php
Normal file
37
app/Casts/ShopperEstablishmentCodeCast.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Casts/ShopperServiceCodeCast.php
Normal file
37
app/Casts/ShopperServiceCodeCast.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Casts/ShopperSiteCodeCast.php
Normal file
37
app/Casts/ShopperSiteCodeCast.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?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é.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
32
app/Console/Commands/MailTest.php
Normal file
32
app/Console/Commands/MailTest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Console/Commands/SyncProductIncosCommand.php
Normal file
38
app/Console/Commands/SyncProductIncosCommand.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
56
app/Console/Commands/UpsertEmployeesFormFile.php
Normal file
56
app/Console/Commands/UpsertEmployeesFormFile.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?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,39 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Domain\Enums\UserRole;
|
||||||
|
use Illuminate\Console\Attributes\Description;
|
||||||
|
use Illuminate\Console\Attributes\Signature;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Hash;
|
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
|
class UserCreate extends Command
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'user:create';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'creates an admin user upon password entry';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$firstname = $this->ask('What is the firstname?', 'Equipe');
|
$firstname = $this->askString('What is the firstname?', 'Equipe');
|
||||||
$lastname = $this->ask('What is the lastname?', 'Web');
|
$lastname = $this->askString('What is the lastname?', 'Web');
|
||||||
$email = $this->ask('What is the email?', 'equipe.web@ldc.fr');
|
$email = $this->askEmail('What is the email?', 'equipe.web@ldc.fr');
|
||||||
$pwd = $this->secret('What is the password?');
|
$pwd = $this->askPassword('What is the password?');
|
||||||
$role = $this->ask('What is the role? (1 = SuperAdmin, 2 = Admin)', 2);
|
$role = $this->askRole();
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->firstname = $firstname;
|
$user->firstname = $firstname;
|
||||||
|
|
@ -45,5 +39,101 @@ class UserCreate extends Command
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$this->info('User created.');
|
$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()}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
<?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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
<?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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
18
app/Contracts/Action.php
Normal file
18
app/Contracts/Action.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
9
app/Contracts/ActionInput.php
Normal file
9
app/Contracts/ActionInput.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface ActionInput
|
||||||
|
{
|
||||||
|
}
|
||||||
13
app/Contracts/ActionInputEmpty.php
Normal file
13
app/Contracts/ActionInputEmpty.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
final class ActionInputEmpty implements ActionInput
|
||||||
|
{
|
||||||
|
public static function create(): self
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Contracts/Directories/CustomerDirectory.php
Normal file
18
app/Contracts/Directories/CustomerDirectory.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
23
app/Contracts/Directories/EmployeeDirectory.php
Normal file
23
app/Contracts/Directories/EmployeeDirectory.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
48
app/Contracts/Directories/OrderDirectory.php
Normal file
48
app/Contracts/Directories/OrderDirectory.php
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
15
app/Contracts/Directory.php
Normal file
15
app/Contracts/Directory.php
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TEntity
|
||||||
|
* @template TId
|
||||||
|
*
|
||||||
|
* @method TEntity|null find(TId $id)
|
||||||
|
*/
|
||||||
|
interface Directory
|
||||||
|
{
|
||||||
|
}
|
||||||
19
app/Contracts/Executor.php
Normal file
19
app/Contracts/Executor.php
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
18
app/Contracts/Query.php
Normal file
18
app/Contracts/Query.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
9
app/Contracts/QueryInput.php
Normal file
9
app/Contracts/QueryInput.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface QueryInput
|
||||||
|
{
|
||||||
|
}
|
||||||
13
app/Contracts/QueryInputEmpty.php
Normal file
13
app/Contracts/QueryInputEmpty.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
final class QueryInputEmpty implements QueryInput
|
||||||
|
{
|
||||||
|
public static function create(): self
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
}
|
||||||
51
app/Contracts/Repositories/EmployeeRepository.php
Normal file
51
app/Contracts/Repositories/EmployeeRepository.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
34
app/Contracts/Repositories/OrderRepository.php
Normal file
34
app/Contracts/Repositories/OrderRepository.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
20
app/Contracts/Repositories/UserRepository.php
Normal file
20
app/Contracts/Repositories/UserRepository.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
17
app/Contracts/Repository.php
Normal file
17
app/Contracts/Repository.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?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
|
||||||
|
{
|
||||||
|
}
|
||||||
32
app/Cqs/Actions/Basket/AddToBasket.php
Normal file
32
app/Cqs/Actions/Basket/AddToBasket.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Cqs/Actions/Basket/AddToBasketInput.php
Normal file
19
app/Cqs/Actions/Basket/AddToBasketInput.php
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Cqs/Actions/Basket/EmptyBasket.php
Normal file
33
app/Cqs/Actions/Basket/EmptyBasket.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Cqs/Actions/Basket/RemoveFromBasket.php
Normal file
44
app/Cqs/Actions/Basket/RemoveFromBasket.php
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Basket/RemoveProductFromBasketInput.php
Normal file
16
app/Cqs/Actions/Basket/RemoveProductFromBasketInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Cqs/Actions/Basket/RemoveQuantityFromBasketInput.php
Normal file
19
app/Cqs/Actions/Basket/RemoveQuantityFromBasketInput.php
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
77
app/Cqs/Actions/Common/ChangeModelOrder.php
Normal file
77
app/Cqs/Actions/Common/ChangeModelOrder.php
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Cqs/Actions/Common/ChangeModelOrderInput.php
Normal file
22
app/Cqs/Actions/Common/ChangeModelOrderInput.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
102
app/Cqs/Actions/Common/ChangeModelOrderPosition.php
Normal file
102
app/Cqs/Actions/Common/ChangeModelOrderPosition.php
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Cqs/Actions/Common/ChangeModelOrderPositionInput.php
Normal file
22
app/Cqs/Actions/Common/ChangeModelOrderPositionInput.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
100
app/Cqs/Actions/Common/ExecuteMassAction.php
Normal file
100
app/Cqs/Actions/Common/ExecuteMassAction.php
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Cqs/Actions/Common/ExecuteMassActionInput.php
Normal file
32
app/Cqs/Actions/Common/ExecuteMassActionInput.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Cqs/Actions/Common/ToggleModelStar.php
Normal file
32
app/Cqs/Actions/Common/ToggleModelStar.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
app/Cqs/Actions/Common/ToggleModelStarInput.php
Normal file
20
app/Cqs/Actions/Common/ToggleModelStarInput.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Cqs/Actions/Common/ToggleModelStatus.php
Normal file
35
app/Cqs/Actions/Common/ToggleModelStatus.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
app/Cqs/Actions/Common/ToggleModelStatusInput.php
Normal file
20
app/Cqs/Actions/Common/ToggleModelStatusInput.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Cqs/Actions/Crm/UnsubscribeFromNewsletter.php
Normal file
39
app/Cqs/Actions/Crm/UnsubscribeFromNewsletter.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Crm/UnsubscribeFromNewsletterInput.php
Normal file
16
app/Cqs/Actions/Crm/UnsubscribeFromNewsletterInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/Cqs/Actions/Crm/UnsubscribeFromNewsletterOutput.php
Normal file
12
app/Cqs/Actions/Crm/UnsubscribeFromNewsletterOutput.php
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Cqs\Actions\Crm;
|
||||||
|
|
||||||
|
enum UnsubscribeFromNewsletterOutput
|
||||||
|
{
|
||||||
|
case SUCCESS;
|
||||||
|
case INVALIDLINK;
|
||||||
|
case FAILURE;
|
||||||
|
}
|
||||||
62
app/Cqs/Actions/Crm/UpdateCustomer.php
Normal file
62
app/Cqs/Actions/Crm/UpdateCustomer.php
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Cqs/Actions/Crm/UpdateCustomerInput.php
Normal file
22
app/Cqs/Actions/Crm/UpdateCustomerInput.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?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,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Crm/UpdateCustomerOutput.php
Normal file
16
app/Cqs/Actions/Crm/UpdateCustomerOutput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Cqs/Actions/Crm/UpdateCustomerPassword.php
Normal file
54
app/Cqs/Actions/Crm/UpdateCustomerPassword.php
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Cqs/Actions/Crm/UpdateCustomerPasswordInput.php
Normal file
22
app/Cqs/Actions/Crm/UpdateCustomerPasswordInput.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Crm/UpdateCustomerPasswordOutput.php
Normal file
16
app/Cqs/Actions/Crm/UpdateCustomerPasswordOutput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
113
app/Cqs/Actions/Customers/RegisterCustomer.php
Normal file
113
app/Cqs/Actions/Customers/RegisterCustomer.php
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?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'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Cqs/Actions/Customers/RegisterCustomerInput.php
Normal file
43
app/Cqs/Actions/Customers/RegisterCustomerInput.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
app/Cqs/Actions/Discounts/CreateDiscount.php
Normal file
56
app/Cqs/Actions/Discounts/CreateDiscount.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Cqs/Actions/Discounts/CreateDiscountInput.php
Normal file
28
app/Cqs/Actions/Discounts/CreateDiscountInput.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Cqs/Actions/Discounts/DeleteDiscount.php
Normal file
25
app/Cqs/Actions/Discounts/DeleteDiscount.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Discounts/DeleteDiscountInput.php
Normal file
16
app/Cqs/Actions/Discounts/DeleteDiscountInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
56
app/Cqs/Actions/Discounts/UpdateDiscount.php
Normal file
56
app/Cqs/Actions/Discounts/UpdateDiscount.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Cqs/Actions/Discounts/UpdateDiscountInput.php
Normal file
30
app/Cqs/Actions/Discounts/UpdateDiscountInput.php
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Cqs/Actions/Employee/ImportEmployees.php
Normal file
106
app/Cqs/Actions/Employee/ImportEmployees.php
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
<?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()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Cqs/Actions/Employee/ImportEmployeesInput.php
Normal file
18
app/Cqs/Actions/Employee/ImportEmployeesInput.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Cqs/Actions/Employee/ImportEmployeesOutput.php
Normal file
23
app/Cqs/Actions/Employee/ImportEmployeesOutput.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Cqs/Actions/Faqs/CreateFaq.php
Normal file
34
app/Cqs/Actions/Faqs/CreateFaq.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Cqs/Actions/Faqs/CreateFaqInput.php
Normal file
22
app/Cqs/Actions/Faqs/CreateFaqInput.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Cqs/Actions/Faqs/DeleteFaq.php
Normal file
26
app/Cqs/Actions/Faqs/DeleteFaq.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Cqs/Actions/Faqs/DeleteFaqInput.php
Normal file
16
app/Cqs/Actions/Faqs/DeleteFaqInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Cqs/Actions/Faqs/UpdateFaq.php
Normal file
34
app/Cqs/Actions/Faqs/UpdateFaq.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Cqs/Actions/Faqs/UpdateFaqInput.php
Normal file
24
app/Cqs/Actions/Faqs/UpdateFaqInput.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Cqs/Actions/Orders/ApplyPickTimeSlot.php
Normal file
42
app/Cqs/Actions/Orders/ApplyPickTimeSlot.php
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?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