Greenfield: Add update store API (#1495)

* Greenfield: Add update store API

* update update store model

* change greenfield controller name to stop conflict
This commit is contained in:
Andrew Camilleri
2020-04-27 13:13:20 +02:00
committed by GitHub
parent b600e5777e
commit c784144a07
7 changed files with 127 additions and 8 deletions

View File

@@ -15,12 +15,12 @@ namespace BTCPayServer.Controllers.GreenField
{
[ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public class StoresController : ControllerBase
public class GreenFieldController : ControllerBase
{
private readonly StoreRepository _storeRepository;
private readonly UserManager<ApplicationUser> _userManager;
public StoresController(StoreRepository storeRepository, UserManager<ApplicationUser> userManager)
public GreenFieldController(StoreRepository storeRepository, UserManager<ApplicationUser> userManager)
{
_storeRepository = storeRepository;
_userManager = userManager;
@@ -73,6 +73,23 @@ namespace BTCPayServer.Controllers.GreenField
var store = await _storeRepository.CreateStore(_userManager.GetUserId(User), request.Name);
return Ok(FromModel(store));
}
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpPut("~/api/v1/stores/{storeId}")]
public async Task<ActionResult> UpdateStore(string storeId, UpdateStoreRequest request)
{
var store = HttpContext.GetStoreData();
if (store == null)
{
return NotFound();
}
if (request?.Name is null)
return BadRequest(CreateValidationProblem(nameof(request.Name), "Name is missing"));
store.StoreName = request.Name;
await _storeRepository.UpdateStore(store);
return Ok(FromModel(store));
}
private static Client.Models.StoreData FromModel(Data.StoreData data)
{