mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-03-05 13:20:20 -05:00
Add v5 Language endpoints
This commit is contained in:
35
src/Sonarr.Api.V5/Localization/LanguageController.cs
Normal file
35
src/Sonarr.Api.V5/Localization/LanguageController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Languages;
|
||||
using Sonarr.Http;
|
||||
using Sonarr.Http.REST;
|
||||
|
||||
namespace Sonarr.Api.V5.Localization;
|
||||
|
||||
[V5ApiController]
|
||||
public class LanguageController : RestController<LanguageResource>
|
||||
{
|
||||
protected override LanguageResource GetResourceById(int id)
|
||||
{
|
||||
var language = (Language)id;
|
||||
|
||||
return new LanguageResource
|
||||
{
|
||||
Id = (int)language,
|
||||
Name = language.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<LanguageResource> GetAll()
|
||||
{
|
||||
var languageResources = Language.All.Select(l => new LanguageResource
|
||||
{
|
||||
Id = (int)l,
|
||||
Name = l.ToString()
|
||||
})
|
||||
.OrderBy(l => l.Id > 0).ThenBy(l => l.Name)
|
||||
.ToList();
|
||||
|
||||
return languageResources;
|
||||
}
|
||||
}
|
||||
12
src/Sonarr.Api.V5/Localization/LanguageResource.cs
Normal file
12
src/Sonarr.Api.V5/Localization/LanguageResource.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Sonarr.Http.REST;
|
||||
|
||||
namespace Sonarr.Api.V5.Localization;
|
||||
|
||||
public class LanguageResource : RestResource
|
||||
{
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
public new int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? NameLower => Name?.ToLowerInvariant();
|
||||
}
|
||||
Reference in New Issue
Block a user