Skip to content

Commit 9ee22ac

Browse files
authored
Merge pull request #11999 from notbakaneko/feature/beatmap-user-tags-path
Update setting beatmap tags to use path param
2 parents c3bbe71 + e8e498a commit 9ee22ac

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

Diff for: app/Http/Controllers/BeatmapTagsController.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public function __construct()
1919

2020
$this->middleware('auth', [
2121
'only' => [
22-
'store',
2322
'destroy',
23+
'update',
2424
],
2525
]);
2626
}
@@ -35,20 +35,18 @@ public function destroy($beatmapId, $tagId)
3535
return response()->noContent();
3636
}
3737

38-
public function store($beatmapId)
38+
public function update($beatmapId, $tagId)
3939
{
40-
$tagId = get_int(request('tag_id'));
41-
4240
$beatmap = Beatmap::findOrFail($beatmapId);
4341
priv_check('BeatmapTagStore', $beatmap)->ensureCan();
4442

4543
$tag = Tag::findOrFail($tagId);
4644

47-
$user = \Auth::user();
48-
4945
$tag
5046
->beatmapTags()
51-
->firstOrCreate(['beatmap_id' => $beatmapId, 'user_id' => $user->getKey()]);
47+
->firstOrCreate(['beatmap_id' => $beatmapId, 'user_id' => \Auth::user()->getKey()]);
48+
49+
$beatmap->expireTopTagIds();
5250

5351
return response()->noContent();
5452
}

Diff for: app/Models/Beatmap.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ public function canBeConvertedTo(int $rulesetId)
251251
return $this->playmode === static::MODES['osu'] || $this->playmode === $rulesetId;
252252
}
253253

254+
public function expireTopTagIds()
255+
{
256+
\Cache::delete("beatmap_top_tag_ids:{$this->getKey()}");
257+
}
258+
254259
public function getAttribute($key)
255260
{
256261
return match ($key) {
@@ -378,10 +383,9 @@ public function topTagIds()
378383
// TODO: Add option to multi query when beatmapset requests all tags for beatmaps?
379384
return $this->memoize(
380385
__FUNCTION__,
381-
fn () => cache_remember_mutexed(
386+
fn () => \Cache::remember(
382387
"beatmap_top_tag_ids:{$this->getKey()}",
383388
$GLOBALS['cfg']['osu']['tags']['beatmap_tags_cache_duration'],
384-
[],
385389
fn () => $this->beatmapTags()->topTagIds()->limit(50)->get()->toArray(),
386390
),
387391
);

Diff for: routes/web.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@
436436
});
437437
});
438438

439-
Route::apiResource('tags', 'BeatmapTagsController', ['only' => ['store', 'destroy']]);
439+
Route::apiResource('tags', 'BeatmapTagsController', ['only' => ['destroy', 'update']]);
440440
});
441441
});
442442

Diff for: tests/Controllers/BeatmapTagsControllerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testStore(): void
3030

3131
$this->actAsScopedUser($user);
3232
$this
33-
->post(route('api.beatmaps.tags.store', ['beatmap' => $this->beatmap->getKey()]), ['tag_id' => $this->tag->getKey()])
33+
->put(route('api.beatmaps.tags.update', ['beatmap' => $this->beatmap->getKey(), 'tag' => $this->tag->getKey()]))
3434
->assertSuccessful();
3535
}
3636

@@ -40,7 +40,7 @@ public function testStoreNoScore(): void
4040

4141
$this->actAsScopedUser(User::factory()->create());
4242
$this
43-
->post(route('api.beatmaps.tags.store', ['beatmap' => $this->beatmap->getKey()]), ['tag_id' => $this->tag->getKey()])
43+
->put(route('api.beatmaps.tags.update', ['beatmap' => $this->beatmap->getKey(), 'tag' => $this->tag->getKey()]))
4444
->assertForbidden();
4545
}
4646

Diff for: tests/api_routes.json

+20-19
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@
174174
"scopes": []
175175
},
176176
{
177-
"uri": "api/v2/beatmaps/{beatmap}/tags",
177+
"uri": "api/v2/beatmaps/{beatmap}/tags/{tag}",
178178
"methods": [
179-
"POST"
179+
"PATCH",
180+
"PUT"
180181
],
181-
"controller": "App\\Http\\Controllers\\BeatmapTagsController@store",
182+
"controller": "App\\Http\\Controllers\\BeatmapTagsController@update",
182183
"middlewares": [
183184
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
184185
"App\\Http\\Middleware\\RequireScopes",
@@ -719,6 +720,22 @@
719720
"forum.write"
720721
]
721722
},
723+
{
724+
"uri": "api/v2/forums/topics",
725+
"methods": [
726+
"GET",
727+
"HEAD"
728+
],
729+
"controller": "App\\Http\\Controllers\\Forum\\TopicsController@index",
730+
"middlewares": [
731+
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
732+
"App\\Http\\Middleware\\RequireScopes",
733+
"App\\Http\\Middleware\\RequireScopes:public"
734+
],
735+
"scopes": [
736+
"public"
737+
]
738+
},
722739
{
723740
"uri": "api/v2/forums/topics",
724741
"methods": [
@@ -735,22 +752,6 @@
735752
"forum.write"
736753
]
737754
},
738-
{
739-
"uri": "api/v2/forums/topics",
740-
"methods": [
741-
"GET",
742-
"HEAD"
743-
],
744-
"controller": "App\\Http\\Controllers\\Forum\\TopicsController@index",
745-
"middlewares": [
746-
"App\\Http\\Middleware\\ThrottleRequests:1200,1,api:",
747-
"App\\Http\\Middleware\\RequireScopes",
748-
"App\\Http\\Middleware\\RequireScopes:public"
749-
],
750-
"scopes": [
751-
"public"
752-
]
753-
},
754755
{
755756
"uri": "api/v2/forums/topics/{topic}",
756757
"methods": [

0 commit comments

Comments
 (0)