2017-08-15 16:31:19 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
|
using Bit.Core.Models.Api;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2017-08-19 08:51:05 -04:00
|
|
|
|
using Bit.Core.Exceptions;
|
2018-03-23 09:44:48 -04:00
|
|
|
|
using Bit.Core.Utilities;
|
2017-08-15 16:31:19 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
[Route("installations")]
|
|
|
|
|
|
[SelfHosted(NotSelfHostedOnly = true)]
|
|
|
|
|
|
public class InstallationsController : Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IInstallationRepository _installationRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public InstallationsController(
|
|
|
|
|
|
IInstallationRepository installationRepository)
|
|
|
|
|
|
{
|
|
|
|
|
|
_installationRepository = installationRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-19 09:56:55 -04:00
|
|
|
|
[HttpGet("{id}")]
|
2017-08-19 08:51:05 -04:00
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<InstallationResponseModel> Get(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var installation = await _installationRepository.GetByIdAsync(id);
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (installation == null)
|
2017-08-19 08:51:05 -04:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new InstallationResponseModel(installation, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-15 16:31:19 -04:00
|
|
|
|
[HttpPost("")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
public async Task<InstallationResponseModel> Post([FromBody] InstallationRequestModel model)
|
|
|
|
|
|
{
|
|
|
|
|
|
var installation = model.ToInstallation();
|
|
|
|
|
|
await _installationRepository.CreateAsync(installation);
|
2017-08-19 08:51:05 -04:00
|
|
|
|
return new InstallationResponseModel(installation, true);
|
2017-08-15 16:31:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|