Skip to content

Commit

Permalink
fix(export): shares missing from app export (#87)
Browse files Browse the repository at this point in the history
* fix(profile): validate profile_website as URL

* chore(ci): switch from Homestead to Sail

* fix(profile): make website optional

* fix(export): include shares for app
  • Loading branch information
Fenrikur authored Sep 16, 2024
1 parent dad4835 commit 9f7a9fa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 93 deletions.
30 changes: 9 additions & 21 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ class ProfileController extends Controller
{
private static ImageManager $manager;

public function index()
{
}
public function index() {}

public function create(Request $request)
{
}
public function create(Request $request) {}

public static function createOrUpdate(Request $request, int $applicationId): Profile
{
Expand Down Expand Up @@ -85,25 +81,15 @@ public static function getByApplicationId(int|null $applicationId): Profile|null
return Profile::findByApplicationId($applicationId);
}

public function store(Request $request)
{
}
public function store(Request $request) {}

public function show(Profile $profile)
{
}
public function show(Profile $profile) {}

public function edit(Profile $profile)
{
}
public function edit(Profile $profile) {}

public function update(Request $request, Profile $profile)
{
}
public function update(Request $request, Profile $profile) {}

public function destroy(Profile $profile)
{
}
public function destroy(Profile $profile) {}

public static function getValidations()
{
Expand Down Expand Up @@ -137,6 +123,8 @@ public static function getValidations()
],
"profile_website" => [
'max:255',
'url:http,https',
'nullable',
],
"twitter" => [
'nullable',
Expand Down
28 changes: 16 additions & 12 deletions app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,23 @@ public static function getAllApplicationsForAppExport(): \Illuminate\Support\Col

$applications = self::query()->toBase()
->leftJoin('profiles', 'applications.id', '=', 'profiles.application_id')
->leftJoin('users', 'user_id', '=', 'users.id')
->leftJoin('users', 'applications.user_id', '=', 'users.id')
->leftJoin('applications as parents', 'applications.parent_id', '=', 'parents.id')
->leftJoinSub($keywords, 'profile_keywords', function (JoinClause $join) {
$join->on('profiles.id', '=', 'profile_keywords.profile_id');
})
->select(
'applications.id AS Reg No.',
'users.name AS Nick',
'display_name AS Display Name',
'applications.display_name AS Display Name',
DB::raw("'' as 'Merchandise'"),
DB::raw("CASE WHEN attends_thu = 1 THEN 'X' ELSE '' END AS 'Attends Thu'"),
DB::raw("CASE WHEN attends_fri = 1 THEN 'X' ELSE '' END AS 'Attends Fri'"),
DB::raw("CASE WHEN attends_sat = 1 THEN 'X' ELSE '' END AS 'Attends Sat'"),
DB::raw("'X' as 'Allows Use of Data'"),
DB::raw("CASE WHEN is_afterdark = 1 THEN 'X' ELSE '' END AS 'After Dark'"),
DB::raw("CASE WHEN applications.is_afterdark = 1 THEN 'X' ELSE '' END AS 'After Dark'"),
// TODO: Temporary fix for EF27 since "Table Number" is not supported by the app backend & apps
DB::raw("TRIM('\n' FROM CONCAT(IFNULL(CONCAT('Table ', table_number), ''), '\\n\\n', IFNULL(short_desc, ''))) AS 'Short Description'"),
DB::raw("TRIM('\n' FROM CONCAT(IFNULL(CONCAT('Table ', IFNULL(parents.table_number, applications.table_number)), ''), '\\n\\n', IFNULL(short_desc, ''))) AS 'Short Description'"),
'artist_desc AS About the Artist',
'art_desc AS About the Art',
'profiles.website as Website',
Expand All @@ -434,17 +435,20 @@ public static function getAllApplicationsForAppExport(): \Illuminate\Support\Col
DB::raw("CASE WHEN image_art IS NOT NULL THEN 'X' ELSE '' END AS 'ArtImg'"),
'profile_keywords.categorized_keywords as Keywords',
'tweet as Tweet',
'table_number as Table Number',
'type as Type',
DB::raw("IFNULL(parents.table_number, applications.table_number) AS 'Table Number'"),
'applications.type as Type',
)
->whereNotNull('offer_accepted_at')
->where(function (Builder $query) {
$query->where('type', ApplicationType::Dealer)
->orWhere('type', ApplicationType::Share);
$query->whereNotNull('applications.offer_accepted_at')
->orWhereNotNull('parents.offer_accepted_at');
})
->where(function (Builder $query) {
$query->where('applications.type', ApplicationType::Dealer)
->orWhere('applications.type', ApplicationType::Share);
})
->where(function (Builder $query) {
$query->where('profiles.is_hidden', '=', '0')
->orWhere('type', ApplicationType::Dealer);
->orWhere('applications.type', ApplicationType::Dealer);
})
->get();
return $applications;
Expand All @@ -460,8 +464,8 @@ public static function getAllApplicationsForAppExport(): \Illuminate\Support\Col
public function tableTypeAssignedAutoNull(): Attribute
{
return Attribute::make(
get: fn (int|null $value, array $attributes) => $attributes['table_type_assigned'],
set: fn (mixed $value) => [
get: fn(int|null $value, array $attributes) => $attributes['table_type_assigned'],
set: fn(mixed $value) => [
'table_type_assigned' => empty($value) ? null : intval($value),
]
);
Expand Down
64 changes: 44 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
context: ./vendor/laravel/sail/runtimes/8.3
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
MYSQL_CLIENT: mariadb-client
image: sail-8.3/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
Expand All @@ -22,10 +22,26 @@ services:
networks:
- sail
depends_on:
- mysql
- redis
mysql:
image: 'mysql/mysql-server:8.0'
- mariadb
- minio
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s
mariadb:
image: 'mariadb:11'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
Expand All @@ -34,40 +50,48 @@ services:
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
- 'sail-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mariadb/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
- healthcheck.sh
- '--connect'
- '--innodb_initialized'
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
minio:
image: 'minio/minio:latest'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
environment:
MINIO_ROOT_USER: sail
MINIO_ROOT_PASSWORD: password
volumes:
- 'sail-redis:/data'
- 'sail-minio:/data/minio'
networks:
- sail
command: 'minio server /data/minio --console-address ":8900"'
healthcheck:
test:
- CMD
- redis-cli
- ping
- curl
- '-f'
- 'http://localhost:9000/minio/health/live'
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
sail-redis:
driver: local
sail-mariadb:
driver: local
sail-minio:
driver: local
66 changes: 26 additions & 40 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,63 +1,49 @@
###
# Simplify development of the Laravel application using Homestead!
# (your milage on Windows may vary…)
# Simplify development of the Laravel application using Sail!
#
# Prerequisites:
# - vagrant
# - docker & compose
# - yq
# - Homestead (https://laravel.com/docs/10.x/homestead)
# - features mariadb & minio must be installed and enabled
# - additional port forwards:
# - 5173:5173 (vite)
# - 9600:9600 (MinIO)
# - 9601:9601 (MinIO console)
# - ensure that both a database and a writeable bucket are available
# - tailspin (optional; but you'll love it!)
#
# The up command will patch your Homestead.yaml to mount the correct directory
# to your Homestead VM.
#
# Add the following variables to a .env file to configure just how you need it:
# - HOMESTEAD_PATH: path to the directory of your local Homestead repo
# - HOMESTEAD_APP_PATH: path at which you expect your app directory (this one)
# to be mounted within the Homestead VM (must be one of
# the folders mapped in Homestead.yaml at folders[].to)
###

set dotenv-load := true

homestead_path := env_var_or_default('HOMESTEAD_PATH', '~/homestead')
homestead_app_path := env_var_or_default('HOMESTEAD_APP_PATH', '/home/vagrant/code')
sail_path := env_var_or_default('SAIL_PATH', './vendor/bin/sail')
tspin := `command -v tspin || true`

# list commands
default:
just --list

_homestead_activate APP_DIR: (_homestead "yq -i e '(.folders[] | select(.to == \""+homestead_app_path+"\").map) |= \""+APP_DIR+"\"' Homestead.yaml; vagrant reload --provision")
# bring Sail up (make sure to run `dev` in a separate shell for Vite)
up:
{{sail_path}} up

_homestead COMMAND:
cd {{homestead_path}};\
{{COMMAND}};
# rebuild Sail images without caching
build:
{{sail_path}} build --no-cache

# patch Homestead.yaml with app directory and reload VM with provisioning to apply
up: (_homestead_activate invocation_directory())
# run PHP commmands on Sail
php *ARGS:
{{sail_path}} php {{ARGS}}

# resume Homestead instance
resume: (_homestead "vagrant resume")
# run composer commmands on Sail
composer *ARGS:
{{sail_path}} composer {{ARGS}}

# suspend Homestead instance (gnite!)
suspend: (_homestead "vagrant suspend")
# run artisan commmands on Sail
artisan *ARGS:
{{sail_path}} artisan {{ARGS}}

# run COMMAND on Homestead instance via ssh
ssh COMMAND='': (_homestead "vagrant ssh"+(if COMMAND != '' { " -c '"+COMMAND+"'" } else { "" }))
# run NPM commmands on Sail
npm *ARGS:
{{sail_path}} npm {{ARGS}}

# bring up vite on Homestead
dev: (ssh 'cd app; npm run dev -- --host 0.0.0.0')
# run node commmands on Sail
node *ARGS:
{{sail_path}} node {{ARGS}}

# open MySQL shell on Homestead
mysql: (ssh "mysql -D "+env_var('DB_DATABASE'))
# bring up Vite on Sail
dev: (npm "i") (npm "run dev")

# tail laravel logs (using tailspin if available)
log:
just ssh 'tail -n100 -f {{homestead_app_path}}/storage/logs/laravel.log'{{if tspin != '' { ' | '+tspin } else { '' } }}

0 comments on commit 9f7a9fa

Please sign in to comment.