Skip to content

Commit

Permalink
cleaned up some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjandrews committed Apr 4, 2017
1 parent 2849ec0 commit 1b80d6a
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 145 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/TodosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public function index()
return Todo::all();
}

public function store(Request $request)
public function create(Request $request)
{
return Todo::create($request->all());;
}

public function show(Request $request)
public function get(Request $request)
{
return Todo::findOrFail($request->id);
}
Expand All @@ -30,12 +30,12 @@ public function update(Request $request)
return $todo;
}

public function destroy(Request $request)
public function delete(Request $request)
{
return response(Todo::destroy($request->id), 204);
}

public function destroyAll()
public function deleteAll()
{
return response(Todo::getQuery()->delete(), 204);
}
Expand Down
10 changes: 6 additions & 4 deletions app/Todo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;

class Todo extends Model
{

protected $attributes = [
'completed' => false,
'position' => 0,
Expand All @@ -30,12 +31,13 @@ public function setOrderAttribute($value)

public function getUrlAttribute()
{
$url_arr = parse_url(url()->full());

$url_arr = parse_url(Request::url());
$url = $url_arr['scheme'].'://'.$url_arr['host'];

if ($url_arr['port'])
if (isset($url_arr['port']))
{
$url.':'.$url_arr['port'];
$url = $url.':'.$url_arr['port'];
}

return $url.'/'.$this->attributes['id'];
Expand Down
2 changes: 1 addition & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
set -e

bin/wait-for-postgres
bin/create-db
time php artisan migrate

time $1
12 changes: 6 additions & 6 deletions codeship-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ services:
links:
- postgres
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_DATABASE: todos
DB_USERNAME: todoapp
DB_PASSWORD: ''
TEST_DB_NAME: todos_testing
DATABASE_URL: postgres://todoapp@postgres/todos
cached: true
postgres:
image: postgres:9.6.2-alpine
environment:
POSTGRES_USER: todoapp
POSTGRES_DB: todos
deploy:
image: codeship/heroku-deployment
encrypted_env_file: deployment.env.encrypted
volumes:
- ./:/deploy
6 changes: 5 additions & 1 deletion codeship-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
steps:
- type: parallel
steps:
- name: phpunit
- name: tests
service: web
command: bin/ci phpunit
- name: deploy
tag: master
service: deploy
command: codeship_heroku deploy /deploy php-laravel-todoapp
113 changes: 11 additions & 102 deletions config/database.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,23 @@
<?php

return [
$url = parse_url(getenv("DATABASE_URL"));
$host = $url["host"];
$username = $url["user"];
$password = isset($url["pass"]) ?: '';
$database = substr($url["path"], 1);

/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
return [

'default' => env('DB_CONNECTION', 'pgsql'),

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/

'connections' => [

'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],

'pgsql_testing' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => 'todos_testing',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
Expand All @@ -82,41 +26,6 @@

],

/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/

'migrations' => 'migrations',

/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/

'redis' => [

'client' => 'predis',

'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],

],
'migrations' => 'migrations'

];
13 changes: 2 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@ services:
ngnix:
image: nginx:1.11.10-alpine
ports:
- "3000:80"
- "80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
links:
- web
web:
build: .
ports:
- "9000"
volumes:
- .:/app
links:
- postgres
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_DATABASE: todos
DB_USERNAME: todoapp
DB_PASSWORD: ''
DATABASE_URL: postgres://todoapp@postgres/todos
postgres:
image: postgres:9.6.2-alpine
volumes:
- ./bin/create-db:/docker-entrypoint-initdb.d/create-db
environment:
POSTGRES_USER: todoapp
POSTGRES_DB: todos
TEST_DB_NAME: todos_testing
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ server {
}

location ~ ^/.+\.php(/|$) {
fastcgi_pass app:9000;
fastcgi_pass web;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"cross-env": "^3.2.3",
"db-migrate": "^0.10.0-beta.20",
"jquery": "^3.1.1",
"laravel-mix": "^0.8.3",
"lodash": "^4.17.4",
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="pgsql_testing"/>
</php>
</phpunit>
19 changes: 13 additions & 6 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

use Illuminate\Http\Request;

Route::get('/', 'TodosController@index');
Route::post('/', 'TodosController@store');
Route::delete('/', 'TodosController@destroyAll');
Route::get('/{id}', 'TodosController@show');
Route::patch('/{id}', 'TodosController@update');
Route::delete('/{id}', 'TodosController@destroy');
Route::group(['prefix' => 'todos'], function() {

Route::get('/', "TodosController@index");
Route::post('/', "TodosController@create");
Route::delete('/', 'TodosController@deleteAll');

Route::group(['prefix' => '{id}'], function() {
Route::get('/', "TodosController@get");
Route::patch('/', "TodosController@update");
Route::delete('/', "TodosController@delete");
});

});
16 changes: 8 additions & 8 deletions tests/Feature/TodosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function tearDownAfterClass()
public function it_gets_all_todos()
{
factory(\App\Todo::class, 5)->create();
$response = $this->get('/', ['Origin' => "Testing"]);
$response = $this->get('/todos', ['Origin' => "Testing"]);
$response
->assertStatus(200)
->assertHeader('access-control-allow-origin', '*');
Expand All @@ -37,7 +37,7 @@ public function it_gets_all_todos()
/** @test */
public function it_creates_new_todo()
{
$response = $this->post('/', ['title' => 'Do something new!']);
$response = $this->post('/todos', ['title' => 'Do something new!']);

self::$currentTodo = $response->getOriginalContent();

Expand All @@ -51,7 +51,7 @@ public function it_creates_new_todo()
/** @test */
public function it_gets_one_todo()
{
$response = $this->get('/'.self::$currentTodo['id']);
$response = $this->get('/todos/'.self::$currentTodo['id']);

$response
->assertStatus(200)
Expand All @@ -61,7 +61,7 @@ public function it_gets_one_todo()
/** @test */
public function it_updates_todos()
{
$response = $this->patch('/'.self::$currentTodo['id'], ['title' => 'Do something else!', 'completed' => true, 'order' => 100] );
$response = $this->patch('/todos/'.self::$currentTodo['id'], ['title' => 'Do something else!', 'completed' => true, 'order' => 100] );
$response
->assertStatus(200)
->assertJson(['title' => 'Do something else!', 'completed' => true, 'order' => 100]);
Expand All @@ -70,21 +70,21 @@ public function it_updates_todos()
/** @test */
public function it_deletes_one_todo()
{
$response = $this->delete('/'.self::$currentTodo['id']);
$response = $this->delete('/todos/'.self::$currentTodo['id']);
$response->assertStatus(204);

$response = $this->get('/'.self::$currentTodo['id']);
$response = $this->get('/todos/'.self::$currentTodo['id']);
$response
->assertStatus(404);
}

/** @test */
public function it_clears_all_todos()
{
$response = $this->delete('/');
$response = $this->delete('/todos');
$response->assertStatus(204);

$response = $this->get('/');
$response = $this->get('/todos');
$response
->assertStatus(200);
$this->assertEquals(count( $response->getOriginalContent() ), 0);
Expand Down

0 comments on commit 1b80d6a

Please sign in to comment.