-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteObservation.cs
53 lines (47 loc) · 1.48 KB
/
DeleteObservation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using StarLog.Services;
using AutoMapper;
using StarLog.Extensions;
using Microsoft.Extensions.Primitives;
using System.Linq;
namespace StarLog.Functions
{
public class DeleteObservation
{
private readonly IObservationService _observationService;
public DeleteObservation(
IObservationService observationService,
IMapper mapper)
{
_observationService = observationService;
}
[FunctionName("DeleteObservation")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
string userId = req.ParseClaimsPrincipal().GetUserId();
bool deleted = false;
if (userId == null)
return new UnauthorizedResult();
if (req.Query.TryGetValue("id", out StringValues ids))
{
var observationId = ids.First();
deleted = await _observationService.DeleteObservationForUserAsync(observationId, userId);
}
if (deleted)
{
return new OkResult();
}
else
{
return new NotFoundResult();
}
}
}
}