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,153 @@
using Microsoft.AspNetCore.Mvc;
using Shadow.Data;
using Shadow.DTOs;
using Shadow.Entities;
using Shadow.Tools;
namespace Shadow.Controllers;
[ApiController]
[Route("rest")]
[Produces("application/json")]
public class MiscController : ControllerBase
{
private readonly ApplicationDbContext db;
private readonly GeneralUseHelpers guhf;
public MiscController(ApplicationDbContext _db, GeneralUseHelpers _guhf)
{
db = _db;
guhf = _guhf;
}
[HttpGet("ping")]
[ProducesResponseType(200)]
public async Task<IActionResult> Ping()
{
User? user = await guhf.GetUserFromParams(Request);
// Wrong credentials?
if (user == null)
{
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
Status = "failed",
error = new ErrorDTO
{
code = 40,
message = "Wrong username or password."
}
}
});
}
return Ok(new ResponseWrapper {
SubsonicResponse = new SubsonicResponseDTO()
});
}
[HttpPost("ping.view")]
[ProducesResponseType(200)]
public async Task<IActionResult> PingForm()
{
User? user = await guhf.GetUserFromForm(Request);
// Wrong credentials?
if (user == null) {
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO {
Status = "failed",
error = new ErrorDTO {
code = 40,
message = "Wrong username or password."
}
}
});
}
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO()
});
}
[HttpGet("getUser")]
[ProducesResponseType(200)]
public async Task<IActionResult> GetUser()
{
User? user = await guhf.GetUserFromParams(Request);
// Wrong credentials?
if (user == null)
{
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
Status = "failed",
error = new ErrorDTO
{
code = 40,
message = "Wrong username or password."
}
}
});
}
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
userPing = new UserPingDTO
{
username = user.Name,
adminRole = user.IsAdmin()
}
}
});
}
[HttpPost("getUser.view")]
[ProducesResponseType(200)]
public async Task<IActionResult> GetUserForm()
{
User? user = await guhf.GetUserFromForm(Request);
// Wrong credentials?
if (user == null)
{
// Craft an error
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
Status = "failed",
error = new ErrorDTO
{
code = 40,
message = "Wrong username or password."
}
}
});
}
return Ok(new ResponseWrapper
{
SubsonicResponse = new SubsonicResponseDTO
{
userPing = new UserPingDTO
{
username = user.Name,
adminRole = user.IsAdmin()
}
}
});
}
}