-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkItemFunctions.cs
More file actions
72 lines (64 loc) · 2.21 KB
/
WorkItemFunctions.cs
File metadata and controls
72 lines (64 loc) · 2.21 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using AzureDevOpsStateTracker.Functions.Extensions;
using AzureDevopsTracker.DTOs.Create;
using AzureDevopsTracker.DTOs.Update;
using AzureDevopsTracker.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Net;
using System.Threading.Tasks;
namespace AzureDevOpsTracker.Functions
{
public class WorkItemFunctions
{
private readonly AzureDevopsTrackerService _azureDevopsTrackerService;
public WorkItemFunctions(
AzureDevopsTrackerService azureDevopsTrackerService)
{
_azureDevopsTrackerService = azureDevopsTrackerService;
}
[FunctionName("workitem")]
public async Task<IActionResult> Create(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
try
{
var workItemDTO = JsonConvert.DeserializeObject<CreateWorkItemDTO>(req.GetBody());
await _azureDevopsTrackerService.Create(workItemDTO);
}
catch (Exception ex)
{
return new OkObjectResult(ex.Message);
}
return new OkObjectResult(HttpStatusCode.OK);
}
[FunctionName("workitem-update")]
public async Task<IActionResult> Update(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
try
{
var workItemDTO = JsonConvert.DeserializeObject<UpdatedWorkItemDTO>(req.GetBody());
await _azureDevopsTrackerService.Update(workItemDTO);
}
catch (Exception ex)
{
return new OkObjectResult(ex.Message);
}
return new OkObjectResult(HttpStatusCode.OK);
}
[FunctionName("ping")]
public IActionResult Ping(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
{
return new OkObjectResult("Ok - Ping");
}
}
}