From d982e445765fef0dd4514e562bbeea0ff7af2ae1 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 16 Jun 2024 19:45:33 -0400 Subject: [PATCH 1/5] #74: Add UserID to the Song model --- Models/Song.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Models/Song.cs b/Models/Song.cs index b295983..ed6b4dc 100644 --- a/Models/Song.cs +++ b/Models/Song.cs @@ -46,6 +46,8 @@ public class Song public int? CoverArtID { get; set; } [JsonProperty("date_created")] public DateTime DateCreated { get; set; } + [JsonProperty("user_id")] + public int UserID { get; set; } #endregion -- 2.47.3 From 3b4799546d7c1f86ed15473349344a57e9f9f9a7 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 17 Jun 2024 20:26:55 -0400 Subject: [PATCH 2/5] #74: Added functionality to retrieve user id from the token --- Controllers/Managers/TokenManager.cs | 56 +++++++++++++++++++--------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/Controllers/Managers/TokenManager.cs b/Controllers/Managers/TokenManager.cs index de2a185..500545b 100644 --- a/Controllers/Managers/TokenManager.cs +++ b/Controllers/Managers/TokenManager.cs @@ -77,11 +77,13 @@ public class TokenManager : BaseManager public LoginResult LoginSymmetric(User user) { - var tokenResult = new TokenTierOne(); - tokenResult.TokenType = "Jwt"; + var tokenResult = new TokenTierOne + { + TokenType = "JWT" + }; var payload = Payload(); - payload.Add(new System.Security.Claims.Claim("user_id", user.UserID.ToString(), ClaimValueTypes.Integer)); + payload.Add(new Claim("user_id", user.UserID.ToString(), ClaimValueTypes.Integer)); var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_config["JWT:Secret"]); @@ -98,10 +100,8 @@ public class TokenManager : BaseManager Audience = _config["Jwt:Audience"] }; - var token = tokenHandler.CreateToken(tokenDescriptor); - - - tokenResult.AccessToken = tokenHandler.WriteToken(token); + // var token = + tokenResult.AccessToken = tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor)); var expClaim = payload.FirstOrDefault(cl => { @@ -112,6 +112,8 @@ public class TokenManager : BaseManager var exp = Math.Floor((expiredDate - DateTime.UnixEpoch).TotalSeconds); tokenResult.Expiration = Convert.ToInt32(exp); + var userId = this.RetrieveUserIdFromToken(tokenResult.AccessToken); + return new LoginResult { UserID = user.UserID, Username = user.Username, Token = tokenResult.AccessToken, @@ -120,6 +122,23 @@ public class TokenManager : BaseManager }; } + public int RetrieveUserIdFromToken(string token) + { + var tokenHandler = new JwtSecurityTokenHandler(); + var readTok = tokenHandler.ReadJwtToken(token); + var userId = -1; + + foreach (var item in readTok.Payload) + { + if (item.Key == "user_id") + { + userId = Convert.ToInt32(item.Value); + } + } + + return userId; + } + private string AllScopes() { @@ -157,30 +176,30 @@ public class TokenManager : BaseManager private List Payload() { + // TODO: Remove this hard coding var expLimit = 30; var currentDate = DateTime.Now; var expiredDate = currentDate.AddMinutes(expLimit); - var issued = Math.Floor((currentDate - DateTime.UnixEpoch).TotalSeconds); - var expires = Math.Floor((expiredDate - DateTime.UnixEpoch).TotalSeconds); - var issuer = "https://soaricarus.auth0.com"; - issuer = "http://localhost:5002"; - var audience = "https://icarus/api"; - audience = "http://localhost:5002"; + // var issuer = "https://soaricarus.auth0.com"; + var issuer = "http://localhost:5002"; + // var audience = "https://icarus/api"; + var audience = "http://localhost:5002"; var subject = _config["JWT:Subject"]; var claim = new List() { - new System.Security.Claims.Claim("scope", AllScopes(), "string"), - new System.Security.Claims.Claim(JwtRegisteredClaimNames.Exp, expiredDate.ToString()), - new System.Security.Claims.Claim(JwtRegisteredClaimNames.Aud, audience), - new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iss, issuer), + new Claim("scope", AllScopes(), "string"), + new Claim(JwtRegisteredClaimNames.Exp, expiredDate.ToString()), + new Claim(JwtRegisteredClaimNames.Aud, audience), + new Claim(JwtRegisteredClaimNames.Iss, issuer), new Claim(JwtRegisteredClaimNames.Sub, subject), - new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iat, currentDate.ToString()) + new Claim(JwtRegisteredClaimNames.Iat, currentDate.ToString()) }; return claim; } + [Obsolete("Deprecated function")] private async Task ReadKeyContent(string filepath) { return await System.IO.File.ReadAllTextAsync(filepath); @@ -234,6 +253,7 @@ public class TokenManager : BaseManager [JsonProperty("grant_type")] public string GrantType { get; set; } } + private class TokenTierOne { [JsonProperty("access_token")] -- 2.47.3 From cd5ee7d0933a26800f81925256024f9e4c40f4a6 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 18 Jun 2024 13:00:50 -0400 Subject: [PATCH 3/5] #74: Songs will now contain the User Id when uploading --- Controllers/Managers/TokenManager.cs | 28 +++++++++++++++++++++------- Controllers/v1/SongDataController.cs | 9 +++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Controllers/Managers/TokenManager.cs b/Controllers/Managers/TokenManager.cs index 500545b..9d7e785 100644 --- a/Controllers/Managers/TokenManager.cs +++ b/Controllers/Managers/TokenManager.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using RestSharp; using Icarus.Models; +using Microsoft.VisualBasic; namespace Icarus.Controllers.Managers; @@ -77,10 +78,7 @@ public class TokenManager : BaseManager public LoginResult LoginSymmetric(User user) { - var tokenResult = new TokenTierOne - { - TokenType = "JWT" - }; + var tokenResult = new TokenTierOne{ TokenType = "JWT" }; var payload = Payload(); payload.Add(new Claim("user_id", user.UserID.ToString(), ClaimValueTypes.Integer)); @@ -100,7 +98,6 @@ public class TokenManager : BaseManager Audience = _config["Jwt:Audience"] }; - // var token = tokenResult.AccessToken = tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor)); var expClaim = payload.FirstOrDefault(cl => @@ -112,8 +109,6 @@ public class TokenManager : BaseManager var exp = Math.Floor((expiredDate - DateTime.UnixEpoch).TotalSeconds); tokenResult.Expiration = Convert.ToInt32(exp); - var userId = this.RetrieveUserIdFromToken(tokenResult.AccessToken); - return new LoginResult { UserID = user.UserID, Username = user.Username, Token = tokenResult.AccessToken, @@ -124,6 +119,11 @@ public class TokenManager : BaseManager public int RetrieveUserIdFromToken(string token) { + if (this.ContainsBearer(token)) + { + token = this.StripBearer(token); + } + var tokenHandler = new JwtSecurityTokenHandler(); var readTok = tokenHandler.ReadJwtToken(token); var userId = -1; @@ -133,12 +133,26 @@ public class TokenManager : BaseManager if (item.Key == "user_id") { userId = Convert.ToInt32(item.Value); + break; } } return userId; } + private string StripBearer(string token) + { + var start = 6; + var strippedToken = token.Substring(start); + + return Strings.Trim(strippedToken); + } + + private bool ContainsBearer(string token) + { + return token.Contains("Bearer"); + } + private string AllScopes() { diff --git a/Controllers/v1/SongDataController.cs b/Controllers/v1/SongDataController.cs index c76d5fb..cd68b35 100644 --- a/Controllers/v1/SongDataController.cs +++ b/Controllers/v1/SongDataController.cs @@ -104,6 +104,15 @@ public class SongDataController : BaseController if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile)) { var song = Newtonsoft.Json.JsonConvert.DeserializeObject(up.SongFile); + var tokMgr = new TokenManager(this._config); + var accessToken = Request.Headers["Authorization"]; + var userId = tokMgr.RetrieveUserIdFromToken(accessToken); + + if (userId != -1) + { + song.UserID = userId; + } + _logger.LogInformation($"Song title: {song.Title}"); _songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song); -- 2.47.3 From c6257da717fcea487550a7d62b7c45db3f0aa976 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 18 Jun 2024 13:14:57 -0400 Subject: [PATCH 4/5] Updated Readme and script to add migrations --- README.md | 9 ++++++--- Scripts/Migrations/Linux/AddUpdate.sh | 27 ++++++++++++++------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5e5362c..26fac34 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ Prior to starting the API, the Migrations must be applied. There are 6 tables wi * Song * Album * Artist -* Year +* CoverArt * Genre There is a script for Linux systems to apply these migrations, it can be found in the [Scripts/Migrations/Linux](https://github.com/kdeng00/Icarus/blob/master/Scripts/Migrations/Linux/AddUpdate.sh) directory. Just merely execute: @@ -126,12 +126,15 @@ scripts/Migrations/Linux/AddUpdate.sh ``` Or you can manually add the migrations like so for each migration: ```shell -dotnet ef migrations Add [Migration] --context [Migration]Context +dotnet-ef migrations Add InitialCreate --context UserContext ``` Then update the migrations to the database like so*: ```shell -dotnet ef database update --context [Migration]Context +dotnet-ef database update --context UserContext ``` + +All of the contexts can be found in Database/Contexts folder. + From this point the database has been successfully configured. Metadata and song filesystem locations can be saved. * Will only need to execute this for UserContext and SongContext because the Song table has relational constraints with Album, Artist, Year, and Genre. diff --git a/Scripts/Migrations/Linux/AddUpdate.sh b/Scripts/Migrations/Linux/AddUpdate.sh index 04e72bd..6a1759c 100644 --- a/Scripts/Migrations/Linux/AddUpdate.sh +++ b/Scripts/Migrations/Linux/AddUpdate.sh @@ -1,26 +1,27 @@ echo "Adding migrations..." echo "Adding User migration" -dotnet ef migrations add User --context UserContext -echo "Adding Song migration" -dotnet ef migrations add Song --context SongContext +dotnet-ef migrations add User --context UserContext echo "Adding Album migration" -dotnet ef migrations add Album --context AlbumContext +dotnet-ef migrations add Album --context AlbumContext echo "Adding Artist migration" -dotnet ef migrations add Artist --context ArtistContext +dotnet-ef migrations add Artist --context ArtistContext echo "Adding Genre migration" -dotnet ef migrations add Genre --context GenreContext -echo "Adding Year migration" -dotnet ef migrations add Year --context YearContext +dotnet-ef migrations add Genre --context GenreContext echo "Adding Cover art migration" -dotnet ef migrations add CoverArt --context CoverArtContext +dotnet-ef migrations add CoverArt --context CoverArtContext +echo "Adding Song migration" +dotnet-ef migrations add Song --context SongContext echo "Updating migrations.." echo "Updating User migration" -dotnet ef database update --context UserContext -echo "Updating Song migration" +dotnet-ef database update --context UserContext echo "Updating Album migration" +dotnet-ef database update --context AlbumContext echo "Updating Artist migration" +dotnet-ef database update --context ArtistContext echo "Updating Genre migration" -echo "Updating Year migration" +dotnet-ef database update --context GenreContext echo "Updating Cover art migration" -dotnet ef database update --context SongContext +dotnet-ef database update --context CoverArtContext +echo "Updating Song migration" +dotnet-ef database update --context SongContext -- 2.47.3 From ef96003f467ced014cd586e0a003ea4bdc70151a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 19 Jun 2024 15:38:32 -0400 Subject: [PATCH 5/5] #74: Some cleanup --- Constants/DirectoryPaths.cs | 2 -- Controllers/Managers/ArtistManager.cs | 12 ++++----- Controllers/Managers/CoverArtManager.cs | 2 +- Controllers/Managers/SongManager.cs | 2 +- Controllers/Managers/TokenManager.cs | 2 -- Controllers/Utilities/SongCompression.cs | 5 ---- Controllers/v1/AlbumController.cs | 15 ++--------- Controllers/v1/ArtistController.cs | 7 ++--- Controllers/v1/BaseController.cs | 4 --- Controllers/v1/GenreController.cs | 21 ++++++--------- Controllers/v1/LogoutController.cs | 0 Controllers/v1/RegisterController.cs | 10 ------- .../v1/SongCompressedDataControllers.cs | 1 - Controllers/v1/SongController.cs | 27 ++++++------------- Controllers/v1/SongStreamController.cs | 21 ++------------- Database/Contexts/AlbumContext.cs | 4 --- Database/Contexts/ArtistContext.cs | 4 --- Database/Contexts/CoverArtContext.cs | 4 --- Database/Contexts/GenreContext.cs | 4 --- Database/Contexts/SongContext.cs | 16 +++++------ Database/Contexts/UserContext.cs | 5 ---- 21 files changed, 36 insertions(+), 132 deletions(-) delete mode 100644 Controllers/v1/LogoutController.cs diff --git a/Constants/DirectoryPaths.cs b/Constants/DirectoryPaths.cs index 8aab732..016cd53 100644 --- a/Constants/DirectoryPaths.cs +++ b/Constants/DirectoryPaths.cs @@ -1,5 +1,3 @@ -using System.IO; - namespace Icarus.Constants; public class DirectoryPaths diff --git a/Controllers/Managers/ArtistManager.cs b/Controllers/Managers/ArtistManager.cs index 31b4f83..3fb7ac3 100644 --- a/Controllers/Managers/ArtistManager.cs +++ b/Controllers/Managers/ArtistManager.cs @@ -29,13 +29,13 @@ public class ArtistManager : BaseManager { _logger.Info("Starting process to save the artist record of the song to the database"); - var artist = new Artist(); + var artist = new Artist + { + Name = song.Artist, + SongCount = 1 + }; - artist.Name = song.Artist; - artist.SongCount = 1; - var artistTitle = artist.Name; - - var artistRetrieved = _artistContext.Artists.FirstOrDefault(art => art.Name.Equals(artistTitle)); + var artistRetrieved = _artistContext.Artists.FirstOrDefault(art => art.Name.Equals(artist.Name)); if (artistRetrieved == null) { diff --git a/Controllers/Managers/CoverArtManager.cs b/Controllers/Managers/CoverArtManager.cs index 4026d21..8988305 100644 --- a/Controllers/Managers/CoverArtManager.cs +++ b/Controllers/Managers/CoverArtManager.cs @@ -97,7 +97,7 @@ public class CoverArtManager : BaseManager else { _logger.Info("Song has no cover art, applying stock cover art"); - // coverArt.ImagePath = _rootCoverArtPath + $"{segment}{defaultExtension}"; + var coverArtFilePath = _rootCoverArtPath + $"{segment}{defaultExtension}"; coverArt.ImagePath = DirectoryPaths.CoverArtPath; metaData.UpdateCoverArt(song, coverArt); diff --git a/Controllers/Managers/SongManager.cs b/Controllers/Managers/SongManager.cs index 7e4a93c..8234e06 100644 --- a/Controllers/Managers/SongManager.cs +++ b/Controllers/Managers/SongManager.cs @@ -107,7 +107,7 @@ public class SongManager : BaseManager try { var songPath = songMetaData.SongPath(); - System.IO.File.Delete(songPath); + File.Delete(songPath); successful = true; DirectoryManager dirMgr = new DirectoryManager(_config, songMetaData); dirMgr.DeleteEmptyDirectories(); diff --git a/Controllers/Managers/TokenManager.cs b/Controllers/Managers/TokenManager.cs index 9d7e785..2c2e03e 100644 --- a/Controllers/Managers/TokenManager.cs +++ b/Controllers/Managers/TokenManager.cs @@ -194,9 +194,7 @@ public class TokenManager : BaseManager var expLimit = 30; var currentDate = DateTime.Now; var expiredDate = currentDate.AddMinutes(expLimit); - // var issuer = "https://soaricarus.auth0.com"; var issuer = "http://localhost:5002"; - // var audience = "https://icarus/api"; var audience = "http://localhost:5002"; var subject = _config["JWT:Subject"]; diff --git a/Controllers/Utilities/SongCompression.cs b/Controllers/Utilities/SongCompression.cs index 4c6d4aa..ef7035a 100644 --- a/Controllers/Utilities/SongCompression.cs +++ b/Controllers/Utilities/SongCompression.cs @@ -1,9 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; - using Ionic.Zip; -using Microsoft.AspNetCore.Http; using Icarus.Models; diff --git a/Controllers/v1/AlbumController.cs b/Controllers/v1/AlbumController.cs index d333872..85bbea2 100644 --- a/Controllers/v1/AlbumController.cs +++ b/Controllers/v1/AlbumController.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Icarus.Models; using Icarus.Database.Contexts; @@ -41,11 +35,9 @@ public class AlbumController : BaseController [HttpGet] public IActionResult GetAlbums() { - List albums = new List(); - var albumContext = new AlbumContext(_connectionString); - albums = albumContext.Albums.ToList(); + var albums = albumContext.Albums.ToList(); if (albums.Count > 0) return Ok(albums); @@ -56,10 +48,7 @@ public class AlbumController : BaseController [HttpGet("{id}")] public IActionResult GetAlbum(int id) { - Album album = new Album - { - AlbumID = id - }; + Album album = new Album{ AlbumID = id }; var albumContext = new AlbumContext(_connectionString); diff --git a/Controllers/v1/ArtistController.cs b/Controllers/v1/ArtistController.cs index 3281774..e6d021d 100644 --- a/Controllers/v1/ArtistController.cs +++ b/Controllers/v1/ArtistController.cs @@ -1,10 +1,5 @@ -using System; -using System.Linq; - using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Icarus.Models; using Icarus.Database.Contexts; @@ -67,7 +62,9 @@ public class ArtistController : BaseController return Ok(artist); } else + { return NotFound(); + } } #endregion } diff --git a/Controllers/v1/BaseController.cs b/Controllers/v1/BaseController.cs index 093b470..e04b9aa 100644 --- a/Controllers/v1/BaseController.cs +++ b/Controllers/v1/BaseController.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; - using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; namespace Icarus.Controllers.V1; diff --git a/Controllers/v1/GenreController.cs b/Controllers/v1/GenreController.cs index 6dd4590..3e8a387 100644 --- a/Controllers/v1/GenreController.cs +++ b/Controllers/v1/GenreController.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Icarus.Models; using Icarus.Database.Contexts; @@ -41,25 +35,24 @@ public class GenreController : BaseController [HttpGet] public IActionResult GetGenres() { - var genres = new List(); - var genreStore = new GenreContext(_connectionString); - genres = genreStore.Genres.ToList(); + var genres = genreStore.Genres.ToList(); if (genres.Count > 0) + { return Ok(genres); + } else + { return NotFound(new List()); + } } [HttpGet("{id}")] public IActionResult GetGenre(int id) { - var genre = new Genre - { - GenreID = id - }; + var genre = new Genre{ GenreID = id }; var genreStore = new GenreContext(_connectionString); @@ -70,7 +63,9 @@ public class GenreController : BaseController return Ok(genre); } else + { return NotFound(new Genre()); + } } #endregion } diff --git a/Controllers/v1/LogoutController.cs b/Controllers/v1/LogoutController.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Controllers/v1/RegisterController.cs b/Controllers/v1/RegisterController.cs index 9493f85..2bad355 100644 --- a/Controllers/v1/RegisterController.cs +++ b/Controllers/v1/RegisterController.cs @@ -1,13 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Threading.Tasks; - using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Icarus.Controllers.Managers; using Icarus.Controllers.Utilities; using Icarus.Models; using Icarus.Database.Contexts; @@ -19,7 +11,6 @@ namespace Icarus.Controllers.V1; public class RegisterController : ControllerBase { #region Fields - private string _connectionString; private IConfiguration _config; #endregion @@ -32,7 +23,6 @@ public class RegisterController : ControllerBase public RegisterController(IConfiguration config) { _config = config; - _connectionString = _config.GetConnectionString("DefaultConnection"); } #endregion diff --git a/Controllers/v1/SongCompressedDataControllers.cs b/Controllers/v1/SongCompressedDataControllers.cs index 2668aa8..7d094cf 100644 --- a/Controllers/v1/SongCompressedDataControllers.cs +++ b/Controllers/v1/SongCompressedDataControllers.cs @@ -42,7 +42,6 @@ public class SongCompressedDataController : BaseController var context = new SongContext(_connectionString); SongCompression cmp = new SongCompression(_archiveDir); - Console.WriteLine($"Archive directory root: {_archiveDir}"); diff --git a/Controllers/v1/SongController.cs b/Controllers/v1/SongController.cs index eed435e..0def6aa 100644 --- a/Controllers/v1/SongController.cs +++ b/Controllers/v1/SongController.cs @@ -1,16 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Threading.Tasks; - -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using Icarus.Controllers.Managers; -using Icarus.Controllers.Utilities; using Icarus.Models; using Icarus.Database.Contexts; @@ -36,8 +27,8 @@ public class SongController : BaseController public SongController(IConfiguration config, ILogger logger) { _config = config; - _connectionString = _config.GetConnectionString("DefaultConnection"); _logger = logger; + _connectionString = _config.GetConnectionString("DefaultConnection"); _songMgr = new SongManager(config); } #endregion @@ -45,23 +36,24 @@ public class SongController : BaseController #region Methods #region HTTP Endpoints - - [HttpGet] public IActionResult GetSongs() { - List songs = new List(); Console.WriteLine("Attemtping to retrieve songs"); _logger.LogInformation("Attempting to retrieve songs"); var context = new SongContext(_connectionString); - songs = context.Songs.ToList(); + var songs = context.Songs.ToList(); if (songs.Count > 0) + { return Ok(songs); + } else + { return NotFound(); + } } [HttpGet("{id}")] @@ -69,8 +61,7 @@ public class SongController : BaseController { var context = new SongContext(_connectionString); - Song song = new Song { SongID = id }; - song = context.RetrieveRecord(song); + var song = context.RetrieveRecord(new Song{ SongID = id }); Console.WriteLine("Here"); @@ -83,8 +74,6 @@ public class SongController : BaseController [HttpPut("{id}")] public IActionResult UpdateSong(int id, [FromBody] Song song) { - var context = new SongContext(_connectionString); - song.SongID = id; Console.WriteLine("Retrieving filepath of song"); _logger.LogInformation("Retrieving filepath of song"); diff --git a/Controllers/v1/SongStreamController.cs b/Controllers/v1/SongStreamController.cs index 7e5aa07..f65937c 100644 --- a/Controllers/v1/SongStreamController.cs +++ b/Controllers/v1/SongStreamController.cs @@ -1,19 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http.Headers; -using System.Web; -using System.Threading.Tasks; - -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Icarus.Models; -using Icarus.Controllers.Managers; using Icarus.Database.Contexts; namespace Icarus.Controllers.V1; @@ -25,7 +12,6 @@ public class SongStreamController : BaseController { #region Fields private ILogger _logger; - private string _connectionString; #endregion @@ -38,7 +24,6 @@ public class SongStreamController : BaseController { _logger = logger; _config = config; - _connectionString = _config.GetConnectionString("DefaultConnection"); } #endregion @@ -63,11 +48,9 @@ public class SongStreamController : BaseController _logger.LogInformation("Starting to stream song...>"); Console.WriteLine("Starting to streamsong..."); - var file = await Task.Run(() => { + return await Task.Run(() => { return File(stream, "application/octet-stream", filename); }); - - return file; } #endregion } diff --git a/Database/Contexts/AlbumContext.cs b/Database/Contexts/AlbumContext.cs index 107c5c5..9d5dc55 100644 --- a/Database/Contexts/AlbumContext.cs +++ b/Database/Contexts/AlbumContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; using Icarus.Models; diff --git a/Database/Contexts/ArtistContext.cs b/Database/Contexts/ArtistContext.cs index b77fe6e..b2007f1 100644 --- a/Database/Contexts/ArtistContext.cs +++ b/Database/Contexts/ArtistContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; using Icarus.Models; diff --git a/Database/Contexts/CoverArtContext.cs b/Database/Contexts/CoverArtContext.cs index f1b285e..f6cd149 100644 --- a/Database/Contexts/CoverArtContext.cs +++ b/Database/Contexts/CoverArtContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; using Icarus.Models; diff --git a/Database/Contexts/GenreContext.cs b/Database/Contexts/GenreContext.cs index 0b09c93..5dacdf3 100644 --- a/Database/Contexts/GenreContext.cs +++ b/Database/Contexts/GenreContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; using Icarus.Models; diff --git a/Database/Contexts/SongContext.cs b/Database/Contexts/SongContext.cs index ff7ed98..897fd8b 100644 --- a/Database/Contexts/SongContext.cs +++ b/Database/Contexts/SongContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; using Icarus.Models; @@ -27,19 +23,19 @@ public class SongContext : DbContext modelBuilder.Entity() .Property(s => s.Year) - .IsRequired(false); + .IsRequired(false); modelBuilder.Entity() .Property(s => s.GenreID) - .IsRequired(false); + .IsRequired(false); modelBuilder.Entity() .Property(s => s.ArtistID) - .IsRequired(false); + .IsRequired(false); modelBuilder.Entity() .Property(s => s.AlbumID) - .IsRequired(false); + .IsRequired(false); modelBuilder.Entity() - .Property(s => s.CoverArtID) - .IsRequired(false); + .Property(s => s.CoverArtID) + .IsRequired(false); } diff --git a/Database/Contexts/UserContext.cs b/Database/Contexts/UserContext.cs index d83287e..f8b7c6b 100644 --- a/Database/Contexts/UserContext.cs +++ b/Database/Contexts/UserContext.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using Icarus.Models; -- 2.47.3