feat: add album and miscellaneous controllers with album mapping
All checks were successful
Update changelog / changelog (push) Successful in 26s

This commit is contained in:
2026-01-28 05:18:03 +01:00
parent 6736ce8c13
commit a1c9e3807b
4 changed files with 367 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
using Shadow.Data;
using Shadow.DTOs;
using Shadow.Entities;
using Shadow.Mapping;
using Shadow.Tools;
namespace Shadow.Controllers;
[ApiController]
[Route("rest")]
[Produces("application/json")]
public class AlbumController : ControllerBase
{
private readonly ApplicationDbContext db;
private readonly GeneralUseHelpers guhf;
public AlbumController(ApplicationDbContext _db, GeneralUseHelpers _guhf)
{
db = _db;
guhf = _guhf;
}
[HttpGet("getCoverArt")]
[HttpGet("getCoverArt.view")]
[HttpPost("getCoverArt.view")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<IActionResult> GetCoverArt()
{
string thumbnailPath = db.Globals
.First(g => g.Key == "musicThumbnailPath").Value!;
IFileInfo fileInfo = new PhysicalFileProvider(thumbnailPath)
.GetFileInfo("default.png");
if (!fileInfo.Exists) return NotFound();
return PhysicalFile(fileInfo.PhysicalPath!, "image/png");
}
[HttpGet("getAlbumList2")]
[ProducesResponseType(200)]
public async Task<IActionResult> GetAlbumList2()
{
// First, check if user is authorized
User? user = await guhf.GetUserFromParams(Request);
if (user == null)
{
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
Status = "failed",
error = new ErrorDTO()
}
});
}
List<AlbumViewShortDTO> albumsDTO = [];
List<Album> albums = db.Albums
.Where(a => a.State != 1)
.Include(a => a.Artist)
.Include(a => a.Songs)
.ToList();
foreach (Album al in albums)
{
albumsDTO.Add(
AlbumMapping.ToAlbumViewShort(al)
);
}
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
albumList2 = new AlbumList2DTO
{
album = albumsDTO
}
}
});
}
[HttpPost("getAlbumList2.view")]
[ProducesResponseType(200)]
public async Task<IActionResult> GetAlbumList2Form()
{
// First, check if user is authorized
User? user = await guhf.GetUserFromForm(Request);
if (user == null)
{
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
Status = "failed",
error = new ErrorDTO()
}
});
}
List<AlbumViewShortDTO> albumsDTO = [];
List<Album> albums = db.Albums
.Where(a => a.State != 1)
.Include(a => a.Artist)
.Include(a => a.Songs)
.ToList();
foreach (Album al in albums)
{
albumsDTO.Add(
AlbumMapping.ToAlbumViewShort(al)
);
}
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
albumList2 = new AlbumList2DTO
{
album = albumsDTO
}
}
});
}
}