Skip to content

Commit

Permalink
Merge branch 'main' into gps
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho committed Jan 10, 2024
2 parents 571f815 + 841e02e commit 756c79b
Show file tree
Hide file tree
Showing 46 changed files with 748 additions and 176 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/web-create-and-publish-to-ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Deploy to Amazon ECR

on:
push:
branches:
- main

env:
AWS_REGION: eu-west-1 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: hero/web # set this to your Amazon ECR repository name

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
#IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f ./deployment/web-dev.dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
65 changes: 65 additions & 0 deletions app/Actions/Photos/ExtractLocationFromPhotoAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Actions\Photos;

use Illuminate\Http\UploadedFile;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;

class ExtractLocationFromPhotoAction implements ExtractsLocationFromPhoto
{
public function run(UploadedFile $photo): array
{
$manager = new ImageManager(new Driver());
$image = $manager->read($photo);
$all = $image->exif('GPS');

if (! $all) {
return [];
}

return $this->convertArrayToLatLng($all);
}

private function convertArrayToLatLng($gpsData)
{
$GPSLatitudeRef = $gpsData['GPSLatitudeRef'];
$GPSLatitude = $gpsData['GPSLatitude'];
$GPSLongitudeRef = $gpsData['GPSLongitudeRef'];
$GPSLongitude = $gpsData['GPSLongitude'];

$lat_degrees = $this->gps2Num($GPSLatitude[0] ?? null);
$lat_minutes = $this->gps2Num($GPSLatitude[1] ?? null);
$lat_seconds = $this->gps2Num($GPSLatitude[2] ?? null);

$lon_degrees = $this->gps2Num($GPSLongitude[0] ?? null);
$lon_minutes = $this->gps2Num($GPSLongitude[1] ?? null);
$lon_seconds = $this->gps2Num($GPSLongitude[2] ?? null);

$lat_direction = ($GPSLatitudeRef == 'W' || $GPSLatitudeRef == 'S') ? -1 : 1;
$lon_direction = ($GPSLongitudeRef == 'W' || $GPSLongitudeRef == 'S') ? -1 : 1;

$latitude = $lat_direction * ($lat_degrees + ($lat_minutes / 60) + ($lat_seconds / (60 * 60)));
$longitude = $lon_direction * ($lon_degrees + ($lon_minutes / 60) + ($lon_seconds / (60 * 60)));

return ['latitude' => $latitude, 'longitude' => $longitude];
}

private function gps2Num($coordPart)
{
if (! $coordPart) {
return 0;
}

$parts = explode('/', $coordPart);
if (count($parts) <= 0) {
return 0;
}

if (count($parts) == 1) {
return $parts[0];
}

return (float) $parts[0] / (float) $parts[1];
}
}
10 changes: 10 additions & 0 deletions app/Actions/Photos/ExtractsLocationFromPhoto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Actions\Photos;

use Illuminate\Http\UploadedFile;

interface ExtractsLocationFromPhoto
{
public function run(UploadedFile $photo): array;
}
73 changes: 73 additions & 0 deletions app/Console/Commands/GenerateRandomPhotos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

use function Laravel\Prompts\progress;

class GenerateRandomPhotos extends Command
{
protected $signature = 'app:generate-random-photos';

public function handle(): void
{
$user = User::query()
->where('email', '[email protected]')
->first();

$bar = progress('Generating 1M photos with tags...', 1_000_000);

$bar->start();

$now = now()->toDateTimeString();

for ($i = 0; $i < 200; $i++) {
$photos = [];
$items = [];
$tags = [];

for ($j = 0; $j < 5000; $j++) {
$photos[] = [
'user_id' => $user->id,
'path' => 'photos/default.jpg',
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photos')->insert($photos);

for ($j = 0; $j < 5000; $j++) {
$items[] = [
'photo_id' => $i * 5000 + $j + 2,
'item_id' => random_int(1, 300),
'picked_up' => 0,
'recycled' => 0,
'quantity' => 1,
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photo_items')->insert($items);

for ($k = 0; $k < 5000; $k++) {
$tags[] = [
'photo_item_id' => $i * 5000 + $k + 1,
'tag_id' => random_int(1, 1500),
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photo_item_tag')->insert($tags);

$bar->advance(5000);
}

$bar->finish();
}
}
2 changes: 2 additions & 0 deletions app/DTO/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class UserSettings extends Data
public function __construct(
#[Required, BooleanType]
public bool $picked_up_by_default = false,
#[Required, BooleanType]
public bool $recycled_by_default = false,
) {
}
}
3 changes: 3 additions & 0 deletions app/Filament/Resources/ItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('ID')
->sortable(),
TextColumn::make('name')
->sortable()
->searchable(),
Expand Down
3 changes: 3 additions & 0 deletions app/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('ID')
->sortable(),
TextColumn::make('name')
->sortable()
->searchable(),
Expand Down
9 changes: 9 additions & 0 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Hash;

class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['password'] = Hash::make('password');
$data['email_verified_at'] = now();

return $data;
}
}
18 changes: 18 additions & 0 deletions app/Http/Controllers/CopyPhotoItemController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers;

use App\Models\PhotoItem;

class CopyPhotoItemController extends Controller
{
public function __invoke(PhotoItem $photoItem): array
{
$newPhotoItem = $photoItem->replicate();
$newPhotoItem->save();

$newPhotoItem->tags()->sync($photoItem->tags);

return [];
}
}
17 changes: 0 additions & 17 deletions app/Http/Controllers/PhotoItemPickedUpController.php

This file was deleted.

21 changes: 21 additions & 0 deletions app/Http/Controllers/PhotoItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Http\Requests\UpdatePhotoItemRequest;
use App\Models\Photo;
use App\Models\PhotoItem;
use App\Models\User;
Expand All @@ -16,11 +17,31 @@ public function store(Photo $photo, Request $request)

$photo->items()->attach($request->item_id, [
'picked_up' => $user->settings->picked_up_by_default,
'recycled' => $user->settings->recycled_by_default,
]);

return [];
}

public function update(PhotoItem $photoItem, UpdatePhotoItemRequest $request): array
{
if ($request->filled('quantity')) {
$photoItem->quantity = $request->quantity;
}

if ($request->filled('picked_up')) {
$photoItem->picked_up = $request->picked_up;
}

if ($request->filled('recycled')) {
$photoItem->recycled = $request->recycled;
}

$photoItem->save();

return [];
}

public function destroy(PhotoItem $photoItem)
{
$photoItem->delete();
Expand Down
11 changes: 11 additions & 0 deletions app/Http/Controllers/PhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Models\Tag;
use App\Models\TagType;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Storage;
use Inertia\Inertia;

class PhotosController extends Controller
Expand Down Expand Up @@ -68,6 +70,15 @@ public function show(Photo $photo)
];
}

public function destroy(Photo $photo): RedirectResponse
{
$photo->delete();

Storage::disk('public')->delete($photo->path);

return redirect()->route('my-photos');
}

private function getNextPhotoUrl(Photo $photo): ?string
{
$nextPhoto = Photo::query()
Expand Down
Loading

0 comments on commit 756c79b

Please sign in to comment.