mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-14 22:02:26 +00:00
Changes from self review
This commit is contained in:
parent
fbe203d84a
commit
af0e5bd424
2 changed files with 25 additions and 30 deletions
|
@ -207,10 +207,10 @@ public class ListController : ControllerBase
|
|||
|
||||
if (pageSize <= 0) return this.BadRequest();
|
||||
|
||||
User? targetUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||
if (targetUser == null) return this.StatusCode(403, "");
|
||||
int targetUserId = await this.database.Users.Where(u => u.Username == username).Select(u => u.UserId).FirstOrDefaultAsync();
|
||||
if (targetUserId == 0) return this.StatusCode(403, "");
|
||||
|
||||
IEnumerable<Playlist> heartedPlaylists = this.database.Playlists.Where(p => p.CreatorId == targetUser.UserId)
|
||||
IEnumerable<Playlist> heartedPlaylists = this.database.Playlists.Where(p => p.CreatorId == targetUserId)
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 30))
|
||||
.AsEnumerable();
|
||||
|
@ -221,7 +221,7 @@ public class ListController : ControllerBase
|
|||
(
|
||||
LbpSerializer.TaggedStringElement("favouritePlaylists", response, new Dictionary<string, object>
|
||||
{
|
||||
{ "total", this.database.HeartedPlaylists.Count(p => p.UserId == targetUser.UserId) },
|
||||
{ "total", this.database.HeartedPlaylists.Count(p => p.UserId == targetUserId) },
|
||||
{ "hint_start", pageStart + Math.Min(pageSize, 30) },
|
||||
})
|
||||
);
|
||||
|
@ -233,15 +233,14 @@ public class ListController : ControllerBase
|
|||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
||||
if (user == null) return this.BadRequest();
|
||||
string username = await this.database.UsernameFromGameToken(token);
|
||||
|
||||
Playlist? playlist = await this.database.Playlists.FirstOrDefaultAsync(s => s.PlaylistId == playlistId);
|
||||
if (playlist == null) return this.NotFound();
|
||||
|
||||
await this.database.HeartPlaylist(token.UserId, playlist);
|
||||
|
||||
return await this.GetFavouritePlaylists(user.Username, 1, 30);
|
||||
return await this.GetFavouritePlaylists(username, 1, 30);
|
||||
}
|
||||
|
||||
[HttpPost("unfavourite/slot/{playlistId:int}")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue