Files
server/src/Api/Controllers/InstallationsController.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.3 KiB
C#
Raw Normal View History

using Bit.Api.Models.Request;
2021-12-14 15:05:07 +00:00
using Bit.Api.Models.Response;
2017-08-19 08:51:05 -04:00
using Bit.Core.Exceptions;
2017-08-15 16:31:19 -04:00
using Bit.Core.Repositories;
2018-03-23 09:44:48 -04:00
using Bit.Core.Utilities;
2017-08-15 16:31:19 -04:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers;
2022-08-29 14:53:16 -04:00
2017-08-15 16:31:19 -04:00
[Route("installations")]
[SelfHosted(NotSelfHostedOnly = true)]
public class InstallationsController : Controller
{
private readonly IInstallationRepository _installationRepository;
2022-08-29 14:53:16 -04:00
2017-08-15 16:31:19 -04:00
public InstallationsController(
IInstallationRepository installationRepository)
{
_installationRepository = installationRepository;
2022-08-29 14:53:16 -04:00
}
2017-08-15 16:31:19 -04:00
2017-08-19 09:56:55 -04:00
[HttpGet("{id}")]
2017-08-15 16:31:19 -04:00
[AllowAnonymous]
public async Task<InstallationResponseModel> Get(Guid id)
2022-08-29 14:53:16 -04:00
{
2017-08-15 16:31:19 -04:00
var installation = await _installationRepository.GetByIdAsync(id);
if (installation == null)
{
throw new NotFoundException();
}
2017-08-19 08:51:05 -04:00
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
}
}