Skip to content

Commit

Permalink
fix demo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
andy3471 committed Feb 28, 2024
1 parent b91eeaa commit 0daeb77
Show file tree
Hide file tree
Showing 30 changed files with 277 additions and 289 deletions.
3 changes: 2 additions & 1 deletion .idea/keyshare.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 28 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 6 additions & 26 deletions app/Console/Commands/CalculateKarma.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,30 @@

class CalculateKarma extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'karma:calculate';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Recalculate Karma';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$karma = DB::select(DB::raw('
SELECT (IFNULL(C.createdkeys,0) - IFNULL(O.ownedkeys,0)) AS karma, U.id FROM users AS U
$karma = DB::select('
SELECT (COALESCE(C.createdkeys, 0) - COALESCE(O.ownedkeys, 0)) AS karma, U.id FROM users AS U
LEFT OUTER JOIN (
SELECT COUNT(created_user_id) AS createdkeys, created_user_id AS user_id FROM `keys`
SELECT COUNT(created_user_id) AS createdkeys, created_user_id AS user_id FROM keys
GROUP BY created_user_id
) AS C
ON C.user_id = U.id
LEFT OUTER JOIN (
SELECT count(owned_user_id) AS ownedkeys, owned_user_id AS user_id FROM `keys`
SELECT count(owned_user_id) AS ownedkeys, owned_user_id AS user_id FROM keys
GROUP BY owned_user_id
) AS O
ON O.user_id = U.id'
));
ON O.user_id = U.id
');

Redis::del('karma');

Expand Down
3 changes: 3 additions & 0 deletions app/Models/Dlc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Dlc extends Model
{
use HasFactory;

protected $fillable = ['name', 'game_id', 'created_user_id'];

public function game()
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Game extends Model
{
use HasFactory;

protected $appends = [
'url',
];
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Group extends Model
{
use HasFactory;

//
}
2 changes: 2 additions & 0 deletions app/Models/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Key extends Model
{
use HasFactory;
use Notifiable;

protected $appends = [
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Subscription extends Model
{
use HasFactory;

//
}
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class User extends Authenticatable
{
use HasFactory;
use Notifiable;

protected $appends = [
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
|--------------------------------------------------------------------------
|
| This locale will be used by the Faker PHP library when generating fake
| data for your database seeds. For example, this will be used to get
| data for your database seeders. For example, this will be used to get
| localized telephone numbers, street address information and more.
|
*/
Expand Down
26 changes: 16 additions & 10 deletions database/factories/DlcFactory.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */
namespace Database\Factories;

use App\Models\Dlc;
use App\Models\Game;
use App\Models\User;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;

$factory->define(Dlc::class, function (Faker $faker) {
return [
'game_id' => Game::all()->random()->id,
'name' => $faker->unique()->realText(20),
'description' => $faker->paragraph($nbSentences = 1),
'created_user_id' => User::all()->random()->id,
];
});
class DlcFactory extends Factory
{
protected $model = Dlc::class;

public function definition(): array
{
return [
'game_id' => Game::all()->random()->id,
'name' => fake()->unique()->realText(20),
'description' => fake()->paragraph($nbSentences = 1),
'created_user_id' => User::all()->random()->id,
];
}
}
42 changes: 42 additions & 0 deletions database/factories/GameFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Database\Factories;

use App\Models\Game;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;

class GameFactory extends Factory
{
protected $model = Game::class;

public function definition(): array
{
if (config('igdb.enabled')) {
$igdb = IGDB::select(['name', 'summary', 'id'])
->with(['cover' => ['image_id']])
->orderBy('first_release_date', 'desc')
->whereNotNull('summary')
->whereNotNull('cover')
->where('aggregated_rating', '>=', 70)
->skip(rand(1, 1000))
->first();

return [
'name' => $igdb->name,
'description' => $igdb->summary,
'igdb_id' => $igdb->id,
'image' => 'https://images.igdb.com/igdb/image/upload/t_cover_big/'.$igdb->cover->image_id.'.jpg',
'igdb_updated' => Carbon::today(),
'created_user_id' => User::all()->random()->id,
];
} else {
return [
'name' => fake()->unique()->realText(20),
'description' => fake()->paragraph($nbSentences = 1),
'created_user_id' => User::all()->random()->id,
];
}
}
}
38 changes: 0 additions & 38 deletions database/factories/GamesFactory.php

This file was deleted.

Loading

0 comments on commit 0daeb77

Please sign in to comment.