You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
3 years ago
|
using System.Collections.Generic;
|
||
|
using FluentValidation;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using NzbDrone.Core.Profiles;
|
||
|
using NzbDrone.Http.REST.Attributes;
|
||
|
using Prowlarr.Http;
|
||
|
using Prowlarr.Http.REST;
|
||
|
|
||
|
namespace Prowlarr.Api.V1.Profiles.App
|
||
|
{
|
||
|
[V1ApiController]
|
||
|
public class AppProfileController : RestController<AppProfileResource>
|
||
|
{
|
||
|
private readonly IProfileService _profileService;
|
||
|
|
||
|
public AppProfileController(IProfileService profileService)
|
||
|
{
|
||
|
_profileService = profileService;
|
||
|
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||
|
}
|
||
|
|
||
|
[RestPostById]
|
||
|
public ActionResult<AppProfileResource> Create(AppProfileResource resource)
|
||
|
{
|
||
|
var model = resource.ToModel();
|
||
|
model = _profileService.Add(model);
|
||
|
return Created(model.Id);
|
||
|
}
|
||
|
|
||
|
[RestDeleteById]
|
||
|
public void DeleteProfile(int id)
|
||
|
{
|
||
|
_profileService.Delete(id);
|
||
|
}
|
||
|
|
||
|
[RestPutById]
|
||
|
public ActionResult<AppProfileResource> Update(AppProfileResource resource)
|
||
|
{
|
||
|
var model = resource.ToModel();
|
||
|
|
||
|
_profileService.Update(model);
|
||
|
|
||
|
return Accepted(model.Id);
|
||
|
}
|
||
|
|
||
|
public override AppProfileResource GetResourceById(int id)
|
||
|
{
|
||
|
return _profileService.Get(id).ToResource();
|
||
|
}
|
||
|
|
||
|
[HttpGet]
|
||
|
public List<AppProfileResource> GetAll()
|
||
|
{
|
||
|
return _profileService.All().ToResource();
|
||
|
}
|
||
|
}
|
||
|
}
|