Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:UlGssQGrsDgLbYxxgWVAlVC6d/X22Ecr2W+GlqFK5i8=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build Laravel PHP Project

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
phpunit:
runs-on: ubuntu-latest
container:
image: kirschbaumdevelopment/laravel-test-runner:8.2

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install front-end dependencies
run: |
npm install
npm run build

- name: Install composer dependencies
run: |
composer update
composer install
- name: Prepare Laravel Application
run: |
cp .env.testing .env
php artisan migrate:fresh --env=testing

- name: Run Testsuite
run: php artisan test
11 changes: 11 additions & 0 deletions app/Enums/PlatformConnectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Enums;


enum PlatformConnectionType: string
{
case ENABLED = 'enabled';
case DISABLED = 'disabled';
case ARCHIVED = 'archived';
}
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/V1/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;


class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/Api/V1/PlatformConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
use App\Models\PlatformConnection;
use App\Http\Resources\PlatformConnectionResource;


class PlatformConnectionController extends Controller
{

/* Get all platform connections */
//*************************************************************
// GET: /api/platform_connection/
// GET: /api/v1/platform_connection/
// Request $req example:
// { "consumer_id": 1 }
// *************************************************************
Expand Down Expand Up @@ -45,7 +44,6 @@ public function store(StorePlatformConnectionRequest $req): PlatformConnectionRe
return response()->json(INVALID_REQUEST_BODY, 401);
}
}

// Get a specific platform connection by consumer or provider id
// *************************************************************
// GET: /api/v1/platform_connection/{id}
Expand Down Expand Up @@ -73,10 +71,10 @@ public function update(UpdatePlatformConnectionRequest $req): PlatformConnection
$validated = $req->validated();
$PlatformConnection = PlatformConnection::where($validated)->first();
$PlatformConnection->state = $validated['state'];
return new PlatformConnectionResource($PlatformConnection->save());
if (!$PlatformConnection) {
return response()->json(['error' => 'No matching platform connection found'], 401);
}
return new PlatformConnectionResource($PlatformConnection->save());
}

// Delete a platform connection
Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/Api/V1/ProviderPlatformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class ProviderPlatformController extends Controller
// ****************************************************
// GET: /api/provider_platforms/
// ****************************************************
public function index()
public function index(): \Illuminate\Http\Resources\Json\AnonymousResourceCollection
{
return ProviderPlatformResource::collection(ProviderPlatform::all(['*']));
}
//
// List information on a specific provider platform
// ****************************************************
// GET: /api/provider_platforms/{request_body}
// GET: /api/v1/provider_platforms/{request_body}
// @param Request $request
// @return JsonResponse
// ****************************************************
public function show(ShowProviderPlatformRequest $request, $id): ProviderPlatformResource|\Illuminate\Http\JsonResponse
public function show(ShowProviderPlatformRequest $request): ProviderPlatformResource|\Illuminate\Http\JsonResponse
{
$providerPlatform = ProviderPlatform::where('id', $id)->first();
$providerPlatform = ProviderPlatform::where('id', $request->id)->first();
if ($providerPlatform) {
return new ProviderPlatformResource($providerPlatform);
} else {
Expand Down Expand Up @@ -60,7 +60,7 @@ public function store(StoreProviderPlatformRequest $req): ProviderPlatformResour
// @return JsonResponse
// Request $request
// ****************************************************
public function update(StoreProviderPlatformRequest $request)
public function update(StoreProviderPlatformRequest $request): ProviderPlatformResource|\Illuminate\Http\JsonResponse
{
$validated = $request->validated();
$providerPlatform = ProviderPlatform::where($validated)->first();
Expand All @@ -78,9 +78,9 @@ public function update(StoreProviderPlatformRequest $request)
// Request $req example:
// { "provider_id": 1 }
// ****************************************************
public function destroy(Request $request, $providerId): \Illuminate\Http\JsonResponse
public function destroy(Request $request): \Illuminate\Http\JsonResponse
{
$providerPlatform = ProviderPlatform::where('id', $providerId)->first();
$providerPlatform = ProviderPlatform::where('id', $request->input('id'))->first();
if (!$providerPlatform) {
return response()->json(['error' => 'Invalid provider ID'], 401);
} else {
Expand Down
11 changes: 0 additions & 11 deletions app/Models/ConsumerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class ConsumerPlatform extends Model
{
Expand All @@ -22,17 +20,8 @@ class ConsumerPlatform extends Model
'api_key',
];

protected $casts = [
'type' => ConsumerPlatformType::class
];

public function platformConnections(): HasMany
{
return $this->hasMany(PlatformConnections::class);
}

public function providerPlatforms(): BelongsToMany
{
return $this->belongsToMany(ProviderPlatform::class, 'platform_connections')->withPivot('state', 'id');
}
}
8 changes: 2 additions & 6 deletions app/Models/PlatformConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ class PlatformConnection extends Model
use HasFactory;

protected $fillable = [
'consumer_platform_id',
'provider_platform_id',
'state',
'consumer_platform',
'provider_platform',
];

protected $casts = [
'state' => PlatformConnectionState::class
];

public function consumerPlatform(): BelongsTo
Expand Down
3 changes: 2 additions & 1 deletion app/Models/ProviderPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Models;

use App\Enums\ProviderPlatformType;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand All @@ -12,6 +12,7 @@ class ProviderPlatform extends Model
use HasFactory;

protected $fillable = [
'id',
'type',
'name',
'description',
Expand Down
Loading