Skip to content

Commit ba6d02a

Browse files
committed
WIP
1 parent c48a1ef commit ba6d02a

18 files changed

+408
-69
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class MeetController extends Controller
8+
{
9+
public function index()
10+
{
11+
return view('meet.index');
12+
}
13+
}

app/Http/Controllers/PostController.php

+15-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
class PostController extends Controller
1515
{
16-
public $action = "append";
1716

1817
/**
1918
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|null
@@ -77,6 +76,12 @@ public function edit(Request $request,Post $post)
7776
])->fragmentsIf(!$request->isMethodSafe());
7877
}
7978

79+
/**
80+
* @param \Illuminate\Http\Request $request
81+
* @param \App\Models\Post $post
82+
*
83+
* @return \Illuminate\Http\RedirectResponse
84+
*/
8085
public function update(Request $request, Post $post)
8186
{
8287
$this->authorize('isOwner', $post);
@@ -86,8 +91,8 @@ public function update(Request $request, Post $post)
8691
'content' => 'required|string',
8792
'type' => [
8893
$post->exists ? 'missing' : 'required',
89-
Rule::enum(PostTypeEnum::class)
90-
]
94+
Rule::enum(PostTypeEnum::class),
95+
],
9196
]);
9297

9398
$post->fill([
@@ -96,11 +101,15 @@ public function update(Request $request, Post $post)
96101
'user_id' => $request->user()->id,
97102
])->save();
98103

99-
//сюда поставить уведомление
100-
101-
return redirect()->route('post.edit', $post);//пока сюда
104+
return redirect()->route('post.show', $post);
102105
}
103106

107+
/**
108+
* @param \Illuminate\Http\Request $request
109+
* @param \App\Models\Post $post
110+
*
111+
* @return \Tonysm\TurboLaravel\Http\MultiplePendingTurboStreamResponse|\Tonysm\TurboLaravel\Http\PendingTurboStreamResponse
112+
*/
104113
public function delete(Request $request, Post $post)
105114
{
106115
$this->authorize('isOwner', $post);
@@ -128,14 +137,6 @@ public function list(Request $request)
128137

129138
$posts = $request->user()->attachLikeStatus($posts);
130139

131-
/*
132-
return view('particles.posts.list', [
133-
'posts' => $posts,
134-
'isMyProfile' => $request->has('user_id') && $request->user()?->id == $request->get('user_id'),
135-
'action' => $this->action
136-
])->fragmentsIf(!$request->isMethodSafe());
137-
*/
138-
139140
return turbo_stream([
140141
turbo_stream()->removeAll('.post-placeholder'),
141142
turbo_stream()->append('posts-frame', view('particles.posts.list', [

app/Http/Controllers/ProfileController.php

+28-12
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,48 @@ public function events(User $user, Request $request)
5252
}
5353

5454

55+
/**
56+
* @param \Illuminate\Http\Request $request
57+
* @param \App\Models\User $user
58+
*
59+
* @return \Illuminate\Contracts\View\View
60+
*/
61+
public function packages(User $user)
62+
{
63+
$packages = $user->packages()->orderBy('stars', 'desc')->get();
64+
65+
return view('profile.packages', [
66+
'packages' => $packages,
67+
'user' => $user,
68+
]);
69+
}
5570

5671

57-
public function comments(Request $request, User $user, array $data = [])
72+
/**
73+
* @param \Illuminate\Http\Request $request
74+
* @param \App\Models\User $user
75+
*
76+
* @return \Illuminate\Contracts\View\View
77+
*/
78+
public function comments(Request $request, User $user)
5879
{
59-
$comments = $user->comments()
80+
$comments = $user->comments()
6081
->withCount('likers')
6182
->orderBy('id', 'desc')
6283
->cursorPaginate(2);
63-
$comments->withPath('/profile/'.$user->nickname.'/comments');
84+
6485
$comments = $request->user()->attachLikeStatus($comments);
6586

66-
return view(
67-
'profile.comments',
68-
array_merge($data, [
69-
'comments' => $comments,
70-
'user' => $user,
71-
'active' => 'comments',
72-
])
73-
);
87+
return view('profile.comments', [
88+
'comments' => $comments,
89+
'user' => $user,
90+
]);
7491
}
7592

7693
public function awards(User $user)
7794
{
7895
return view('profile.awards', [
7996
'user' => $user,
80-
'active' => 'awards'
8197
]);
8298
}
8399

app/Http/Kernel.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class Kernel extends HttpKernel
4040
\App\Http\Middleware\VerifyCsrfToken::class,
4141
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4242
SetDefaultVersionForUrl::class,
43-
TurboRedirect::class,
44-
Turbo::class,
43+
'cache.headers:private;must_revalidate;etag',
4544
],
4645

4746
'api' => [

app/Jobs/UpdateStatusPackages.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use App\Models\Package;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldBeUnique;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Foundation\Bus\Dispatchable;
10+
use Illuminate\Queue\InteractsWithQueue;
11+
use Illuminate\Queue\SerializesModels;
12+
use Illuminate\Support\Facades\Http;
13+
14+
class UpdateStatusPackages implements ShouldQueue
15+
{
16+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17+
18+
/**
19+
* Create a new job instance.
20+
*/
21+
public function __construct(protected Package $package)
22+
{
23+
//
24+
}
25+
26+
/**
27+
* Execute the job.
28+
*/
29+
public function handle(): void
30+
{
31+
$info = Http::get("https://packagist.org/packages/{$this->package->packagist_name}.json")
32+
->collect('package')->only([
33+
'name',
34+
'description',
35+
'repository',
36+
'github_stars',
37+
'downloads',
38+
]);
39+
40+
$this->package->update([
41+
'stars' => $info['github_stars'],
42+
'downloads' => $info['downloads']['total'],
43+
]);
44+
}
45+
}

app/Models/Meet.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
class Meet extends Model
10+
{
11+
use HasFactory;
12+
13+
/**
14+
* @var string[]
15+
*/
16+
protected $fillable = [
17+
'user_id',
18+
'name',
19+
'description',
20+
'start_date',
21+
'address',
22+
'online',
23+
'link',
24+
];
25+
26+
/**
27+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
28+
*/
29+
public function author(): BelongsTo
30+
{
31+
return $this->belongsTo(User::class);
32+
}
33+
}

app/Models/Package.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
class Package extends Model
10+
{
11+
use HasFactory;
12+
13+
/**
14+
* @var string[]
15+
*/
16+
protected $fillable = [
17+
'user_id',
18+
'name',
19+
'description',
20+
'packagist_name',
21+
'website',
22+
'downloads',
23+
'stars',
24+
'approved',
25+
];
26+
27+
/**
28+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
29+
*/
30+
public function author(): BelongsTo
31+
{
32+
return $this->belongsTo(User::class);
33+
}
34+
}

app/Models/User.php

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ public function comments()
7070
return $this->hasMany(Comment::class);
7171
}
7272

73+
/**
74+
* Returns all packages that this user has made.
75+
*/
76+
public function packages()
77+
{
78+
return $this->hasMany(Package::class);
79+
}
80+
7381
/**
7482
* Returns only approved comments that this user has made.
7583
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('meets', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id');
17+
$table->string('name');
18+
$table->text('description');
19+
$table->timestamp('start_date');
20+
$table->string('address')->nullable();
21+
$table->boolean('online')->default(false);
22+
$table->string('link')->nullable();
23+
$table->boolean('approved')->default(true);
24+
$table->timestamps();
25+
26+
$table->foreign('user_id')
27+
->references('id')
28+
->on('users')
29+
->onDelete('cascade');
30+
});
31+
}
32+
33+
/**
34+
* Reverse the migrations.
35+
*/
36+
public function down(): void
37+
{
38+
Schema::dropIfExists('meets');
39+
}
40+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('packages', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id');
17+
$table->string('name');
18+
$table->text('description');
19+
$table->string('packagist_name')->unique();
20+
$table->string('website')->nullable();
21+
$table->bigInteger('downloads')->default(0);
22+
$table->bigInteger('stars')->default(0);
23+
24+
$table->boolean('approved')->default(true);
25+
$table->timestamps();
26+
27+
$table->foreign('user_id')
28+
->references('id')
29+
->on('users')
30+
->onDelete('cascade');
31+
});
32+
}
33+
34+
/**
35+
* Reverse the migrations.
36+
*/
37+
public function down(): void
38+
{
39+
Schema::dropIfExists('packages');
40+
}
41+
};

0 commit comments

Comments
 (0)