refactor code style and code review

This commit is contained in:
2024-01-15 01:11:19 +03:00
parent bc2c8df9af
commit 12e4b419ce
16 changed files with 39 additions and 40 deletions

View File

@@ -6,8 +6,8 @@ use App\Models\BlogPost;
use App\Models\Recipe;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
class FeedService
{
@@ -46,21 +46,21 @@ class FeedService
$hotBlogPosts = collect(
DB::select($sql)
)
->map(fn($post) => BlogPost::find($post->id))
->map(fn ($post) => BlogPost::find($post->id))
->take(16)
->chunk(4);
$newbiesBlogPosts = User::orderBy('created_at', 'desc')
->withCount('author_of_blog_post')
->get()
->filter(fn($u) => $u->author_of_blog_post_count > 0)
->filter(fn ($u) => $u->author_of_blog_post_count > 0)
->take(4)
->pluck('id')
->map(fn($id) => User::find($id)->author_of_blog_post()->limit(2)->get())
->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get())
->flatten()
->random();
$randomRecipe = Recipe::where('created_at', '>=', $dateMin)
Recipe::where('created_at', '>=', $dateMin)
->where('created_at', '<=', $dateMax)
->inRandomOrder()
->limit(2)
@@ -69,7 +69,7 @@ class FeedService
$firstCollection = collect([$hotBlogPosts->first(), $newbiesBlogPosts->first()]);
$secondCollection = collect([$hotBlogPosts->skip(1)->first(), $newbiesBlogPosts->skip(1)->first()]);
return $firstCollection->concat($secondCollection)->filter(fn($el) => !is_null($el) && $el->id);
return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id);
// $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first());
// $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first());