chore: init commit from GitHub
Some checks are pending
Deploy / update (push) Waiting to run
Build Project .NET / build (push) Waiting to run

This commit is contained in:
Lisoveliy
2025-05-12 19:44:33 +03:00
parent 11a3f40596
commit aebe654c38
107 changed files with 18953 additions and 403 deletions

View File

@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
using SWAD.API.Consts.Enums;
namespace SWAD.API.Controllers.DTOs;
/// <summary>
/// Track directly from query
/// </summary>
/// <param Name="Name">Name of track</param>
/// <param Name="Artist">Artist of track</param>
/// <param Name="AlbumObject">AlbumObject of track</param>
/// <param Name="Service">Service provider</param>
public record TrackDto([Required] string Name, [Required] string Artist, string Album, MusicService Service);
/// <summary>
/// Track from service link
/// </summary>
/// <param Name="Link">
/// Spotify example: https://open.spotify.com/track/2K7xn816oNHJZ0aVqdQsha
/// Tidal example: https://tidal.com/track/294942856
/// Yandex.Music example: https://music.yandex.by/Albums/25851387/track/113810002 P.S.: Будда какая параша, даже тут
/// яндекс отличился
/// </param>
/// <param Name="Service">
/// </param>
public record TrackLinkDto([Required] string Link, [Required] MusicService Service);
/// <summary>
/// Service Name
/// </summary>
/// <param Name="Service">Enum MusicService</param>
/// <param Name="Name">MusicService.ToString</param>
public record ServiceDto(MusicService Service, string Name);
/// <summary>
/// Result of GetLink method
/// </summary>
/// <param Name="Link"></param>
public record LinkResultDto(string? Link);

View File

@@ -0,0 +1,111 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using SWAD.API.Consts;
using SWAD.API.Consts.Enums;
using SWAD.API.Controllers.DTOs;
using SWAD.API.Services.Links;
namespace SWAD.API.Controllers;
/// <summary>
/// Controller for get links from music providers
/// </summary>
[Tags($"{nameof(LinkController)}: Controller for get links from music providers")]
[Route("[controller]")]
[ApiController]
public class LinkController(LinksService linksService) : SwadController
{
/// <summary>
/// Get link from other link
/// </summary>
/// <param Name="track">Track query such as Name, artist, Albums</param>
/// <returns>Link for track</returns>
[HttpPost("FromLink")]
[ProducesResponseType(typeof(LinkResultDto), 200)]
[ProducesResponseType(typeof(ProblemDetails), 400)]
[ProducesResponseType(typeof(ProblemDetails), 404)]
[ProducesResponseType(typeof(ProblemDetails), 502)]
public async Task<IActionResult> GetLink(TrackLinkDto track)
{
var serviceResult = await linksService.MapLinks(track);
switch (serviceResult.result)
{
case ServiceResult.Success:
return Ok(new LinkResultDto(serviceResult.link));
case ServiceResult.Failure:
return BadRequest($"{track.Link} is not recognized. Try other link");
case ServiceResult.NoResponse:
return BadGateway("Bad gateway with one of services");
case ServiceResult.BadRequest:
return BadRequest($"Unknown service {track.Service} or parameters not valid");
case ServiceResult.NotFound:
return NotFound(ErrorResources.NotFound);
default:
throw new ApplicationException("Unknown response from service");
}
}
/// <summary>
/// Get link from search query such as artist and song Name
/// </summary>
/// <param Name="track">Track query such as Name, artist, Albums</param>
/// <returns>Link for track</returns>
[HttpPost("FromQuery")]
[ProducesResponseType(typeof(LinkResultDto), 200)]
[ProducesResponseType(typeof(ProblemDetails), 400)]
[ProducesResponseType(typeof(ProblemDetails), 404)]
[ProducesResponseType(typeof(ProblemDetails), 502)]
public async Task<IActionResult> GetLink(TrackDto track)
{
var serviceResult = await linksService.GetLinkByQuery(track);
switch (serviceResult.result)
{
case ServiceResult.Success:
return Ok(new LinkResultDto(serviceResult.link));
case ServiceResult.Failure:
return NotFound($"Track {track.Name} - {track.Artist} not found!");
case ServiceResult.NoResponse:
return BadGateway($"Bad gateway with service {track.Service}");
case ServiceResult.BadRequest:
return BadRequest($"Unknown service {track.Service} or parameters not valid");
case ServiceResult.NotFound:
return BadRequest(ErrorResources.NotFound);
default:
throw new ApplicationException($"Unknown response from service {linksService}");
}
}
/// <summary>
/// Get service what uses that link
/// </summary>
/// <param name="link"></param>
/// <returns></returns>
/// <exception cref="ApplicationException"></exception>
[HttpGet("GetService")]
[ProducesResponseType(typeof(ServiceDto), 200)]
[ProducesResponseType(typeof(ProblemDetails), 400)]
public async Task<IActionResult> GetServiceOfLink([Required] string link)
{
var serviceResult = await linksService.GetServiceByLink(link);
switch (serviceResult.result)
{
case ServiceResult.Success:
return Ok(new ServiceDto(serviceResult.service!.Value,
serviceResult.service.Value.ToString()));
case ServiceResult.Failure:
return BadRequest($"{link} is not recognized. Try other link");
default:
throw new ApplicationException("WTF are you doing?");
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;
namespace SWAD.API.Controllers;
public abstract class ProblemsController : ControllerBase
{
protected ObjectResult BadRequest(string? detail)
{
return Problem(statusCode: StatusCodes.Status400BadRequest, title: "Bad request!", detail: detail);
}
protected ObjectResult NotFound(string? detail)
{
return Problem(statusCode: StatusCodes.Status404NotFound, title: "Not found :c", detail: detail);
}
protected ObjectResult BadGateway(string? detail)
{
return Problem(statusCode: StatusCodes.Status502BadGateway, title: "Some problems in other side, dude!",
detail: detail);
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc;
namespace SWAD.API.Controllers;
public class SwadController : ProblemsController
{
public static string GetTitleForSwagger(string controllerName, string description)
{
return $"{controllerName}: {description}";
}
}