From 23b3c6ca737f683cbdcc8e1a5ec0fe3873b4e9c4 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 12 Jun 2024 20:00:11 -0400 Subject: [PATCH] More cleanup and making some constants --- Constants/DirectoryPaths.cs | 3 +++ Database/Contexts/SongContext.cs | 32 -------------------------------- Database/Contexts/UserContext.cs | 5 ----- Models/Album.cs | 6 ------ Models/Artist.cs | 5 ----- Models/CoverArt.cs | 7 ++++--- Models/Genre.cs | 5 ----- Models/Song.cs | 8 ++++---- 8 files changed, 11 insertions(+), 60 deletions(-) diff --git a/Constants/DirectoryPaths.cs b/Constants/DirectoryPaths.cs index be323e5..1bb39dd 100644 --- a/Constants/DirectoryPaths.cs +++ b/Constants/DirectoryPaths.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Runtime.InteropServices; namespace Icarus.Constants; @@ -7,4 +8,6 @@ public class DirectoryPaths { public static string CoverArtPath => Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png"; + public static string FILENAME_CHARACTERS = "ABCDEF0123456789"; + public static int FILENAME_LENGTH = 25; } diff --git a/Database/Contexts/SongContext.cs b/Database/Contexts/SongContext.cs index 3b49a05..ff7ed98 100644 --- a/Database/Contexts/SongContext.cs +++ b/Database/Contexts/SongContext.cs @@ -25,38 +25,6 @@ public class SongContext : DbContext modelBuilder.Entity() .ToTable("Song"); - /** - modelBuilder.Entity() - .HasOne(s => s.Album) - .WithMany(al => al.Songs) - .HasForeignKey(s => s.AlbumID) - .OnDelete(DeleteBehavior.SetNull); - - modelBuilder.Entity() - .HasOne(sa => sa.SongArtist) - .WithMany(ar => ar.Songs) - .HasForeignKey(s => s.ArtistID) - .OnDelete(DeleteBehavior.SetNull); - - modelBuilder.Entity() - .HasOne(s => s.SongGenre) - .WithMany(gnr => gnr.Songs) - .HasForeignKey(s => s.GenreID) - .OnDelete(DeleteBehavior.SetNull); - - modelBuilder.Entity() - .HasOne(s => s.SongYear) - .WithMany(yr => yr.Songs) - .HasForeignKey(s => s.YearID) - .OnDelete(DeleteBehavior.SetNull); - - modelBuilder.Entity() - .HasOne(s => s.SongCoverArt) - .WithMany(ca => ca.Songs) - .HasForeignKey(s => s.CoverArtID) - .OnDelete(DeleteBehavior.SetNull); - */ - modelBuilder.Entity() .Property(s => s.Year) .IsRequired(false); diff --git a/Database/Contexts/UserContext.cs b/Database/Contexts/UserContext.cs index 2ec1249..d83287e 100644 --- a/Database/Contexts/UserContext.cs +++ b/Database/Contexts/UserContext.cs @@ -2,11 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -// using MySql.Data.EntityFrameworkCore; -// using MySql.Data; -// using MySql.Data.EntityFrameworkCore.Extensions; -// using MySql.Data.Entity; -// using MySql.Data.MySqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; diff --git a/Models/Album.cs b/Models/Album.cs index 857aacf..7fe3d64 100644 --- a/Models/Album.cs +++ b/Models/Album.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -20,8 +18,4 @@ public class Album public int SongCount { get; set; } [JsonProperty("year")] public int Year { get; set; } - - [JsonIgnore] - [NotMapped] - public List Songs { get; set; } } diff --git a/Models/Artist.cs b/Models/Artist.cs index b4a8a19..ca66412 100644 --- a/Models/Artist.cs +++ b/Models/Artist.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -16,7 +14,4 @@ public class Artist [JsonProperty("song_count")] [NotMapped] public int SongCount { get; set; } - [JsonIgnore] - [NotMapped] - public List Songs { get; set; } } diff --git a/Models/CoverArt.cs b/Models/CoverArt.cs index 4bf423f..7b22816 100644 --- a/Models/CoverArt.cs +++ b/Models/CoverArt.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Reflection.Metadata; using System.Text; using Newtonsoft.Json; @@ -23,12 +24,12 @@ public class CoverArt #region Methods public string GenerateFilename(int flag) { - const int length = 25; - const string chars = "ABCDEF0123456789"; + int length = Constants.DirectoryPaths.FILENAME_LENGTH; + string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS; var random = new Random(); var filename = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); - var extension = Icarus.Constants.FileExtensions.JPG_EXTENSION; + var extension = Constants.FileExtensions.JPG_EXTENSION; return (flag == 0) ? filename : $"{filename}{extension}"; } diff --git a/Models/Genre.cs b/Models/Genre.cs index b3ad87a..b157a5f 100644 --- a/Models/Genre.cs +++ b/Models/Genre.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; @@ -16,7 +14,4 @@ public class Genre [JsonProperty("song_count")] [NotMapped] public int SongCount { get; set; } - [JsonIgnore] - [NotMapped] - public List Songs { get; set; } } diff --git a/Models/Song.cs b/Models/Song.cs index 5a76ce4..828005e 100644 --- a/Models/Song.cs +++ b/Models/Song.cs @@ -73,8 +73,8 @@ public class Song public string GenerateFilename(int flag = 0) { - const int length = 25; - const string chars = "ABCDEF0123456789"; + int length = Constants.DirectoryPaths.FILENAME_LENGTH; + string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS; var random = new Random(); var filename = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); @@ -84,8 +84,8 @@ public class Song } public async Task GenerateFilenameAsync(int flag = 0) { - const int length = 25; - const string chars = "ABCDEF0123456789"; + int length = Constants.DirectoryPaths.FILENAME_LENGTH; + string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS; var extension = Icarus.Constants.FileExtensions.WAV_EXTENSION; var random = new Random(); var filename = await Task.Run(() =>