diff --git a/.github/workflows/dotnet-test.yml b/.github/workflows/dotnet-test.yml index 1080ebd..97c621c 100644 --- a/.github/workflows/dotnet-test.yml +++ b/.github/workflows/dotnet-test.yml @@ -15,7 +15,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v2 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - working-directory: ./Edge.MyMusic run: | dotnet test diff --git a/.gitignore b/.gitignore index 068c0e8..9fe7499 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ obj bin out +## wwwroot +Edge.MyMusic/src/Edge.MyMusic/wwwroot/* +!Edge.MyMusic/src/Edge.MyMusic/wwwroot/__blank__ + # Web.MyMusic diff --git a/.vscode/launch.json b/.vscode/launch.json index 8655f9e..a07cdce 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic/bin/Debug/net7.0/Edge.MyMusic.dll", + "program": "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic/bin/Debug/net8.0/Edge.MyMusic.dll", "args": [], "cwd": "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic", "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 17140cc..9da21fd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj", + "${workspaceFolder}/Edge.MyMusic/Edge.MyMusic.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], @@ -19,7 +19,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj", + "${workspaceFolder}/Edge.MyMusic/Edge.MyMusic.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], @@ -33,7 +33,7 @@ "watch", "run", "--project", - "${workspaceFolder}/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj" + "${workspaceFolder}/Edge.MyMusic/Edge.MyMusic.sln" ], "problemMatcher": "$msCompile" } diff --git a/Edge.MyMusic/README.md b/Edge.MyMusic/README.md index 55e10b4..0a3fed9 100644 --- a/Edge.MyMusic/README.md +++ b/Edge.MyMusic/README.md @@ -31,6 +31,12 @@ $ dotnet run -webapp $ dotnet run --audios=path/to/folder/or/file ``` +- `--base-url`: Specifies the base URL for the server. If not provided, the default is `http://localhost:5000`. + +```bash +$ dotnet run --base-url=https://www.mymusic.com +``` + ## How to Run Tests Execute the following command: diff --git a/Edge.MyMusic/src/Edge.MyMusic.Tests/Edge.MyMusic.Tests.csproj b/Edge.MyMusic/src/Edge.MyMusic.Tests/Edge.MyMusic.Tests.csproj index 07d6754..f67a58b 100644 --- a/Edge.MyMusic/src/Edge.MyMusic.Tests/Edge.MyMusic.Tests.csproj +++ b/Edge.MyMusic/src/Edge.MyMusic.Tests/Edge.MyMusic.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/Edge.MyMusic/src/Edge.MyMusic.Tests/MusicServiceTests.cs b/Edge.MyMusic/src/Edge.MyMusic.Tests/MusicServiceTests.cs index 78c2856..cde1deb 100644 --- a/Edge.MyMusic/src/Edge.MyMusic.Tests/MusicServiceTests.cs +++ b/Edge.MyMusic/src/Edge.MyMusic.Tests/MusicServiceTests.cs @@ -60,8 +60,11 @@ public async Task CanAddSongAsync() IsFavorite = false }; - AudioResponse expectedMetaData = new(title: request.Title, album: request.Album, artist: request.Artist) + AudioResponse expectedMetaData = new() { + Title = request.Title, + Album = request.Album, + Artist = request.Artist, Duration = 185 }; diff --git a/Edge.MyMusic/src/Edge.MyMusic/ApplicationBuilderExtension.cs b/Edge.MyMusic/src/Edge.MyMusic/ApplicationBuilderExtension.cs index 07e6ea8..a27ff7e 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/ApplicationBuilderExtension.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/ApplicationBuilderExtension.cs @@ -52,7 +52,7 @@ internal static IApplicationBuilder UseCustomPath(this IApplicationBuilder appli internal static IApplicationBuilder UseCors(this IApplicationBuilder application, ICORSPolicySetting cors) { - return application.UseCors(cors.PolicyName); + return application.UseCors(cors.PolicyName!); } internal static IApplicationBuilder UseServerHandler(this IApplicationBuilder application) diff --git a/Edge.MyMusic/src/Edge.MyMusic/ApplicationParser.cs b/Edge.MyMusic/src/Edge.MyMusic/ApplicationParser.cs index 964b83d..fa95ce0 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/ApplicationParser.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/ApplicationParser.cs @@ -9,15 +9,8 @@ public static ApplicationSetting Parse(string[] args, IConfiguration configurati ICORSPolicySetting? cors = configuration.GetSection("CORSPolicy").Get(); IMongoDBSetting? dbSetting = configuration.GetSection("MongoDBSetting").Get(); - static bool HasInMemoryFlag(string[] args) - { - return args.Any(arg => arg == "-inmemory"); - } - - static bool HasWebAppFlag(string[] args) - { - return args.Any(arg => arg == "-webapp"); - } + static bool HasInMemoryFlag(string[] args) => args.Any(arg => arg == "-inmemory"); + static bool HasWebAppFlag(string[] args) => args.Any(arg => arg == "-webapp"); static string? ExtractAudioFolderPath(string[] args) { @@ -28,6 +21,11 @@ static bool HasWebAppFlag(string[] args) : flag!.Split("=")[1]; } + static string ExtractBaseUrlPath(string[] args) + { + return args.FirstOrDefault(x => x.StartsWith("--base-url="))?.Split("=")[1] ?? "http://localhost:5000"; + } + return new ApplicationSetting { PolicyName = cors?.PolicyName, @@ -35,6 +33,7 @@ static bool HasWebAppFlag(string[] args) ConnectionString = dbSetting?.ConnectionString, DatabaseName = dbSetting?.DatabaseName, AudiosPath = ExtractAudioFolderPath(args), + BaseUrl = ExtractBaseUrlPath(args), UseInMemory = HasInMemoryFlag(args), UseWebApp = HasWebAppFlag(args) }; diff --git a/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPostRequest.cs b/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPostRequest.cs index 7399e38..7a55170 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPostRequest.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPostRequest.cs @@ -2,24 +2,16 @@ namespace Edge.MyMusic.Controllers.Models; -public sealed class SongPostRequest: IValidatableObject +public sealed class SongPostRequest( + string album, + string artist, + string path, + string title) : IValidatableObject { - public SongPostRequest( - string album, - string artist, - string path, - string title) - { - this.Album = album; - this.Artist = artist; - this.Path = path; - this.Title = title; - } - - public string Album { get; } - public string Artist { get; } - public string Path { get; } - public string Title { get; } + public string Album => album; + public string Artist => artist; + public string Path => path; + public string Title => title; public bool IsFavorite { get; init; } public IEnumerable Validate(ValidationContext validationContext) @@ -28,18 +20,22 @@ public IEnumerable Validate(ValidationContext validationContex { { nameof(this.Album), this.Album}, { nameof(this.Artist), this.Artist}, - { nameof(this.Path), this.Path}, { nameof(this.Title), this.Title}, }); } - internal IEnumerable Validate(IReadOnlyDictionary propertiesAndValues) + internal IEnumerable Validate(IReadOnlyDictionary properties) { - foreach(KeyValuePair kv in propertiesAndValues) + if (!Uri.IsWellFormedUriString(this.Path, UriKind.Absolute)) + { + yield return new ValidationResult("Invalid url", new[] { this.Path }); + } + + foreach(KeyValuePair property in properties) { - if (string.IsNullOrWhiteSpace(kv.Value)) + if (string.IsNullOrWhiteSpace(property.Value)) { - yield return new ValidationResult($"{kv.Key} cannot be empty", new[] { kv.Key}); + yield return new ValidationResult($"{property.Key} cannot be empty", new[] { property.Key}); } } } diff --git a/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPutRequest.cs b/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPutRequest.cs index a7b6c11..b23fb44 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPutRequest.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Controllers/Models/SongPutRequest.cs @@ -8,6 +8,8 @@ public sealed class SongPutRequest : IValidatableObject, IMusicUpdateQuery { public string? Album { get; init; } public string? Artist { get; init; } + + [Range(1, int.MaxValue)] public int? Length { get; init; } public string? Path { get; init; } public string? Title { get; init; } @@ -19,28 +21,23 @@ public IEnumerable Validate(ValidationContext validationContex { { nameof(this.Album), this.Album}, { nameof(this.Artist), this.Artist}, - { nameof(this.Path), this.Path}, { nameof(this.Title), this.Title}, }); } - internal IEnumerable Validate(IReadOnlyDictionary propertiesAndValues) + internal IEnumerable Validate(IReadOnlyDictionary properties) { - if (this.Length <= 0) + + if (!string.IsNullOrEmpty(this.Path) && !Uri.IsWellFormedUriString(this.Path, UriKind.Absolute)) { - yield return new ValidationResult($"{nameof(this.Length)} needs to be greater than 0", new[] { nameof(this.Length)}); + yield return new ValidationResult("Invalid url", new[] { this.Path }); } - foreach(KeyValuePair kv in propertiesAndValues) + foreach(KeyValuePair property in properties.Where(kv => kv.Value != null)) { - if (kv.Value == null) - { - continue; - } - - if (kv.Value.IsEmptyOrWhiteSpace()) + if (property.Value!.IsEmptyOrWhiteSpace()) { - yield return new ValidationResult($"{kv.Key} cannot be empty", new[] { kv.Key}); + yield return new ValidationResult($"{property.Key} cannot be empty", new[] { property.Key}); } } } diff --git a/Edge.MyMusic/src/Edge.MyMusic/Controllers/SongController.cs b/Edge.MyMusic/src/Edge.MyMusic/Controllers/SongController.cs index d321056..448302e 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Controllers/SongController.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Controllers/SongController.cs @@ -5,14 +5,9 @@ namespace Edge.MyMusic.Controllers; -public class SongController : BaseController +public class SongController(IMusicService musicService) : BaseController { - private readonly IMusicService _musicService; - - public SongController(IMusicService musicService) - { - _musicService = musicService; - } + private readonly IMusicService _musicService = musicService; [HttpGet] [ProducesResponseType(statusCode: StatusCodes.Status200OK, Type = typeof(CollectionModel))] diff --git a/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj b/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj index ea28e70..66e4f7a 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj +++ b/Edge.MyMusic/src/Edge.MyMusic/Edge.MyMusic.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/Edge.MyMusic/src/Edge.MyMusic/Processors/BaseProcessor.cs b/Edge.MyMusic/src/Edge.MyMusic/Processors/BaseProcessor.cs new file mode 100644 index 0000000..99588b8 --- /dev/null +++ b/Edge.MyMusic/src/Edge.MyMusic/Processors/BaseProcessor.cs @@ -0,0 +1,11 @@ +namespace Edge.MyMusic.Processors; + +internal abstract class BaseProcessor: IHostedLifecycleService +{ + public virtual Task StartingAsync(CancellationToken cancellationToken) => Task.CompletedTask; + public virtual Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; + public virtual Task StartedAsync(CancellationToken cancellationToken) => Task.CompletedTask; + public virtual Task StoppingAsync(CancellationToken cancellationToken) => Task.CompletedTask; + public virtual Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + public virtual Task StoppedAsync(CancellationToken cancellationToken) => Task.CompletedTask; +} \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Processors/MapperExtension.cs b/Edge.MyMusic/src/Edge.MyMusic/Processors/MapperExtension.cs deleted file mode 100644 index 717cf6c..0000000 --- a/Edge.MyMusic/src/Edge.MyMusic/Processors/MapperExtension.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Edge.MyMusic.Providers.Models; -using Edge.MyMusic.Repositories.Models.Documents; - -namespace Edge.MyMusic.Processors; - -internal static class MapperExtension -{ - internal static MusicDocument ToDocument(this AudioResponse from, string path) - { - return new MusicDocument - { - Album = from.Album, - Artist = from.Artist, - IsFavorite = false, - Length = from.Duration, - Path = path, - Title = from.Title - }; - } -} \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Processors/StartupProcessor.cs b/Edge.MyMusic/src/Edge.MyMusic/Processors/StartupProcessor.cs index 726b38e..8277cf0 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Processors/StartupProcessor.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Processors/StartupProcessor.cs @@ -1,51 +1,44 @@ using Edge.MyMusic.Providers; using Edge.MyMusic.Providers.Models; using Edge.MyMusic.Repositories; +using Edge.MyMusic.Repositories.Models.Documents; using Edge.MyMusic.Settings; namespace Edge.MyMusic.Processors; -internal class StartupProcessor : IHostedService +internal class StartupProcessor( + ILogger logger, + IMusicRepository musicRepository, + IAudioProvider audioProvider, + IArgsSetting argsSetting) : BaseProcessor { - private readonly IHostApplicationLifetime _applicationLifetime; - private readonly ILogger _logger; - private readonly IMusicRepository _musicRepository; - private readonly IAudioProvider _audioProvider; - private readonly IArgsSetting _argsSetting; + private readonly ILogger _logger = logger; + private readonly IMusicRepository _musicRepository = musicRepository; + private readonly IAudioProvider _audioProvider = audioProvider; + private readonly IArgsSetting _argsSetting = argsSetting; - private const string _baseUri = "http://localhost:5000"; + private const string _default = "Unknown"; - public StartupProcessor( - IHostApplicationLifetime applicationLifetime, - ILogger logger, - IMusicRepository musicRepository, - IAudioProvider audioProvider, - IArgsSetting argsSetting) + public override Task StartAsync(CancellationToken cancellationToken) { - _applicationLifetime = applicationLifetime; - _logger = logger; - _musicRepository = musicRepository; - _audioProvider = audioProvider; - _argsSetting = argsSetting; + _logger.LogInformation($"{nameof(StartupProcessor)} is starting..."); + return Task.CompletedTask; } - public Task StartAsync(CancellationToken cancellationToken) + public override Task StartedAsync(CancellationToken cancellationToken) { - _logger.LogInformation($"{nameof(StartupProcessor)} is starting..."); - if (string.IsNullOrEmpty(_argsSetting.AudiosPath)) { return Task.CompletedTask; } - // run only after the application host has fully started. - _applicationLifetime.ApplicationStarted.Register(async () => + return Task.Run(async() => { - IEnumerable files = Directory.GetFiles(_argsSetting.AudiosPath); + IEnumerable files = Directory.EnumerateFiles(_argsSetting.AudiosPath); foreach(string filePath in files) { - string path = $"{_baseUri}/audios/{Path.GetFileName(filePath)}"; + string path = $"{_argsSetting.BaseUrl}/audios/{Path.GetFileName(filePath)}"; AudioResponse? audio = await _audioProvider.GetMetadataAsync(path); if (audio == null) @@ -54,15 +47,20 @@ public Task StartAsync(CancellationToken cancellationToken) continue; } - await _musicRepository.AddMusicAsync(audio.ToDocument(path)); + await _musicRepository.AddMusicAsync(new MusicDocument + { + Album = audio.Album ?? _default, + Artist = audio.Artist ?? _default, + IsFavorite = false, + Length = audio.Duration, + Path = path, + Title = audio.Title ?? _default + }); }; }); - - return Task.CompletedTask; - } - public Task StopAsync(CancellationToken cancellationToken) + public override Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation($"{nameof(StartupProcessor)} is stopping..."); return Task.CompletedTask; diff --git a/Edge.MyMusic/src/Edge.MyMusic/Providers/AudioProvider.cs b/Edge.MyMusic/src/Edge.MyMusic/Providers/AudioProvider.cs index 6556b29..a874f17 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Providers/AudioProvider.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Providers/AudioProvider.cs @@ -2,14 +2,9 @@ namespace Edge.MyMusic.Providers; -internal class AudioProvider : BaseHttpProvider, IAudioProvider +internal class AudioProvider(ILogger logger, IHttpClientFactory factory) : BaseHttpProvider(factory), IAudioProvider { - private readonly ILogger _logger; - - public AudioProvider(ILogger logger, IHttpClientFactory factory) : base(factory) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public async Task GetMetadataAsync(string url) { @@ -23,10 +18,13 @@ public AudioProvider(ILogger logger, IHttpClientFactory factory) await File.WriteAllBytesAsync(tempFilePath, await response.Content.ReadAsByteArrayAsync()); } - TagLib.File metadata = TagLib.File.Create(tempFilePath); + using TagLib.File metadata = TagLib.File.Create(tempFilePath); - return new AudioResponse(title: metadata.Tag.Title, album: metadata.Tag.Album, artist: metadata.Tag.FirstPerformer) + return new AudioResponse { + Title = metadata.Tag.Title, + Album = metadata.Tag.Album, + Artist = metadata.Tag.FirstPerformer, Duration = (int) metadata.Properties.Duration.TotalSeconds }; } diff --git a/Edge.MyMusic/src/Edge.MyMusic/Providers/BaseHttpProvider.cs b/Edge.MyMusic/src/Edge.MyMusic/Providers/BaseHttpProvider.cs index d045794..1440deb 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Providers/BaseHttpProvider.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Providers/BaseHttpProvider.cs @@ -1,16 +1,11 @@ namespace Edge.MyMusic.Providers; -internal abstract class BaseHttpProvider +internal abstract class BaseHttpProvider(IHttpClientFactory factory) { - private readonly IHttpClientFactory _factory; - - protected BaseHttpProvider(IHttpClientFactory factory) - { - _factory = factory; - } + private readonly IHttpClientFactory _factory = factory; protected HttpClient GetClient() { - return _factory.CreateClient(nameof(TProvider)); + return _factory.CreateClient(typeof(TProvider).Name); } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Providers/Models/AudioResponse.cs b/Edge.MyMusic/src/Edge.MyMusic/Providers/Models/AudioResponse.cs index c563f11..1a5bf35 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Providers/Models/AudioResponse.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Providers/Models/AudioResponse.cs @@ -2,15 +2,8 @@ namespace Edge.MyMusic.Providers.Models; public sealed class AudioResponse { - public AudioResponse(string title, string album, string artist) - { - this.Title = !string.IsNullOrEmpty(title) ? title : "Unknown"; - this.Album = !string.IsNullOrEmpty(album) ? album : "Unknown"; - this.Artist = !string.IsNullOrEmpty(artist) ? artist : "Unknown"; - } - - public string Title { get; } - public string Album { get; } - public string Artist { get; } + public string? Title { get; init; } + public string? Album { get; init; } + public string? Artist { get; init; } public int Duration { get; init; } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicInMemoryRepository.cs b/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicInMemoryRepository.cs index cc9fa94..9ab97c9 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicInMemoryRepository.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicInMemoryRepository.cs @@ -107,29 +107,28 @@ public Task AddMusicAsync(MusicDocument doc) public Task UpdateMusicAsync(string id, IMusicUpdateQuery query) { - _datastore.TryGetValue(id, out MusicDocument? doc); - if (doc == null) + if (_datastore.TryGetValue(id, out MusicDocument? doc)) { - return Task.FromResult(null); + MusicDocument updatedDoc = new() + { + Id = id, + Artist = query.Artist ?? doc!.Artist, + Album = query.Album ?? doc!.Album, + IsFavorite = query.IsFavorite ?? doc!.IsFavorite, + Length = query.Length ?? doc!.Length, + Title = query.Title ?? doc!.Title, + Path = query.Path ?? doc!.Path, + CreateDate = doc!.CreateDate, + UpdateDate = DateTime.UtcNow + }; + + _datastore[id] = updatedDoc; + + return Task.FromResult(updatedDoc); } - MusicDocument updatedDoc = new() - { - Id = id, - Artist = query.Artist ?? doc!.Artist, - Album = query.Album ?? doc!.Album, - IsFavorite = query.IsFavorite ?? doc!.IsFavorite, - Length = query.Length ?? doc!.Length, - Title = query.Title ?? doc!.Title, - Path = query.Path ?? doc!.Path, - CreateDate = doc!.CreateDate, - UpdateDate = DateTime.UtcNow - }; - - _datastore[id] = updatedDoc; - - return Task.FromResult(updatedDoc); + return Task.FromResult(null); } public Task DeleteMusicAsync(string id) diff --git a/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicRepository.cs b/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicRepository.cs index 5a63761..8ddef3d 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicRepository.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Repositories/MusicRepository.cs @@ -6,14 +6,10 @@ namespace Edge.MyMusic.Repositories; -internal class MusicRepository : BaseMongoRepository, IMusicRepository +internal class MusicRepository(ILogger logger, IMongoDBSetting setting) : BaseMongoRepository(logger, setting), IMusicRepository { protected override string CollectionName => "music"; - public MusicRepository(ILogger logger, IMongoDBSetting setting) : base(logger, setting) - { - } - public async Task> SearchMusicAsync(IMusicSearchQuery query, IPaging pagingInfo) { FilterDefinition filter = query.ToFilterDefinition(); diff --git a/Edge.MyMusic/src/Edge.MyMusic/ServiceCollectionExtension.cs b/Edge.MyMusic/src/Edge.MyMusic/ServiceCollectionExtension.cs index 890ce39..5318092 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/ServiceCollectionExtension.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/ServiceCollectionExtension.cs @@ -78,10 +78,10 @@ internal static IServiceCollection AddCors(this IServiceCollection services, ICO { return services.AddCors(options => { - options.AddPolicy(name: cors.PolicyName, + options.AddPolicy(name: cors.PolicyName!, builder => { - builder.WithOrigins(cors.AllowedOrigins); + builder.WithOrigins(cors.AllowedOrigins!); // https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api // If you set headers to anything other than "*", // you should include at least "accept", "content-type", and "origin", diff --git a/Edge.MyMusic/src/Edge.MyMusic/Services/MusicService.cs b/Edge.MyMusic/src/Edge.MyMusic/Services/MusicService.cs index 074c989..0782244 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Services/MusicService.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Services/MusicService.cs @@ -5,16 +5,10 @@ namespace Edge.MyMusic.Services; -public class MusicService : IMusicService +public class MusicService(IAudioProvider audioProvider, IMusicRepository musicRepository) : IMusicService { - private readonly IAudioProvider _audioProvider; - private readonly IMusicRepository _musicRepository; - - public MusicService(IAudioProvider audioProvider, IMusicRepository musicRepository) - { - _audioProvider = audioProvider; - _musicRepository = musicRepository; - } + private readonly IAudioProvider _audioProvider = audioProvider; + private readonly IMusicRepository _musicRepository = musicRepository; public async Task> SearchSongsAsync(SongSearchRequest request) { diff --git a/Edge.MyMusic/src/Edge.MyMusic/Settings/ApplicationSetting.cs b/Edge.MyMusic/src/Edge.MyMusic/Settings/ApplicationSetting.cs index 40e2f3b..4e702cb 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Settings/ApplicationSetting.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Settings/ApplicationSetting.cs @@ -2,13 +2,12 @@ namespace Edge.MyMusic.Settings; internal class ApplicationSetting : ICORSPolicySetting, IArgsSetting, IMongoDBSetting { -#nullable disable - public string PolicyName { get; set; } - public string[] AllowedOrigins { get; set; } - public string ConnectionString { get; set; } - public string DatabaseName { get; set; } -#nullable enable - public string? AudiosPath { get; set; } - public bool UseInMemory { get; set; } - public bool UseWebApp { get; set; } + public string? PolicyName { get; init; } + public string[]? AllowedOrigins { get; init; } + public string? ConnectionString { get; init; } + public string? DatabaseName { get; init; } + public string? AudiosPath { get; init; } + public string? BaseUrl { get; init; } + public bool UseInMemory { get; init; } + public bool UseWebApp { get; init; } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Settings/IArgsSetting.cs b/Edge.MyMusic/src/Edge.MyMusic/Settings/IArgsSetting.cs index 94a40b7..b1e1266 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Settings/IArgsSetting.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Settings/IArgsSetting.cs @@ -2,7 +2,8 @@ namespace Edge.MyMusic.Settings; internal interface IArgsSetting { - string? AudiosPath { get; set; } - bool UseInMemory { get; set; } - bool UseWebApp { get; set; } + string? AudiosPath { get; init; } + string? BaseUrl { get; init; } + bool UseInMemory { get; init; } + bool UseWebApp { get; init; } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Settings/ICORSPolicySetting.cs b/Edge.MyMusic/src/Edge.MyMusic/Settings/ICORSPolicySetting.cs index 71358a2..b0869e2 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Settings/ICORSPolicySetting.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Settings/ICORSPolicySetting.cs @@ -2,6 +2,6 @@ namespace Edge.MyMusic.Settings; internal interface ICORSPolicySetting { - string PolicyName { get; set; } - string[] AllowedOrigins { get; set; } + string? PolicyName { get; init; } + string[]? AllowedOrigins { get; init; } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/Settings/IMongoDBSetting.cs b/Edge.MyMusic/src/Edge.MyMusic/Settings/IMongoDBSetting.cs index 1f81bc7..7412488 100644 --- a/Edge.MyMusic/src/Edge.MyMusic/Settings/IMongoDBSetting.cs +++ b/Edge.MyMusic/src/Edge.MyMusic/Settings/IMongoDBSetting.cs @@ -2,6 +2,6 @@ namespace Edge.MyMusic.Settings; internal interface IMongoDBSetting { - string ConnectionString { get; set; } - string DatabaseName { get; set; } + string? ConnectionString { get; init; } + string? DatabaseName { get; init; } } \ No newline at end of file diff --git a/Edge.MyMusic/src/Edge.MyMusic/wwwroot/_blank_ b/Edge.MyMusic/src/Edge.MyMusic/wwwroot/__blank__ similarity index 100% rename from Edge.MyMusic/src/Edge.MyMusic/wwwroot/_blank_ rename to Edge.MyMusic/src/Edge.MyMusic/wwwroot/__blank__ diff --git a/README.md b/README.md index d6f2f33..c735619 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Your go-to platform for playing and effortlessly managing all your favorite tune ## Prerequisites 1. [Node.js](https://nodejs.org/en/) (v18) -2. [.NET Core](https://dotnet.microsoft.com/en-us/download) (v7+) +2. [.NET Core](https://dotnet.microsoft.com/en-us/download) (v8) 3. [Make](https://www.gnu.org/software/make/) ## Usage