-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from larsverp/feature/points
Feature/points
- Loading branch information
Showing
8 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Points; | ||
|
||
use Illuminate\Http\Request; | ||
use App\hos_use; | ||
use App\cat_use; | ||
use App\points_settings; | ||
|
||
class Points | ||
{ | ||
static function Hosts($setting, $host, Request $request){ | ||
$settings = points_settings::pluck('setting')->toArray(); | ||
if(in_array($setting, $settings)){ | ||
$data = hos_use::where('host_id', $host) | ||
->where('user_id', $request->user()->id) | ||
->First(); | ||
if($data == null){ | ||
$data = hos_use::FindOrFail(hos_use::create(['host_id' => $host, 'user_id' => $request->user()->id])->id); | ||
} | ||
$newPoints = $data->points + points_settings::where('setting', $setting)->pluck('value')[0]; | ||
$data->update(['points' => $newPoints]); | ||
} | ||
else{ | ||
dd( response()->json([ | ||
'succes' => false, | ||
'reason' => 'The given setting is not a valid setting, see documentation for further info' | ||
], 403)); | ||
} | ||
} | ||
|
||
static function Categories($setting, $category, Request $request){ | ||
$settings = points_settings::pluck('setting')->toArray(); | ||
if(in_array($setting, $settings)){ | ||
$data = cat_use::where('category_id', $category) | ||
->where('user_id', $request->user()->id) | ||
->First(); | ||
if($data == null){ | ||
$data = cat_use::FindOrFail(cat_use::create(['category_id' => $category, 'user_id' => $request->user()->id])->id); | ||
} | ||
$newPoints = $data->points + points_settings::where('setting', $setting)->pluck('value')[0]; | ||
$data->update(['points' => $newPoints]); | ||
} | ||
else{ | ||
dd( response()->json([ | ||
'succes' => false, | ||
'reason' => 'The given setting is not a valid setting, see documentation for further info' | ||
], 403)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class cat_use extends Model | ||
{ | ||
protected $fillable = ['category_id', 'user_id', 'points', 'following']; | ||
|
||
public $timestamps = false; | ||
|
||
protected $hidden = [ | ||
'id', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
database/migrations/2020_05_22_080437_create_cat_uses_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCatUsesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('cat_uses', function (Blueprint $table) { | ||
$table->id(); | ||
$table->uuid('category_id'); | ||
$table->uuid('user_id'); | ||
$table->integer('points')->default(0); | ||
$table->boolean('following')->default(false); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('cat_uses'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters