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;
7
8use App\Models\Beatmapset;
9use Auth;
10use Exception;
11
12class BeatmapsetWatchesController extends Controller
13{
14 public function __construct()
15 {
16 parent::__construct();
17
18 $this->middleware('auth');
19 }
20
21 public function update($beatmapsetId)
22 {
23 $beatmapset = Beatmapset::findOrFail($beatmapsetId);
24
25 try {
26 $beatmapset->watches()->create(['user_id' => Auth::user()->getKey()]);
27 } catch (Exception $e) {
28 if (!is_sql_unique_exception($e)) {
29 throw $e;
30 }
31 }
32
33 return response([], 204);
34 }
35
36 public function destroy($beatmapsetId)
37 {
38 $beatmapset = Beatmapset::findOrFail($beatmapsetId);
39
40 $beatmapset->watches()->where('user_id', '=', Auth::user()->getKey())->delete();
41
42 return response([], 204);
43 }
44}