Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Updating
  • Loading branch information
DiegoGalante committed Aug 18, 2021
commit 6c28273e7c8793fc28ab63847af588a95a490cc7
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<UserSecretsId>035287d5-0b94-46fd-b3a9-b927fdb7b8ed</UserSecretsId>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.18" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
</ItemGroup>
<ItemGroup>
Expand Down
21 changes: 11 additions & 10 deletions AzureDevOpsStateTracker.Functions/WorkItemFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using AzureDevopsStateTracker.DTOs.Create;
using AzureDevopsStateTracker.DTOs.Update;
using AzureDevopsStateTracker.Services;
using AzureDevOpsStateTracker.Functions.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using AzureDevopsStateTracker.Services;
using AzureDevOpsStateTracker.Functions.Extensions;
using Newtonsoft.Json;
using AzureDevopsStateTracker.DTOs.Create;
using AzureDevopsStateTracker.DTOs.Update;
using System.Net;
using System;
using System.Net;
using System.Threading.Tasks;

namespace AzureDevOpsStateTracker.Functions
{
Expand All @@ -24,15 +25,15 @@ public WorkItemFunctions(
}

[FunctionName("workitem")]
public IActionResult Create(
public async Task<IActionResult> Create(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{

try
{
var workItemDTO = JsonConvert.DeserializeObject<CreateWorkItemDTO>(req.GetBody());
_azureDevopsStateTrackerService.Create(workItemDTO);
await _azureDevopsStateTrackerService.Create(workItemDTO);
}
catch (Exception ex)
{
Expand All @@ -43,14 +44,14 @@ public IActionResult Create(
}

[FunctionName("workitem-update")]
public IActionResult Update(
public async Task<IActionResult> Update(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
try
{
var workItemDTO = JsonConvert.DeserializeObject<UpdatedWorkItemDTO>(req.GetBody());
_azureDevopsStateTrackerService.Update(workItemDTO);
await _azureDevopsStateTrackerService.Update(workItemDTO);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion AzureDevopsStateTracker/AzureDevopsStateTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.18" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.16" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions AzureDevopsStateTracker/DTOs/Create/CreateWorkItemDTO.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace AzureDevopsStateTracker.DTOs.Create
{
public class CreateWorkItemDTO
{
[JsonPropertyName("resource")]
[JsonProperty("resource")]
public Resource Resource { get; set; }
}

public class Resource
{
[JsonPropertyName("id")]
[JsonProperty("id")]
public string Id { get; set; }

[JsonPropertyName("fields")]
[JsonProperty("fields")]
public Fields Fields { get; set; }
}
Expand Down
20 changes: 19 additions & 1 deletion AzureDevopsStateTracker/DTOs/Fields.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,76 @@
using Newtonsoft.Json;
using System;
using System.Text.Json.Serialization;

namespace AzureDevopsStateTracker.DTOs
{
public class Fields
{
[JsonPropertyName("System.AreaPath")]
[JsonProperty("System.AreaPath")]
public string AreaPath { get; set; }

[JsonPropertyName("System.TeamProject")]
[JsonProperty("System.TeamProject")]
public string TeamProject { get; set; }

[JsonPropertyName("System.IterationPath")]
[JsonProperty("System.IterationPath")]
public string IterationPath { get; set; }

[JsonPropertyName("System.AssignedTo")]
[JsonProperty("System.AssignedTo")]
public string AssignedTo { get; set; }

[JsonPropertyName("System.WorkItemType")]
[JsonProperty("System.WorkItemType")]
public string Type { get; set; }

[JsonPropertyName("System.CreatedDate")]
[JsonProperty("System.CreatedDate")]
public DateTime CreatedDate { get; set; }

[JsonPropertyName("System.CreatedBy")]
[JsonProperty("System.CreatedBy")]
public string CreatedBy { get; set; }

[JsonPropertyName("System.ChangedBy")]
[JsonProperty("System.ChangedBy")]
public string ChangedBy { get; set; }

[JsonPropertyName("System.State")]
[JsonProperty("System.State")]
public string State { get; set; }

[JsonPropertyName("System.Title")]
[JsonProperty("System.Title")]
public string Title { get; set; }

[JsonPropertyName("System.Tags")]
[JsonProperty("System.Tags")]
public string Tags { get; set; }

[JsonPropertyName("System.Parent")]
[JsonProperty("System.Parent")]
public string Parent { get; set; }
public string Parent { get; set; }

[JsonPropertyName("Microsoft.VSTS.Scheduling.StoryPoints")]
[JsonProperty("Microsoft.VSTS.Scheduling.StoryPoints")]
public string StoryPoints { get; set; }

[JsonPropertyName("Microsoft.VSTS.Scheduling.OriginalEstimate")]
[JsonProperty("Microsoft.VSTS.Scheduling.OriginalEstimate")]
public string OriginalEstimate { get; set; }

[JsonPropertyName("Microsoft.VSTS.Scheduling.RemainingWork")]
[JsonProperty("Microsoft.VSTS.Scheduling.RemainingWork")]
public string RemainingWork { get; set; }

[JsonPropertyName("Microsoft.VSTS.Scheduling.Effort")]
[JsonProperty("Microsoft.VSTS.Scheduling.Effort")]
public string Effort { get; set; }

[JsonPropertyName("Microsoft.VSTS.Common.Activity")]
[JsonProperty("Microsoft.VSTS.Common.Activity")]
public string Activity { get; set; }
}
Expand Down
23 changes: 14 additions & 9 deletions AzureDevopsStateTracker/DTOs/Update/UpdateWorkItemDTO.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,73 @@
using Newtonsoft.Json;
using System;
using System.Text.Json.Serialization;

namespace AzureDevopsStateTracker.DTOs.Update
{
public class UpdatedWorkItemDTO
{
[JsonPropertyName("resource")]
[JsonProperty("resource")]
public Resource Resource { get; set; }
}

public class Resource
{
[JsonPropertyName("workItemId")]
[JsonProperty("workItemId")]
public string WorkItemId { get; set; }

[JsonPropertyName("fields")]
[JsonProperty("fields")]
public ResourceFields Fields { get; set; }

[JsonPropertyName("revision")]
[JsonProperty("revision")]
public Revision Revision { get; set; }
}

public class Revision
{
[JsonPropertyName("fields")]
[JsonProperty("fields")]
public Fields Fields { get; set; }
}

public class ResourceFields
{
[JsonPropertyName("System.State")]
[JsonProperty("System.State")]
public OldNewValues State { get; set; }

[JsonPropertyName("Microsoft.VSTS.Common.StateChangeDate")]
[JsonProperty("Microsoft.VSTS.Common.StateChangeDate")]
public DateTimeOldNewValues StateChangeDate { get; set; }

[JsonPropertyName("System.ChangedBy")]
[JsonProperty("System.ChangedBy")]
public ChangedByOldNewValues ChangedBy { get; set; }
public OldNewValues ChangedBy { get; set; }
}

public class OldNewValues
{
[JsonPropertyName("oldValue")]
[JsonProperty("oldValue")]
public string OldValue { get; set; }

[JsonPropertyName("newValue")]
[JsonProperty("newValue")]
public string NewValue { get; set; }
}

public class DateTimeOldNewValues
{
[JsonPropertyName("oldValue")]
[JsonProperty("oldValue")]
public DateTime OldValue { get; set; }

[JsonPropertyName("newValue")]
[JsonProperty("newValue")]
public DateTime NewValue { get; set; }
}

public class ChangedByOldNewValues
{
[JsonProperty("oldValue")]
public string OldValue { get; set; }

[JsonProperty("newValue")]
public string NewValue { get; set; }
}
}
11 changes: 10 additions & 1 deletion AzureDevopsStateTracker/Data/DataBaseConfig.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
using AzureDevopsStateTracker.Extensions;
using System;
using System.Runtime.InteropServices;

namespace AzureDevopsStateTracker.Data
{
public class DataBaseConfig
{
public DataBaseConfig(string connectionsString, string schemaName = "dbo")
public DataBaseConfig(string connectionsString, string schemaName = "dbo", TimeZoneInfo timeZoneInfo = null)
{
if (connectionsString.IsNullOrEmpty())
throw new ArgumentException("The ConnectionsString is required");

if (timeZoneInfo == null)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
else
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Brazil/East");

ConnectionsString = connectionsString;
SchemaName = schemaName;
TimeZoneInfo = timeZoneInfo;
}

public static string ConnectionsString { get; private set; }
public static string SchemaName { get; private set; }
public static TimeZoneInfo TimeZoneInfo { get; private set; }
}
}
29 changes: 14 additions & 15 deletions AzureDevopsStateTracker/Data/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AzureDevopsStateTracker.Data
{
Expand All @@ -19,14 +19,14 @@ public Repository(AzureDevopsStateTrackerContext db)
DbSet = db.Set<TEntity>();
}

public virtual void Add(TEntity entity)
public virtual async Task Add(TEntity entity)
{
DbSet.Add(entity);
await DbSet.AddAsync(entity);
}

public virtual void Add(IEnumerable<TEntity> entities)
public virtual async Task Add(IEnumerable<TEntity> entities)
{
DbSet.AddRange(entities);
await DbSet.AddRangeAsync(entities);
}

public virtual void Update(TEntity entity)
Expand All @@ -44,22 +44,21 @@ public virtual void Delete(TEntity entity)
DbSet.Remove(entity);
}

public virtual TEntity GetById(string id)
public virtual async Task<TEntity> GetById(string id)
{
return DbSet
.Where(x => x.Id == id)
.FirstOrDefault();
return await DbSet
.FirstOrDefaultAsync(x => x.Id == id);
}

public bool Exist(string id)
public async Task<bool> Exist(string id)
{
return DbSet
.Any(x => x.Id == id);
return await DbSet
.AnyAsync(x => x.Id == id);
}
public void SaveChanges()

public async Task SaveChangesAsync()
{
Db.SaveChanges();
await Db.SaveChangesAsync();
}

public void Dispose()
Expand Down
Loading