Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
500cebb
melhorando autocomplete no laravel
josemotta Aug 16, 2021
7a726e9
criando model category
josemotta Aug 17, 2021
d056a0f
definicao recurso de categorias
josemotta Aug 17, 2021
4995709
resource categories post
josemotta Aug 19, 2021
7645b8d
exclusao logica
josemotta Aug 19, 2021
b3c51c4
substituindo id por uuid
josemotta Aug 19, 2021
ffdc136
desafio - criando recurso category
josemotta Aug 19, 2021
c069513
add genre model
josemotta Aug 20, 2021
1b43c61
remove gender model
josemotta Aug 20, 2021
fad67a8
fix typo
josemotta Aug 20, 2021
ff73ab7
criando crud de generos
josemotta Aug 20, 2021
cf771b8
iniciando com testes unitarios
josemotta Aug 20, 2021
1f22a31
boas praticas com testes unitarios
josemotta Aug 20, 2021
7f359bb
configuracao ambiente de testes
josemotta Aug 20, 2021
b216e30
conhecendo o ambiente exec testes phpunit
josemotta Aug 21, 2021
1e7f53c
iniciando com testes integracao DB
josemotta Aug 23, 2021
63b339e
testando criacao categoria
josemotta Aug 23, 2021
9a5ef60
testando edicao categoria
josemotta Aug 23, 2021
3154a9c
add test delete category
josemotta Aug 23, 2021
a7c1fd8
desafio - testes integracao categorias generos
josemotta Aug 23, 2021
cc08ec3
desafio - testes integracao categorias generos
josemotta Aug 23, 2021
f9f56f2
desafio - testes integracao categorias generos
josemotta Aug 23, 2021
fd510b0
fix factory at testUpdate
josemotta Aug 24, 2021
726c8ac
rev testDelete
josemotta Aug 24, 2021
65257c5
testando validacao dos dados
josemotta Aug 24, 2021
bdaa3a2
testando criacao e edicao de categorias
josemotta Aug 24, 2021
06aeb4d
rev comments
josemotta Aug 25, 2021
1ef7da4
desafio - testes com http
josemotta Aug 25, 2021
13b65e9
criando trait para organizar assercoes de erros
josemotta Aug 25, 2021
b2b121e
organizando assercoes de erros de valid para criaçao
josemotta Aug 25, 2021
e3d2bf4
organizando assercoes de erros de valid para criaçao
josemotta Aug 25, 2021
b09045a
organizando assercoes erros valid para edicao
josemotta Aug 26, 2021
f6148ba
organizando assercoes na criacao
josemotta Aug 26, 2021
3cfff3a
organizando assercoes na edicao
josemotta Aug 26, 2021
2fa6fe2
change repo for ci build
josemotta Sep 1, 2021
d3c5e59
fix micro-videos-app name at cloud build
josemotta Sep 1, 2021
976aaf6
fix www folder at cloud build
josemotta Sep 1, 2021
5d5ae6c
fix composer at cloud build
josemotta Sep 1, 2021
3455c81
fix .env files
josemotta Sep 1, 2021
f6611cd
fix GenreTest class name
josemotta Sep 1, 2021
87d568c
fix cloud build
josemotta Sep 1, 2021
0d8c266
fix 2 cloud build
josemotta Sep 1, 2021
d46eebc
Merge pull request #1 from bampli/develop
josemotta Sep 1, 2021
1c8897b
criando stubs
josemotta Sep 2, 2021
ec0596c
review terminal.integrated.shell.linux settings
josemotta Sep 3, 2021
56c7607
recuperando model pela Id de forma dinamica
josemotta Sep 4, 2021
79b1a59
usando BasicCrudController em category e genre
josemotta Sep 4, 2021
9f4e43f
fix localhost for DB_HOST
josemotta Sep 4, 2021
3bff62c
add CastMember
josemotta Sep 4, 2021
cdb15c7
trying to fix SQL error at cloudbuild with migrate:fresh
josemotta Sep 4, 2021
5298615
finish cast_member and remove --prefer-dist --optimize-autoloader fro…
josemotta Sep 4, 2021
84b7b1e
remove local SQL volume to fix CI build
josemotta Sep 6, 2021
e8be91a
add CastMemberUnitTest & adjust UnitTest names
josemotta Sep 6, 2021
d876e88
add video
josemotta Sep 6, 2021
2582811
add video controller test
josemotta Sep 6, 2021
f2b1391
testando crud de videos parte2
josemotta Sep 6, 2021
946c301
testando invalidacao dos relacionamentos de video
josemotta Sep 8, 2021
b0735a3
testando modo transacao
josemotta Sep 9, 2021
a287d42
testando modo transacao 2
josemotta Sep 9, 2021
3b57f22
fix @var for ->store()
josemotta Sep 9, 2021
18e1eed
fix @var for ->store()
josemotta Sep 9, 2021
224c4e6
fix CI
josemotta Sep 10, 2021
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
10 changes: 8 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/laravel-quickstart",
"workspaceFolder": "/laravel",

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
//"terminal.integrated.shell.linux": "/bin/bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"terminal.integrated.defaultProfile.linux": "bash"
},

// Add the IDs of extensions you want installed when the container is created.
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/laravel-quickstart:cached
- .:/laravel:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock
Expand Down
3 changes: 3 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

#On error no such file entrypoint.sh, execute in terminal - dos2unix .docker\entrypoint.sh
cp .env.example .env
cp .env.testing.example .env.testing

chown -R www-data:www-data .
composer install
php artisan key:generate
Expand Down
2 changes: 2 additions & 0 deletions .docker/mysql/initdb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE IF NOT EXISTS code_micro_videos;
CREATE DATABASE IF NOT EXISTS code_micro_videos_test;
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=base64:KXriJ44+bmjwlMw6u8kD2cvxoNssPsfu+E0oMb/DcQE=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_DATABASE=code_micro_videos
DB_USERNAME=root
DB_PASSWORD=
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

Expand Down
10 changes: 5 additions & 5 deletions .docker/app/.env → .env.testing.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
APP_NAME=Laravel
APP_ENV=local
APP_ENV=testing
APP_KEY=base64:KXriJ44+bmjwlMw6u8kD2cvxoNssPsfu+E0oMb/DcQE=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST={{ .Env._DB_HOST }}
DB_HOST=db
DB_PORT=3306
DB_DATABASE={{ .Env._DB_DATABASE }}
DB_USERNAME={{ .Env._DB_USERNAME }}
DB_PASSWORD={{ .Env._DB_PASSWORD }}
DB_DATABASE=code_micro_videos_test
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: ci
on:
push:
pull_request: [develop]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Rodando docker-compose"
run: docker-compose -f docker-compose.prod.yaml up -d app db redis nginx
env:
GOOGLE_CLOUD_PROJECT_ID: $PROJECT_ID
GOOGLE_CLOUD_KEY_FILE: service-account-storage.json
GOOGLE_CLOUD_STORAGE_BUCKET: code-micro-videos1
GOOGLE_CLOUD_STORAGE_API_URI: https://storage.cloud.google.com/code-micro-videos1
TESTING_PROD: true

# - name: "Chown in /var/www"
# run: docker exec -u root -t micro-videos-app chown -R www-data:www-data /var/www

# - name: "Rodando composer"
# run: docker exec -t micro-videos-app composer install --no-interaction -d /var/www

# - name: "Copiando backend .env"
# run: docker exec -t micro-videos-app cp .env.example /var/www/.env

# - name: "Copiando backend .env.testing"
# run: docker exec -t micro-videos-app cp .env.testing.example /var/www/.env.testing

# - name: "Rodando key:generate"
# run: docker exec -t micro-videos-app php /var/www/artisan key:generate

# - name: "Rodando migrations"
# run: docker exec -t micro-videos-app php /var/www/artisan migrate

- name: "Waiting php-fpm"
run: docker-compose -f docker-compose.prod.yaml up dockerize

- name: "Rodando Phpunit"
run: docker exec -t micro-videos-app php /var/www/vendor/bin/phpunit -c /var/www/phpunit.xml

# - name: "Copiando frontend .env"
# run: docker exec -t micro-videos-app cp /var/www/frontend/.env.example /var/www/frontend/.env

# - name: Install front-end
# run: docker exec -t micro-videos-app npm install --prefix /var/www/frontend

# - name: Permission on scripts/build.sh
# run: docker exec -t micro-videos-app chmod +x /var/www/frontend/scripts/build.sh

# - name: Build front-end
# run: docker exec -t micro-videos-app npm run build-laravel --prefix /var/www/frontend

# - name: Test Laravel and React integration
# run: docker exec -w /var/www -t micro-videos-app php artisan dusk --env=testing
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/public/storage
/storage/*.key
/vendor
.env
/.env
/.env.testing
.env.backup
.phpunit.result.cache
Homestead.json
Expand All @@ -15,3 +16,5 @@ yarn-error.log
.vscode/
.history/
.devcontainer/
_ide_helper_models.php
_ide_helper.php
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM php:7.3.6-fpm-alpine3.9

ARG USER www-data

RUN apk add --no-cache shadow openssl bash mysql-client nodejs npm git
RUN docker-php-ext-install pdo pdo_mysql

Expand All @@ -12,12 +14,12 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN usermod -u 1000 www-data
RUN usermod -u 1000 --shell /bin/bash www-data

WORKDIR /var/www

RUN rm -rf /var/www/html && ln -s public html

USER www-data
USER $USER

EXPOSE 9000
23 changes: 23 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:7.3.6-fpm-alpine3.9

RUN apk add --no-cache shadow openssl bash mysql-client nodejs npm git
RUN docker-php-ext-install pdo pdo_mysql

RUN touch /home/www-data/.bashrc | echo "PS1='\w\$ '" >> /home/www-data/.bashrc

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN usermod -u 1000 www-data

WORKDIR /var/www

RUN rm -rf /var/www/html && ln -s public html

USER www-data

EXPOSE 9000
56 changes: 56 additions & 0 deletions app/Http/Controllers/Api/BasicCrudController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

abstract class BasicCrudController extends Controller
{
protected abstract function model();

protected abstract function rulesStore();

protected abstract function rulesUpdate();

public function index()
{
return $this->model()::all();
}

public function store(Request $request)
{
$validatedData = $this->validate($request, $this->rulesStore());
$obj = $this->model()::create($validatedData);
$obj->refresh();
return $obj;
}

protected function findOrFail($id)
{
$model = $this->model();
$keyName = (new $model)->getRouteKeyName();
return $this->model()::where($keyName, $id)->firstOrFail();
}

public function show($id)
{
return $this->findOrFail($id);
}

public function update(Request $request, $id)
{
$obj = $this->findOrFail($id);
$validatedData = $this->validate($request, $this->rulesUpdate());
$obj->update($validatedData);
$obj->refresh(); // added refresh to fix VideoControllerTest.TestSave()
return $obj;
}

public function destroy($id)
{
$obj = $this->findOrFail($id);
$obj->delete();
return response()->noContent(); // status 204 - No content
}
}
34 changes: 34 additions & 0 deletions app/Http/Controllers/Api/CastMemberController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers\Api;

use App\Models\CastMember;
use Illuminate\Http\Request;

class CastMemberController extends BasicCrudController
{
private $rules;

public function __construct() // this is the only way to initialize
{
$this->rules = [
'name' => 'required|max:255',
'type' => 'required|in:' . implode(',', [CastMember::TYPE_ACTOR, CastMember::TYPE_DIRECTOR])
];
}

protected function model()
{
return CastMember::class;
}

protected function rulesStore()
{
return $this->rules;
}

protected function rulesUpdate()
{
return $this->rules;
}
}
30 changes: 30 additions & 0 deletions app/Http/Controllers/Api/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Controllers\Api;

use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends BasicCrudController
{
private $rules = [
'name' => 'required|max:255',
'description' => 'nullable',
'is_active' => 'boolean'
];

protected function model()
{
return Category::class;
}

protected function rulesStore()
{
return $this->rules;
}

protected function rulesUpdate()
{
return $this->rules;
}
}
29 changes: 29 additions & 0 deletions app/Http/Controllers/Api/GenreController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers\Api;

use App\Models\Genre;
use Illuminate\Http\Request;

class GenreController extends BasicCrudController
{
private $rules = [
'name' => 'required|max:255',
'is_active' => 'boolean'
];

protected function model()
{
return Genre::class;
}

protected function rulesStore()
{
return $this->rules;
}

protected function rulesUpdate()
{
return $this->rules;
}
}
Loading