From a091f8c9f953c4ad3cfee5ffea4d19f73d09aae2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 3 Apr 2025 20:01:18 -0400 Subject: [PATCH] Updated more models --- Icarus/Controllers/v1/ArtistController.cs | 2 +- Icarus/Database/Contexts/AccessLevelContext.cs | 8 ++++++++ Icarus/Database/Contexts/AlbumContext.cs | 8 ++++++++ Icarus/Database/Contexts/ArtistContext.cs | 8 ++++++++ Icarus/Database/Contexts/CoverArtContext.cs | 7 +++++++ Icarus/Database/Contexts/GenreContext.cs | 8 ++++++++ Icarus/Database/Contexts/SongContext.cs | 8 ++++++++ Icarus/Database/Contexts/UserContext.cs | 10 +++++----- Models/AccessLevel.cs | 3 ++- Models/Album.cs | 4 +++- Models/Artist.cs | 4 +++- Models/CoverArt.cs | 5 ++++- Models/CreateFile.cs | 3 --- Models/Genre.cs | 3 ++- Models/Song.cs | 4 +++- Models/SongData.cs | 2 +- 16 files changed, 71 insertions(+), 16 deletions(-) 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/Database/Contexts/AccessLevelContext.cs b/Icarus/Database/Contexts/AccessLevelContext.cs index ac8a5ea..fb4b742 100644 --- a/Icarus/Database/Contexts/AccessLevelContext.cs +++ b/Icarus/Database/Contexts/AccessLevelContext.cs @@ -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..9fafa54 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..11b1dba 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..5b692a5 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..95176ec 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..9a87856 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 818ad3d..f2f7ce8 100644 --- a/Icarus/Database/Contexts/UserContext.cs +++ b/Icarus/Database/Contexts/UserContext.cs @@ -25,12 +25,12 @@ public class UserContext : DbContext .ToTable("User"); modelBuilder.Entity(entity => -{ - entity.HasKey(e => e.Id); + { + entity.HasKey(e => e.Id); - entity.Property(e => e.Id) - .HasColumnType("binary(16)"); // **** Map Guid to BINARY(16) **** -}); + 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/AccessLevel.cs b/Models/AccessLevel.cs index d983b31..1c11cb7 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,7 +7,7 @@ public class AccessLevel { #region Properties [Newtonsoft.Json.JsonProperty("id")] - public int Id { get; set; } + public Guid Id { get; set; } [Newtonsoft.Json.JsonProperty("level")] public string? Level { get; set; } [Newtonsoft.Json.JsonProperty("song_id")] 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/Song.cs b/Models/Song.cs index c314adf..22192af 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")] 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