public virtual async Task <IActionResult> Get(string id, CancellationToken cancellationToken) { IRestfulGrain <TState> grain = GetGrain(id); var v = await grain.Exists(); return(v ? base.Ok(await grain.Get()) : (IActionResult)base.NotFound()); }
public virtual async Task <IActionResult> Delete(string id, TResource resource, CancellationToken cancellationToken) { IRestfulGrain <TGrain> grain = GetGrain(id); var result = await grain.Delete <TResource>(resource); var state = await grain.Get(); return(Respond(state, result)); }
public virtual async Task <IActionResult> Patch(string id, TInput input, CancellationToken cancellationToken) { IRestfulGrain <TGrain> grain = GetGrain(id); var result = await grain.Patch(input); var state = await grain.Get(); return(Respond(state, result)); }
protected virtual async Task <IActionResult> ProcessRequest <TInput>( string id, MutationRequest type, TInput input, Func <TState, Result, IActionResult> responseFunc, CancellationToken cancellationToken) { IRestfulGrain <TState> grain = GetGrain(id); var result = await grain.Execute(new CustomRequest <TResource, TInput>(type, input)); return(responseFunc(await grain.Get(), result)); }
public virtual async Task <IActionResult> Post(string id, TResource input, CancellationToken cancellationToken) { IRestfulGrain <TGrain> grain = GetGrain(id); if (input is TGrain && await grain.Exists()) { return(Conflict()); } var result = await grain.Post(input); var state = await grain.Get(); return(Respond(state, result)); }
public virtual async Task <IActionResult> Put(string id, CancellationToken cancellationToken) { IRestfulGrain <TGrain> grain = GetGrain(id); using var streamReader = new StreamReader(this.Request.Body, Encoding.UTF8); var body = await streamReader.ReadToEndAsync(); var options = new JsonSerializerOptions().Configure(); try { if (this.Request.Headers.Keys.Contains("Metaflow-Batch")) { var input = JsonSerializer.Deserialize <List <TResource> >(body, options); var results = new List <Result>(); foreach (var i in input) { results.Add(await grain.Put(i)); } List <Result> errors = results.Where(r => !r.OK).ToList(); var state = await grain.Get(); return(!errors.Any() ? Ok(state) : (IActionResult)BadRequest(new { state, errors })); } else { var input = JsonSerializer.Deserialize <TResource>(body, options); var result = await grain.Put(input); var state = await grain.Get(); return(Respond(state, result)); } } catch (JsonException jex) { return(BadRequest(jex.Message)); } }