Skip to content

Commit

Permalink
API-471: Add CreateRfi, UpdateRfi, UpdateRfiStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkplangrid committed Jan 19, 2016
1 parent 97aa1b2 commit bbcf831
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
88 changes: 88 additions & 0 deletions PlanGrid.Api.Tests/RfisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public async Task GetRfiStatuses()
Assert.AreEqual("#34b27d", statuses.Data[0].Color);
}

[Test]
public async Task UpdateRfiStatuses()
{
IPlanGridApi client = PlanGridClient.Create();
Page<RfiStatus> statuses = await client.GetRfiStatuses(TestData.Project1Uid);
Assert.AreEqual("draft", statuses.Data[0].Label);
await client.UpdateRfiStatus(TestData.Project1Uid, statuses.Data[0].Uid, new RfiStatusUpdate { Label = "draft2" });
statuses = await client.GetRfiStatuses(TestData.Project1Uid);
Assert.AreEqual("draft2", statuses.Data[0].Label);
await client.UpdateRfiStatus(TestData.Project1Uid, statuses.Data[0].Uid, new RfiStatusUpdate { Label = "draft" });
statuses = await client.GetRfiStatuses(TestData.Project1Uid);
Assert.AreEqual("draft", statuses.Data[0].Label);
}

[Test]
public async Task GetRfiComments()
{
Expand Down Expand Up @@ -99,5 +113,79 @@ public async Task GetRfiAttachments()
Assert.AreEqual(1, attachments.TotalCount);
Assert.AreEqual("PA1.11.pdf", attachments.Data[0].Name);
}

[Test]
public async Task CreateRfi()
{
IPlanGridApi client = PlanGridClient.Create();
var rfiInsert = new RfiUpsert
{
Question = "test question",
Answer = "test answer",
AssignedTo = new[] { TestData.ApiTestsUserUid },
DueDate = new DateTime(2020, 1, 1),
IsLocked = true,
SentDate = new DateTime(2019, 1, 1),
StatusUid = TestData.Project2DraftRfiStatusUid,
Title = "test title"
};
Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert);
Assert.AreEqual(rfiInsert.Question, rfi.Question);
Assert.AreEqual(rfiInsert.Answer, rfi.Answer);
Assert.AreEqual(rfiInsert.AssignedTo[0], rfi.AssignedTo[0].Uid);
Assert.AreEqual(rfiInsert.DueDate, rfi.DueDate);
Assert.AreEqual(rfiInsert.IsLocked, rfi.IsLocked);
Assert.AreEqual(rfiInsert.SentDate, rfi.SentDate);
Assert.AreEqual(rfiInsert.StatusUid, rfi.Status.Uid);
Assert.AreEqual(rfiInsert.Title, rfi.Title);
Assert.AreEqual(TestData.ApiTestsUserUid, rfi.CreatedBy.Uid);
Assert.AreNotEqual(rfi.CreatedAt, default(DateTime));
Assert.AreEqual(TestData.ApiTestsUserUid, rfi.UpdatedBy.Uid);
Assert.AreNotEqual(rfi.UpdatedAt, default(DateTime));
}

[Test]
public async Task UpdateRfi()
{
IPlanGridApi client = PlanGridClient.Create();
var rfiInsert = new RfiUpsert
{
Question = "test question",
Answer = "test answer",
AssignedTo = new[] { TestData.ApiTestsUserUid },
DueDate = new DateTime(2020, 1, 1),
IsLocked = true,
SentDate = new DateTime(2019, 1, 1),
StatusUid = TestData.Project2DraftRfiStatusUid,
Title = "test title"
};
Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert);

var rfiUpdate = new RfiUpsert
{
Question = "test question2",
Answer = "test answer2",
AssignedTo = new[] { TestData.ApiTestsUser2Uid },
DueDate = new DateTime(2020, 1, 2),
IsLocked = false,
SentDate = new DateTime(2019, 1, 2),
StatusUid = TestData.Project2OpenRfiStatusUid,
Title = "test title2"
};
rfi = await client.UpdateRfi(TestData.Project2Uid, rfi.Uid, rfiUpdate);

Assert.AreEqual(rfiUpdate.Question, rfi.Question);
Assert.AreEqual(rfiUpdate.Answer, rfi.Answer);
Assert.AreEqual(rfiUpdate.AssignedTo[0], rfi.AssignedTo[0].Uid);
Assert.AreEqual(rfiUpdate.DueDate, rfi.DueDate);
Assert.AreEqual(rfiUpdate.IsLocked, rfi.IsLocked);
Assert.AreEqual(rfiUpdate.SentDate, rfi.SentDate);
Assert.AreEqual(rfiUpdate.StatusUid, rfi.Status.Uid);
Assert.AreEqual(rfiUpdate.Title, rfi.Title);
Assert.AreEqual(TestData.ApiTestsUserUid, rfi.CreatedBy.Uid);
Assert.AreNotEqual(rfi.CreatedAt, default(DateTime));
Assert.AreEqual(TestData.ApiTestsUserUid, rfi.UpdatedBy.Uid);
Assert.AreNotEqual(rfi.UpdatedAt, default(DateTime));
}
}
}
5 changes: 5 additions & 0 deletions PlanGrid.Api.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public static class TestData
public const string Project1Uid = "d1e8e222-b05b-e750-74e4-d19b92c25506";
public const string Project1Issue1Uid = "45460feb-2c09-663f-352f-d053444b138a";
public const string Project1Rfi1Uid = "a3d1c702-3bed-c496-8cf0-6535218cce00";
public const string Project2Uid = "269ad633-0688-395e-5c30-cc685e0ce964";
public const string Project2DraftRfiStatusUid = "00a8b880";
public const string Project2OpenRfiStatusUid = "bcadf1c9";
public const string PhotoUrl = "https://photo-assets-test.plangrid.com/5a16f6d9-8006-ea7d-12ee-76c778b7094f.jpg";
public const string ApiTestsUserEmail = "[email protected]";
public const string ApiTestsUserUid = "5644e9acf0cb79476f1d48ee";
public const string ApiTestsUser2Email = "[email protected]";
public const string ApiTestsUser2Uid = "569e7cf89a5775ea157c9032";
public const string InvitedUserEmail = "[email protected]";
public const string AdminRoleId = "2fdbafe9";
}
Expand Down
9 changes: 9 additions & 0 deletions PlanGrid.Api/IPlanGridApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@ public interface IPlanGridApi : IDisposable

[Get("/projects/{projectUid}/rfis/{rfiUid}/snapshots")]
Task<Page<Snapshot>> GetRfiSnapshots(string projectUid, string rfiUid, int skip = Page.Skip, int limit = Page.Limit);

[Patch("/projects/{projectUid}/rfis/statuses/{statusUid}")]
Task<RfiStatus> UpdateRfiStatus(string projectUid, string statusUid, [Body]RfiStatusUpdate statusUpdate);

[Post("/projects/{projectUid}/rfis")]
Task<Rfi> CreateRfi(string projectUid, [Body]RfiUpsert rfi);

[Patch("/projects/{projectUid}/rfis/{rfiUid}")]
Task<Rfi> UpdateRfi(string projectUid, string rfiUid, [Body]RfiUpsert rfi);
}
}
2 changes: 2 additions & 0 deletions PlanGrid.Api/PlanGrid.Api.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Project.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectUpdate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Rfi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RfiUpsert.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RfiStatus.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RfiStatusUpdate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Role.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Settings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Snapshot.cs" />
Expand Down
1 change: 1 addition & 0 deletions PlanGrid.Api/PlanGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static IPlanGridApi Create(string apiKey = null, string baseUrl = null, s
JsonSerializerSettings = new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
Converters = new List<JsonConverter>(new[]
{
new StringEnumConverter()
Expand Down
13 changes: 13 additions & 0 deletions PlanGrid.Api/RfiStatusUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace PlanGrid.Api
{
public class RfiStatusUpdate
{
[JsonProperty("label")]
public string Label { get; set; }
}
}
34 changes: 34 additions & 0 deletions PlanGrid.Api/RfiUpsert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace PlanGrid.Api
{
public class RfiUpsert
{
[JsonProperty("status")]
public string StatusUid { get; set; }

[JsonProperty("locked")]
public bool IsLocked { get; set; }

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("question")]
public string Question { get; set; }

[JsonProperty("answer")]
public string Answer { get; set; }

[JsonProperty("sent_date")]
public DateTime? SentDate { get; set; }

[JsonProperty("due_date")]
public DateTime? DueDate { get; set; }

[JsonProperty("assigned_to")]
public string[] AssignedTo { get; set; }
}
}

0 comments on commit bbcf831

Please sign in to comment.