mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Update HashtagFollowController, add store method
This commit is contained in:
parent
45e4cbe65c
commit
db49f5e052
1 changed files with 41 additions and 1 deletions
|
@ -3,8 +3,48 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Auth;
|
||||||
|
use App\{
|
||||||
|
Hashtag,
|
||||||
|
HashtagFollow,
|
||||||
|
Status
|
||||||
|
};
|
||||||
|
|
||||||
class HashtagFollowController extends Controller
|
class HashtagFollowController extends Controller
|
||||||
{
|
{
|
||||||
//
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'name' => 'required|alpha_num|min:1|max:124|exists:hashtags,name'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = Auth::user();
|
||||||
|
$profile = $user->profile;
|
||||||
|
$tag = $request->input('name');
|
||||||
|
|
||||||
|
$hashtag = Hashtag::whereName($tag)->firstOrFail();
|
||||||
|
|
||||||
|
$hashtagFollow = HashtagFollow::firstOrCreate([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'profile_id' => $user->profile_id ?? $user->profile->id,
|
||||||
|
'hashtag_id' => $hashtag->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($hashtagFollow->wasRecentlyCreated) {
|
||||||
|
$state = 'created';
|
||||||
|
// todo: send to HashtagFollowService
|
||||||
|
} else {
|
||||||
|
$state = 'deleted';
|
||||||
|
$hashtagFollow->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'state' => $state
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue