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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/logs/*
!/logs/README.md
.idea/*
12 changes: 12 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteRule ^ index.php [QSA,L]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
34 changes: 0 additions & 34 deletions README.md

This file was deleted.

105 changes: 105 additions & 0 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Controllers;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
use App\Models\User;

class UserController
{
public function __construct()
{

}

public function index(Application $app, Request $request)
{
$users = User::all();
return $app->json(
[
'msg' => "Success when list user all",
'data' => $users
], 200, ['Content-Type' => 'application/json']
);
}

public function find(Application $app, Request $request, $id)
{
$user = User::find($id);

if ( !$user ) {
throw new Exception("User not found", 404);
}

return $app->json(
[
'msg' => "Success, found user",
'data' => $user
], 200, ['Content-Type' => 'application/json']
);
}

public function create(Application $app, Request $request)
{
$data = $request->request->all();
$password = crypt($data['password']);
$code = rand(000000000000, 999999999999)."-".rand(0, 9);
$user = new User($data);
$user->password = $password;
$user->code = $code;

try {
$user->save();
}catch (Exception $exception){
throw new Exception("Fields: name, email, phone, city and password are required!", 400);
}


return $app->json(
[
'msg' => "Success when register user",
'data' => $user
], 201, ['Content-Type' => 'application/json']
);
}

public function update(Application $app, Request $request, $id)
{
$user = User::find($id);
if ( !$user ) {
throw new Exception("User not found", 404);
}
$data = $request->request->all();
$password = crypt($data['password']);
$user->fill($data);
$user->password = $password;
$user->save();

return $app->json(
[
'msg' => "Success when update user",
'data' => $user
], 200, ['Content-Type' => 'application/json']
);
}

public function delete(Application $app, Request $request, $id)
{
$user = User::find($id);
if ( !$user ) {
throw new Exception("User not found", 404);
}
$user->delete();

return $app->json(
[
'msg' => "Success when deleting user",
'data' => $user
], 204, ['Content-Type' => 'application/json']
);

}
}
23 changes: 23 additions & 0 deletions app/Models/DrawDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;

class DrawDate extends Eloquent
{

protected $table = 'draw_dates';

protected $dates = ['date'];

protected $dateFormat = 'd/m';

protected $fillable = [

'id',
'date'
];


}
36 changes: 36 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent
{

protected $table = 'users';


protected $dates = [
'created_at',
'updated_at',
];

protected $fillable = [

'id',
'name',
'email',
'city',
'phone',
'code',
'status'

];

protected $hidden = [

'password'

];

}
35 changes: 35 additions & 0 deletions app/Models/Winner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Winner extends Eloquent
{

protected $table = 'winners';



protected $fillable = [

'id',
'user_id',
'draw_date_id',

];

public function user()
{

return $this->belongsTo('App\Models\User');
}

public function drawDate()
{

return $this->belongsTo('App\Models\DrawDate');
}


}
7 changes: 7 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php


require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/connection.php';

$app = new Silex\Application();
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require": {
"silex/silex": "~2.0",
"illuminate/database": "~5.5",
"symfony/twig-bridge": "~2.3",
"firebase/php-jwt": "^5.0"
},

"autoload-dev": {
"psr-4": {
"App\\": "app/"
}
}
}
Loading