mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
add request name validation
This commit is contained in:
parent
b7c0e049b5
commit
297b84a18b
@ -9,6 +9,7 @@ using BTCPayServer.Services.Stores;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace BTCPayServer.Controllers.GreenField
|
||||
{
|
||||
@ -67,8 +68,8 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
public async Task<ActionResult<Client.Models.StoreData>> CreateStore(CreateStoreRequest request)
|
||||
{
|
||||
if (request is null)
|
||||
return BadRequest();
|
||||
if (request?.Name is null)
|
||||
return BadRequest(CreateValidationProblem(nameof(request.Name), "Name is missing"));
|
||||
var store = await _storeRepository.CreateStore(_userManager.GetUserId(User), request.Name);
|
||||
return Ok(FromModel(store));
|
||||
}
|
||||
@ -81,5 +82,12 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
Name = data.StoreName
|
||||
};
|
||||
}
|
||||
|
||||
private ValidationProblemDetails CreateValidationProblem(string propertyName, string errorMessage)
|
||||
{
|
||||
var modelState = new ModelStateDictionary();
|
||||
modelState.AddModelError(propertyName, errorMessage);
|
||||
return new ValidationProblemDetails(modelState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user