-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
379 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,4 +434,5 @@ $RECYCLE.BIN/ | |
|
||
*.litedb | ||
|
||
.vscode/ | ||
.vscode/ | ||
music/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,101 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Pcm.Entities; | ||
using Pcm.Proto; | ||
using Pcm.Proxy; | ||
using Pcm.Services; | ||
using Pcm.Utils; | ||
using System; | ||
|
||
namespace Pcm.Handlers | ||
{ | ||
public class CategoryHandler | ||
{ | ||
public async Task<StatusCode> Get(Context ctx, Request req, Response resp) | ||
{ | ||
return await Task.FromResult(StatusCode.Ok); | ||
} | ||
|
||
public async Task<StatusCode> List(Context ctx, Request req, Response resp) | ||
public async Task<StatusCode> ListByAlbum(Context ctx, Request req, Response resp) | ||
{ | ||
var musics = MusicService.Instance.Collection.FindAll() | ||
.Select(t => t.ToResp()) | ||
.GroupBy(m => m.Album) | ||
.ToDictionary(m => m.Key, m => new ListMusicResponseBody() { Musics = { m.ToList() }}); | ||
|
||
resp.Body.ListByAlbum = new ListByAlbumResponseBody() | ||
resp.Body.ListByAlbumBody = new ListByAlbumResponseBody() | ||
{ | ||
Albums = { musics } | ||
}; | ||
return await Task.FromResult(StatusCode.Ok); | ||
} | ||
|
||
|
||
public async Task<StatusCode> ListByPerformer(Context ctx, Request req, Response resp) | ||
{ | ||
var musics = MusicService.Instance.Collection.FindAll() | ||
// extend to musics with single performer | ||
.SelectMany(m => m.Performers.Select(performer => new Music() | ||
{ | ||
MusicId = m.MusicId, | ||
Title = m.Title, | ||
Album = m.Album, | ||
Genres = m.Genres, | ||
Performers = new[] {performer}, | ||
Track = m.Track, | ||
TrackCount = m.TrackCount, | ||
PictureCount = m.PictureCount, | ||
FilePath = m.FilePath, | ||
PlayCount = m.PlayCount, | ||
Length = m.Length, | ||
MimeType = m.MimeType | ||
})) | ||
.GroupBy(t => t.Performers[0]) | ||
.ToDictionary(t => t.Key, t => new List<GetMusicResponseBody>(t.Select(m => m.MusicId) | ||
.Distinct() | ||
.Select(m => MusicService.Instance.Get(m.ToString())) | ||
.Select(m => m.ToResp()))) | ||
.ToDictionary(t => t.Key, t => new ListMusicResponseBody() { Musics = { t.Value }}); | ||
|
||
resp.Body.ListByPerformerBody = new ListByPerformerResponseBody() | ||
{ | ||
Performers = { musics } | ||
}; | ||
return await Task.FromResult(StatusCode.Ok); | ||
} | ||
|
||
public async Task<StatusCode> Search(Context ctx, Request req, Response resp) | ||
{ | ||
var keywords = req.Body.ListSearchBody.Keyword.ToLower().RemoveSpecialCharacters().Split(" "); | ||
var searchThreshold = ConfigManager.GetInt("searchThreshold", 2); | ||
|
||
var musics = MusicService.Instance.Collection.FindAll() | ||
// extend to musics with single performer | ||
.SelectMany(m => m.Performers.Select(performer => new Music() | ||
{ | ||
MusicId = m.MusicId, | ||
Title = m.Title, | ||
Album = m.Album ?? string.Empty, | ||
Genres = m.Genres, | ||
Performers = new[] {performer}, | ||
Track = m.Track, | ||
TrackCount = m.TrackCount, | ||
PictureCount = m.PictureCount, | ||
FilePath = m.FilePath, | ||
PlayCount = m.PlayCount, | ||
Length = m.Length, | ||
MimeType = m.MimeType | ||
})) | ||
.Where(t => t.Album.ToLower().Distance(keywords) <= searchThreshold || | ||
t.Title.ToLower().Distance(keywords) <= searchThreshold || | ||
t.Performers[0].ToLower().Distance(keywords) <= searchThreshold || | ||
t.FileName.ToLower().Distance(keywords) <= searchThreshold) | ||
.Select(t => t.MusicId) | ||
.Distinct() | ||
.Select(t => MusicService.Instance.Get(t.ToString())) | ||
.Select(t => t.ToResp()); | ||
|
||
resp.Body.ListSearchBody = new ListSearchResponseBody() | ||
{ | ||
Musics = { musics } | ||
}; | ||
return await Task.FromResult(StatusCode.Ok); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.