* #95: Updated Id of the CoverArt model * Model and migration changes
This commit was merged in pull request #99.
This commit is contained in:
@@ -45,14 +45,14 @@ public class AlbumManager : BaseManager
|
||||
_albumContext.Add(album);
|
||||
_albumContext.SaveChanges();
|
||||
|
||||
Console.WriteLine($"Album Id {album.AlbumID}");
|
||||
Console.WriteLine($"Album Id {album.Id}");
|
||||
}
|
||||
else
|
||||
{
|
||||
album.AlbumID = albumRetrieved.AlbumID;
|
||||
album.Id = albumRetrieved.Id;
|
||||
}
|
||||
|
||||
song.AlbumID = album.AlbumID;
|
||||
song.AlbumId = album.Id;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class AlbumManager : BaseManager
|
||||
private int SongsInAlbum(Album album)
|
||||
{
|
||||
var sngContext = new SongContext(_connectionString);
|
||||
var songs = sngContext.Songs.Where(sng => sng.AlbumID == album.AlbumID).ToList();
|
||||
var songs = sngContext.Songs.Where(sng => sng.AlbumId == album.Id).ToList();
|
||||
|
||||
return songs.Count;
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ public class ArtistManager : BaseManager
|
||||
}
|
||||
else
|
||||
{
|
||||
artist.ArtistID = artistRetrieved.ArtistID;
|
||||
artist.Id = artistRetrieved.Id;
|
||||
}
|
||||
|
||||
song.ArtistID = artist.ArtistID;
|
||||
song.ArtistId = artist.Id;
|
||||
}
|
||||
|
||||
public Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)
|
||||
@@ -120,7 +120,7 @@ public class ArtistManager : BaseManager
|
||||
private int SongsOfArtist(Artist artist)
|
||||
{
|
||||
var sngContext = new SongContext(_connectionString);
|
||||
var songs = sngContext.Songs.Where(sng => sng.ArtistID == artist.ArtistID).ToList();
|
||||
var songs = sngContext.Songs.Where(sng => sng.ArtistId == artist.Id).ToList();
|
||||
|
||||
return songs.Count;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using Icarus.Constants;
|
||||
using Icarus.Controllers.Utilities;
|
||||
using Icarus.Database.Contexts;
|
||||
using Icarus.Models;
|
||||
using Icarus.Types;
|
||||
|
||||
namespace Icarus.Controllers.Managers;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class CoverArtManager : BaseManager
|
||||
_coverArtContext.Add(coverArt);
|
||||
_coverArtContext.SaveChanges();
|
||||
|
||||
song.CoverArtID = coverArt.CoverArtID;
|
||||
song.CoverArtId = coverArt.Id;
|
||||
}
|
||||
public void DeleteCoverArtFromDatabase(CoverArt coverArt)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Reflection.PortableExecutable;
|
||||
using Icarus.Models;
|
||||
using Icarus.Types;
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ public class GenreManager : BaseManager
|
||||
}
|
||||
else
|
||||
{
|
||||
genre.GenreID = genreRetrieved.GenreID;
|
||||
genre.Id = genreRetrieved.Id;
|
||||
}
|
||||
|
||||
song.GenreID = genre.GenreID;
|
||||
song.GenreId = genre.Id;
|
||||
}
|
||||
|
||||
public Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)
|
||||
@@ -120,7 +120,7 @@ public class GenreManager : BaseManager
|
||||
private int SongsInGenre(Genre genre)
|
||||
{
|
||||
var sngContext = new SongContext(_connectionString);
|
||||
var songs = sngContext.Songs.Where(sng => sng.GenreID == genre.GenreID).ToList();
|
||||
var songs = sngContext.Songs.Where(sng => sng.GenreId == genre.Id).ToList();
|
||||
|
||||
return songs.Count;
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ public class SongManager : BaseManager
|
||||
var gnrMgr = new GenreManager(_config);
|
||||
var artMgr = new ArtistManager(_config);
|
||||
var updatedAlbum = albMgr.UpdateAlbumInDatabase(oldSongRecord, updatedSong);
|
||||
oldSongRecord.AlbumID = updatedAlbum.AlbumID;
|
||||
oldSongRecord.AlbumId = updatedAlbum.Id;
|
||||
|
||||
var updatedArtist = artMgr.UpdateArtistInDatabase(oldSongRecord, updatedSong);
|
||||
oldSongRecord.ArtistID = updatedArtist.ArtistID;
|
||||
oldSongRecord.ArtistId = updatedArtist.Id;
|
||||
|
||||
var updatedGenre = gnrMgr.UpdateGenreInDatabase(oldSongRecord, updatedSong);
|
||||
oldSongRecord.GenreID = updatedGenre.GenreID;
|
||||
oldSongRecord.GenreId = updatedGenre.Id;
|
||||
|
||||
UpdateSongInDatabase(ref oldSongRecord, ref updatedSong, ref result);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public class TokenManager : BaseManager
|
||||
private string _audience;
|
||||
private string _grantType;
|
||||
private string _url;
|
||||
private string SUCCESSFUL_TOKEN_MESSAGE = "Successfully retrieved token";
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -67,12 +68,7 @@ public class TokenManager : BaseManager
|
||||
.DeserializeObject<TokenTierOne>(response.Content);
|
||||
_logger.Info("Response deserialized");
|
||||
|
||||
return new LoginResult
|
||||
{
|
||||
UserID = user.UserID, Username = user.Username, Token = tokenResult.AccessToken,
|
||||
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
||||
Message = "Successfully retrieved token"
|
||||
};
|
||||
return this.InitializeLoginResult(user, tokenResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +77,7 @@ public class TokenManager : BaseManager
|
||||
var tokenResult = new TokenTierOne{ TokenType = "JWT" };
|
||||
|
||||
var payload = Payload();
|
||||
payload.Add(new Claim("user_id", user.UserID.ToString(), ClaimValueTypes.Integer));
|
||||
payload.Add(new Claim("user_id", user.Id.ToString(), ClaimValueTypes.Integer));
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_config["JWT:Secret"]);
|
||||
@@ -89,7 +85,7 @@ public class TokenManager : BaseManager
|
||||
{
|
||||
Subject = new ClaimsIdentity(new Claim[]
|
||||
{
|
||||
new Claim("user_id", user.UserID.ToString(), ClaimValueTypes.Integer)
|
||||
new Claim("user_id", user.Id.ToString(), ClaimValueTypes.Integer)
|
||||
// Add more claims as needed
|
||||
}),
|
||||
Expires = DateTime.UtcNow.AddHours(1),
|
||||
@@ -109,11 +105,16 @@ public class TokenManager : BaseManager
|
||||
var exp = Math.Floor((expiredDate - DateTime.UnixEpoch).TotalSeconds);
|
||||
tokenResult.Expiration = Convert.ToInt32(exp);
|
||||
|
||||
return this.InitializeLoginResult(user, tokenResult);
|
||||
}
|
||||
|
||||
private LoginResult InitializeLoginResult(User user, TokenTierOne token)
|
||||
{
|
||||
return new LoginResult
|
||||
{
|
||||
UserID = user.UserID, Username = user.Username, Token = tokenResult.AccessToken,
|
||||
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
||||
Message = "Successfully retrieved token"
|
||||
UserId = user.Id, Username = user.Username, Token = token.AccessToken,
|
||||
TokenType = token.TokenType, Expiration = token.Expiration,
|
||||
Message = SUCCESSFUL_TOKEN_MESSAGE
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using TagLib;
|
||||
|
||||
@@ -46,16 +42,16 @@ public class MetadataRetriever
|
||||
public static void PrintMetadata(Song song)
|
||||
{
|
||||
Console.WriteLine("\n\nMetadata of the song:");
|
||||
Console.WriteLine($"ID: {song.SongID}");
|
||||
Console.WriteLine($"ID: {song.Id}");
|
||||
Console.WriteLine($"Title: {song.Title}");
|
||||
Console.WriteLine($"Artist: {song.Artist}");
|
||||
Console.WriteLine($"Album: {song.AlbumTitle}");
|
||||
Console.WriteLine($"Genre: {song.Genre}");
|
||||
Console.WriteLine($"Year: {song.Year}");
|
||||
Console.WriteLine($"Duration: {song.Duration}");
|
||||
Console.WriteLine($"AlbumID: {song.AlbumID}");
|
||||
Console.WriteLine($"ArtistID: {song.ArtistID}");
|
||||
Console.WriteLine($"GenreID: {song.GenreID}");
|
||||
Console.WriteLine($"AlbumID: {song.AlbumId}");
|
||||
Console.WriteLine($"ArtistID: {song.ArtistId}");
|
||||
Console.WriteLine($"GenreID: {song.GenreId}");
|
||||
Console.WriteLine($"Song Path: {song.SongPath()}");
|
||||
Console.WriteLine($"Filename: {song.Filename}");
|
||||
Console.WriteLine("\n");
|
||||
|
||||
@@ -48,7 +48,7 @@ public class AlbumController : BaseController
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetAlbum(int id)
|
||||
{
|
||||
Album album = new Album{ AlbumID = id };
|
||||
Album album = new Album{ Id = id };
|
||||
|
||||
var albumContext = new AlbumContext(_connectionString);
|
||||
|
||||
|
||||
@@ -48,10 +48,7 @@ public class ArtistController : BaseController
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetArtist(int id)
|
||||
{
|
||||
Artist artist = new Artist
|
||||
{
|
||||
ArtistID = id
|
||||
};
|
||||
Artist artist = new Artist { Id = id };
|
||||
|
||||
var artistContext = new ArtistContext(_connectionString);
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CoverArtController : BaseController
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetCoverArt(int id)
|
||||
{
|
||||
var coverArt = new CoverArt { CoverArtID = id };
|
||||
var coverArt = new CoverArt { Id = id };
|
||||
|
||||
var coverArtContext = new CoverArtContext(_connectionString);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class CoverArtController : BaseController
|
||||
var songContext = new SongContext(_connectionString);
|
||||
var covMgr = new CoverArtManager(this._config);
|
||||
|
||||
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
||||
var songMetaData = songContext.RetrieveRecord(new Song { Id = id});
|
||||
var c = covMgr.GetCoverArt(songMetaData);
|
||||
|
||||
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.JPG_EXTENSION, songMetaData.Title, randomizeFilename);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GenreController : BaseController
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetGenre(int id)
|
||||
{
|
||||
var genre = new Genre{ GenreID = id };
|
||||
var genre = new Genre { Id = id };
|
||||
|
||||
var genreStore = new GenreContext(_connectionString);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SongCompressedDataController : BaseController
|
||||
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
||||
|
||||
Console.WriteLine("Starting process of retrieving comrpessed song");
|
||||
var sng = context.RetrieveRecord(new Song{ SongID = id });
|
||||
var sng = context.RetrieveRecord(new Song{ Id = id });
|
||||
SongData song = await cmp.RetrieveCompressedSong(sng);
|
||||
|
||||
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.ZIP_EXTENSION, sng.Title, randomizeFilename);
|
||||
|
||||
@@ -61,11 +61,11 @@ public class SongController : BaseController
|
||||
{
|
||||
var context = new SongContext(_connectionString);
|
||||
|
||||
var song = context.RetrieveRecord(new Song{ SongID = id });
|
||||
var song = context.RetrieveRecord(new Song{ Id = id });
|
||||
|
||||
Console.WriteLine("Here");
|
||||
|
||||
if (song.SongID != 0)
|
||||
if (song.Id != 0)
|
||||
return Ok(song);
|
||||
else
|
||||
return NotFound();
|
||||
@@ -74,7 +74,7 @@ public class SongController : BaseController
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult UpdateSong(int id, [FromBody] Song song)
|
||||
{
|
||||
song.SongID = id;
|
||||
song.Id = id;
|
||||
Console.WriteLine("Retrieving filepath of song");
|
||||
_logger.LogInformation("Retrieving filepath of song");
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SongDataController : BaseController
|
||||
public IActionResult Download(int id, [FromQuery] bool? randomizeFilename)
|
||||
{
|
||||
var songContext = new SongContext(_connectionString);
|
||||
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
||||
var songMetaData = songContext.RetrieveRecord(new Song { Id = id});
|
||||
|
||||
var song = _songMgr.RetrieveSong(songMetaData).Result;
|
||||
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.WAV_EXTENSION, songMetaData.Title, randomizeFilename);
|
||||
@@ -110,7 +110,7 @@ public class SongDataController : BaseController
|
||||
|
||||
if (userId != -1)
|
||||
{
|
||||
song.UserID = userId;
|
||||
song.UserId = userId;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Song title: {song.Title}");
|
||||
@@ -131,8 +131,8 @@ public class SongDataController : BaseController
|
||||
{
|
||||
var songContext = new SongContext(_connectionString);
|
||||
|
||||
var songMetaData = new Song{ SongID = id };
|
||||
Console.WriteLine($"Id {songMetaData.SongID}");
|
||||
var songMetaData = new Song{ Id = id };
|
||||
Console.WriteLine($"Id {songMetaData.Id}");
|
||||
|
||||
songMetaData = songContext.RetrieveRecord(songMetaData);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class SongStreamController : BaseController
|
||||
{
|
||||
var context = new SongContext(_config.GetConnectionString("DefaultConnection"));
|
||||
|
||||
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
||||
var song = context.Songs.FirstOrDefault(sng => sng.Id == id);
|
||||
|
||||
var stream = new FileStream(song.SongPath(), FileMode.Open, FileAccess.Read);
|
||||
stream.Position = 0;
|
||||
|
||||
Reference in New Issue
Block a user