the browser-facing portion of osu!
at master 1.3 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers\Beatmapsets; 7 8use App\Exceptions\InvariantException; 9use App\Http\Controllers\Controller; 10use App\Models\Beatmapset; 11 12class FavouritesController extends Controller 13{ 14 public function __construct() 15 { 16 parent::__construct(); 17 18 $this->middleware('auth'); 19 } 20 21 public function store($beatmapsetId) 22 { 23 $beatmapset = Beatmapset::findOrFail($beatmapsetId); 24 $user = auth()->user(); 25 26 switch (request('action')) { 27 case 'favourite': 28 if ($user->favouriteBeatmapsets()->count() >= $user->beatmapsetFavouriteAllowance()) { 29 return error_popup(osu_trans('beatmapsets.show.favourites.limit_reached')); 30 } 31 $beatmapset->favourite($user); 32 break; 33 34 case 'unfavourite': 35 $beatmapset->unfavourite($user); 36 break; 37 38 default: 39 throw new InvariantException('Invalid action'); 40 } 41 42 return [ 43 'favourite_count' => $beatmapset->fresh()->favourite_count, 44 ]; 45 } 46}