diff --git a/Icarus/.editconfig b/Icarus/.editconfig new file mode 100644 index 0000000..8020433 --- /dev/null +++ b/Icarus/.editconfig @@ -0,0 +1,19 @@ +# Top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.cs] +# Use 'var' when possible +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion + +# Use expression body for methods +csharp_style_expression_bodied_methods = true:silent \ No newline at end of file diff --git a/Icarus/Controllers/Managers/TokenManager.cs b/Icarus/Controllers/Managers/TokenManager.cs index bbb79e7..ee0aeed 100644 --- a/Icarus/Controllers/Managers/TokenManager.cs +++ b/Icarus/Controllers/Managers/TokenManager.cs @@ -149,7 +149,7 @@ public class TokenManager : BaseManager return null; } - public int? RetrieveUserIdFromToken(string token) + public Guid? RetrieveUserIdFromToken(string token) { var parsedToken = this.ContainsBearer(token) ? this.StripBearer(token) : token; var tokenHandler = new JwtSecurityTokenHandler(); @@ -159,7 +159,15 @@ public class TokenManager : BaseManager { if (item.Key == "user_id") { - return Convert.ToInt32(item.Value); + if (item.Value != null) + { + var id = item.Value.ToString(); + return Guid.Parse(id!); + } + else + { + return null; + } } } diff --git a/Icarus/Controllers/v1/AccessLevelController.cs b/Icarus/Controllers/v1/AccessLevelController.cs index 1d74488..b7ace42 100644 --- a/Icarus/Controllers/v1/AccessLevelController.cs +++ b/Icarus/Controllers/v1/AccessLevelController.cs @@ -27,9 +27,9 @@ public class AccessLevelController : BaseController #region HTTP Routes [HttpGet] - public IActionResult GetAccessLevels(int? id, int? songId) + public IActionResult GetAccessLevels(Guid? id, Guid? songId) { - var accLevel = new Models.AccessLevel { Id = 0 }; + var accLevel = new Models.AccessLevel { }; var accessLevelContext = new Database.Contexts.AccessLevelContext(_connectionString!); if (id != null) @@ -43,7 +43,7 @@ public class AccessLevelController : BaseController var response = new GetAccessLevelsResponse { Data = new List() }; - if (accLevel?.Id > 0) + if (accLevel?.Id.ToString().Length > 0) { response.Subject = "Successful"; response.Data.Add(accLevel); @@ -57,7 +57,7 @@ public class AccessLevelController : BaseController } [HttpPatch("{id}")] - public IActionResult UpdateAccessLevel(int id, [FromBody] Models.AccessLevel accessLevel) + public IActionResult UpdateAccessLevel(Guid id, [FromBody] Models.AccessLevel accessLevel) { var response = new UpdateAccessLevelResponse { Data = new List() }; var targetLevel = accessLevel.Level; diff --git a/Icarus/Controllers/v1/AlbumController.cs b/Icarus/Controllers/v1/AlbumController.cs index 76834de..4ccb3a3 100644 --- a/Icarus/Controllers/v1/AlbumController.cs +++ b/Icarus/Controllers/v1/AlbumController.cs @@ -46,7 +46,7 @@ public class AlbumController : BaseController } [HttpGet("{id}")] - public IActionResult GetAlbum(int id) + public IActionResult GetAlbum(Guid id) { Album album = new Album { Id = id }; diff --git a/Icarus/Controllers/v1/ArtistController.cs b/Icarus/Controllers/v1/ArtistController.cs index b336088..ca26ebf 100644 --- a/Icarus/Controllers/v1/ArtistController.cs +++ b/Icarus/Controllers/v1/ArtistController.cs @@ -46,7 +46,7 @@ public class ArtistController : BaseController } [HttpGet("{id}")] - public IActionResult GetArtist(int id) + public IActionResult GetArtist(Guid id) { Artist artist = new Artist { Id = id }; diff --git a/Icarus/Controllers/v1/CoverArtController.cs b/Icarus/Controllers/v1/CoverArtController.cs index d28af2c..fc2e808 100644 --- a/Icarus/Controllers/v1/CoverArtController.cs +++ b/Icarus/Controllers/v1/CoverArtController.cs @@ -49,7 +49,7 @@ public class CoverArtController : BaseController } [HttpGet("{id}")] - public IActionResult GetCoverArt(int id) + public IActionResult GetCoverArt(Guid id) { var coverArt = new CoverArt { Id = id }; @@ -74,7 +74,7 @@ public class CoverArtController : BaseController } [HttpGet("data/download/{id}")] - public async Task Download(int id, [FromQuery] bool? randomizeFilename) + public async Task Download(Guid id, [FromQuery] bool? randomizeFilename) { var songContext = new SongContext(_connectionString!); var covMgr = new CoverArtManager(this._config!); diff --git a/Icarus/Controllers/v1/GenreController.cs b/Icarus/Controllers/v1/GenreController.cs index 6cdec26..51c166d 100644 --- a/Icarus/Controllers/v1/GenreController.cs +++ b/Icarus/Controllers/v1/GenreController.cs @@ -50,7 +50,7 @@ public class GenreController : BaseController } [HttpGet("{id}")] - public IActionResult GetGenre(int id) + public IActionResult GetGenre(Guid id) { var genre = new Genre { Id = id }; diff --git a/Icarus/Controllers/v1/SongCompressedDataControllers.cs b/Icarus/Controllers/v1/SongCompressedDataControllers.cs index d82864b..cbd55de 100644 --- a/Icarus/Controllers/v1/SongCompressedDataControllers.cs +++ b/Icarus/Controllers/v1/SongCompressedDataControllers.cs @@ -37,7 +37,7 @@ public class SongCompressedDataController : BaseController #region API Routes [HttpGet("{id}")] - public async Task DownloadCompressedSong(int id, [FromQuery] bool? randomizeFilename) + public async Task DownloadCompressedSong(Guid id, [FromQuery] bool? randomizeFilename) { var context = new SongContext(_connectionString!); diff --git a/Icarus/Controllers/v1/SongController.cs b/Icarus/Controllers/v1/SongController.cs index f59a0c9..ba71459 100644 --- a/Icarus/Controllers/v1/SongController.cs +++ b/Icarus/Controllers/v1/SongController.cs @@ -57,7 +57,7 @@ public class SongController : BaseController } [HttpGet("{id}")] - public IActionResult GetSong(int id) + public IActionResult GetSong(Guid id) { var context = new SongContext(_connectionString!); @@ -65,14 +65,14 @@ public class SongController : BaseController Console.WriteLine("Here"); - if (song.Id != 0) + if (song.Id.ToString().Length != 0) return Ok(song); else return NotFound(); } [HttpPut("{id}")] - public IActionResult UpdateSong(int id, [FromBody] Song song) + public IActionResult UpdateSong(Guid id, [FromBody] Song song) { song.Id = id; Console.WriteLine("Retrieving filepath of song"); diff --git a/Icarus/Controllers/v1/SongDataController.cs b/Icarus/Controllers/v1/SongDataController.cs index 4cbd4b4..b2e62eb 100644 --- a/Icarus/Controllers/v1/SongDataController.cs +++ b/Icarus/Controllers/v1/SongDataController.cs @@ -40,7 +40,7 @@ public class SongDataController : BaseController [HttpGet("download/{id}")] - public IActionResult Download(int id, [FromQuery] bool? randomizeFilename) + public IActionResult Download(Guid id, [FromQuery] bool? randomizeFilename) { var tokenManager = new TokenManager(this._config!); var songContext = new SongContext(this._connectionString!); @@ -172,7 +172,7 @@ public class SongDataController : BaseController } [HttpDelete("delete/{id}")] - public IActionResult DeleteSong(int id) + public IActionResult DeleteSong(Guid id) { var songContext = new SongContext(_connectionString!); var songMetaData = songContext.RetrieveRecord(new Song { Id = id }); diff --git a/Icarus/Controllers/v1/SongStreamController.cs b/Icarus/Controllers/v1/SongStreamController.cs index f38a966..27469de 100644 --- a/Icarus/Controllers/v1/SongStreamController.cs +++ b/Icarus/Controllers/v1/SongStreamController.cs @@ -32,7 +32,7 @@ public class SongStreamController : BaseController #region HTTP endpoints [HttpGet("{id}")] - public async Task StreamSong(int id) + public async Task StreamSong(Guid id) { var context = new SongContext(_config!.GetConnectionString("DefaultConnection")!); diff --git a/Icarus/Database/Contexts/AccessLevelContext.cs b/Icarus/Database/Contexts/AccessLevelContext.cs index ac8a5ea..280cd0a 100644 --- a/Icarus/Database/Contexts/AccessLevelContext.cs +++ b/Icarus/Database/Contexts/AccessLevelContext.cs @@ -20,7 +20,7 @@ public class AccessLevelContext : DbContext #endregion #region Methods - public Models.AccessLevel? GetAccessLevel(int songId) + public Models.AccessLevel? GetAccessLevel(Guid songId) { var accessLevel = this.AccessLevels!.FirstOrDefault(acc => acc.SongId == songId); return accessLevel; @@ -30,6 +30,14 @@ public class AccessLevelContext : DbContext { modelBuilder.Entity().ToTable("AccessLevel"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); + modelBuilder.Entity().Property(m => m.Level).IsRequired(true); } #endregion diff --git a/Icarus/Database/Contexts/AlbumContext.cs b/Icarus/Database/Contexts/AlbumContext.cs index 5a312ee..2bbb510 100644 --- a/Icarus/Database/Contexts/AlbumContext.cs +++ b/Icarus/Database/Contexts/AlbumContext.cs @@ -18,6 +18,14 @@ public class AlbumContext : DbContext { modelBuilder.Entity() .ToTable("Album"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); } public Album RetrieveRecord(Album album) diff --git a/Icarus/Database/Contexts/ArtistContext.cs b/Icarus/Database/Contexts/ArtistContext.cs index 6f77d81..94b892c 100644 --- a/Icarus/Database/Contexts/ArtistContext.cs +++ b/Icarus/Database/Contexts/ArtistContext.cs @@ -18,6 +18,14 @@ public class ArtistContext : DbContext { modelBuilder.Entity() .ToTable("Artist"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); } public Artist RetrieveRecord(Artist artist) diff --git a/Icarus/Database/Contexts/CoverArtContext.cs b/Icarus/Database/Contexts/CoverArtContext.cs index 5a5f6d1..3626896 100644 --- a/Icarus/Database/Contexts/CoverArtContext.cs +++ b/Icarus/Database/Contexts/CoverArtContext.cs @@ -20,6 +20,13 @@ public class CoverArtContext : DbContext { modelBuilder.Entity() .ToTable("CoverArt"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); } public CoverArt RetrieveRecord(CoverArt cover) diff --git a/Icarus/Database/Contexts/GenreContext.cs b/Icarus/Database/Contexts/GenreContext.cs index 1091119..dbd1425 100644 --- a/Icarus/Database/Contexts/GenreContext.cs +++ b/Icarus/Database/Contexts/GenreContext.cs @@ -20,6 +20,14 @@ public class GenreContext : DbContext { modelBuilder.Entity() .ToTable("Genre"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); } diff --git a/Icarus/Database/Contexts/SongContext.cs b/Icarus/Database/Contexts/SongContext.cs index 192b011..5eaeac0 100644 --- a/Icarus/Database/Contexts/SongContext.cs +++ b/Icarus/Database/Contexts/SongContext.cs @@ -21,6 +21,14 @@ public class SongContext : DbContext modelBuilder.Entity() .ToTable("Song"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); + }); + modelBuilder.Entity() .Property(s => s.Year) .IsRequired(false); diff --git a/Icarus/Database/Contexts/UserContext.cs b/Icarus/Database/Contexts/UserContext.cs index 3bb0cec..f2f7ce8 100644 --- a/Icarus/Database/Contexts/UserContext.cs +++ b/Icarus/Database/Contexts/UserContext.cs @@ -23,6 +23,14 @@ public class UserContext : DbContext { modelBuilder.Entity() .ToTable("User"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); + + entity.Property(e => e.Id) + .HasColumnType("binary(16)"); // **** Map Guid to BINARY(16) **** + }); modelBuilder.Entity() .Property(u => u.LastLogin).IsRequired(false); modelBuilder.Entity() diff --git a/Models/.editconfig b/Models/.editconfig new file mode 100644 index 0000000..8020433 --- /dev/null +++ b/Models/.editconfig @@ -0,0 +1,19 @@ +# Top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.cs] +# Use 'var' when possible +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion + +# Use expression body for methods +csharp_style_expression_bodied_methods = true:silent \ No newline at end of file diff --git a/Models/AccessLevel.cs b/Models/AccessLevel.cs index d983b31..385783d 100644 --- a/Models/AccessLevel.cs +++ b/Models/AccessLevel.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Icarus.Models; @@ -6,11 +7,12 @@ public class AccessLevel { #region Properties [Newtonsoft.Json.JsonProperty("id")] - public int Id { get; set; } + [Key] + public Guid Id { get; set; } [Newtonsoft.Json.JsonProperty("level")] public string? Level { get; set; } [Newtonsoft.Json.JsonProperty("song_id")] - public int SongId { get; set; } + public Guid SongId { get; set; } #endregion #region Methods diff --git a/Models/Album.cs b/Models/Album.cs index 715f745..81b0b37 100644 --- a/Models/Album.cs +++ b/Models/Album.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -8,7 +9,8 @@ public class Album { #region Properties [JsonProperty("id")] - public int Id { get; set; } + [Key] + public Guid Id { get; set; } [JsonProperty("title")] public string? Title { get; set; } [JsonProperty("album_artist")] diff --git a/Models/Artist.cs b/Models/Artist.cs index 699930f..957d7ee 100644 --- a/Models/Artist.cs +++ b/Models/Artist.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -8,7 +9,8 @@ public class Artist { #region Properties [JsonProperty("id")] - public int Id { get; set; } + [Key] + public Guid Id { get; set; } [JsonProperty("name")] [Column("Artist")] public string? Name { get; set; } diff --git a/Models/CoverArt.cs b/Models/CoverArt.cs index 3343e17..6eb3839 100644 --- a/Models/CoverArt.cs +++ b/Models/CoverArt.cs @@ -1,3 +1,5 @@ +using System.ComponentModel.DataAnnotations; + using Newtonsoft.Json; namespace Icarus.Models; @@ -6,7 +8,8 @@ public class CoverArt { #region Properties [JsonProperty("id")] - public int Id { get; set; } + [Key] + public Guid Id { get; set; } [JsonProperty("title")] public string? SongTitle { get; set; } [JsonIgnore] diff --git a/Models/CreateFile.cs b/Models/CreateFile.cs index 6e16e3d..4d0cbd0 100644 --- a/Models/CreateFile.cs +++ b/Models/CreateFile.cs @@ -1,6 +1,3 @@ - - - namespace Icarus.Models; public enum CreateFileResult diff --git a/Models/Genre.cs b/Models/Genre.cs index c1a4af1..8b397c4 100644 --- a/Models/Genre.cs +++ b/Models/Genre.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -8,7 +9,7 @@ public class Genre { #region Properties [JsonProperty("id")] - public int Id { get; set; } + public Guid Id { get; set; } [JsonProperty("genre")] [Column("Category")] public string? GenreName { get; set; } diff --git a/Models/LoginResult.cs b/Models/LoginResult.cs index d8d4da7..bf7942a 100644 --- a/Models/LoginResult.cs +++ b/Models/LoginResult.cs @@ -6,7 +6,7 @@ public class LoginResult : BaseResult { #region Properties [JsonProperty("user_id")] - public int UserId { get; set; } + public Guid UserId { get; set; } [JsonProperty("username")] public string? Username { get; set; } [JsonProperty("token")] diff --git a/Models/Song.cs b/Models/Song.cs index c314adf..3fd38fd 100644 --- a/Models/Song.cs +++ b/Models/Song.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -8,7 +9,8 @@ public class Song { #region Properties [JsonProperty("id")] - public int Id { get; set; } + [Key] + public Guid Id { get; set; } [JsonProperty("title")] public string? Title { get; set; } [JsonProperty("album")] @@ -39,17 +41,17 @@ public class Song [JsonProperty("disc_count")] public int DiscCount { get; set; } = 0; [JsonIgnore] - public int? AlbumId { get; set; } + public Guid? AlbumId { get; set; } [JsonIgnore] - public int? ArtistId { get; set; } + public Guid? ArtistId { get; set; } [JsonIgnore] - public int? GenreId { get; set; } + public Guid? GenreId { get; set; } [JsonIgnore] - public int? CoverArtId { get; set; } + public Guid? CoverArtId { get; set; } [JsonProperty("date_created")] public DateTime DateCreated { get; set; } [JsonProperty("user_id")] - public int UserId { get; set; } + public Guid UserId { get; set; } #endregion diff --git a/Models/SongData.cs b/Models/SongData.cs index 8600368..3865018 100644 --- a/Models/SongData.cs +++ b/Models/SongData.cs @@ -3,7 +3,7 @@ namespace Icarus.Models; public class SongData { #region Properties - public int ID { get; set; } + public Guid ID { get; set; } public byte[]? Data { get; set; } public int SongID { get; set; } #endregion diff --git a/Models/User.cs b/Models/User.cs index 95182f4..b2d0721 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -12,7 +12,7 @@ public class User [JsonProperty("id")] [Column("Id")] [Key] - public int Id { get; set; } + public Guid Id { get; set; } [JsonProperty("username")] public string? Username { get; set; } [JsonProperty("password")]