diff --git a/PlanGrid.Api.Tests/RfisTests.cs b/PlanGrid.Api.Tests/RfisTests.cs index a771298..2482911 100644 --- a/PlanGrid.Api.Tests/RfisTests.cs +++ b/PlanGrid.Api.Tests/RfisTests.cs @@ -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 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() { @@ -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)); + } } } \ No newline at end of file diff --git a/PlanGrid.Api.Tests/TestData.cs b/PlanGrid.Api.Tests/TestData.cs index 8545390..83f7394 100644 --- a/PlanGrid.Api.Tests/TestData.cs +++ b/PlanGrid.Api.Tests/TestData.cs @@ -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 = "kirk+apitests@plangrid.com"; public const string ApiTestsUserUid = "5644e9acf0cb79476f1d48ee"; + public const string ApiTestsUser2Email = "kirk+apitests2@plangrid.com"; + public const string ApiTestsUser2Uid = "569e7cf89a5775ea157c9032"; public const string InvitedUserEmail = "kirk+apiinvitee@plangrid.com"; public const string AdminRoleId = "2fdbafe9"; } diff --git a/PlanGrid.Api/IPlanGridApi.cs b/PlanGrid.Api/IPlanGridApi.cs index a7b9a19..0566489 100644 --- a/PlanGrid.Api/IPlanGridApi.cs +++ b/PlanGrid.Api/IPlanGridApi.cs @@ -60,5 +60,14 @@ public interface IPlanGridApi : IDisposable [Get("/projects/{projectUid}/rfis/{rfiUid}/snapshots")] Task> GetRfiSnapshots(string projectUid, string rfiUid, int skip = Page.Skip, int limit = Page.Limit); + + [Patch("/projects/{projectUid}/rfis/statuses/{statusUid}")] + Task UpdateRfiStatus(string projectUid, string statusUid, [Body]RfiStatusUpdate statusUpdate); + + [Post("/projects/{projectUid}/rfis")] + Task CreateRfi(string projectUid, [Body]RfiUpsert rfi); + + [Patch("/projects/{projectUid}/rfis/{rfiUid}")] + Task UpdateRfi(string projectUid, string rfiUid, [Body]RfiUpsert rfi); } } \ No newline at end of file diff --git a/PlanGrid.Api/PlanGrid.Api.projitems b/PlanGrid.Api/PlanGrid.Api.projitems index 8e22dae..7e5e98b 100644 --- a/PlanGrid.Api/PlanGrid.Api.projitems +++ b/PlanGrid.Api/PlanGrid.Api.projitems @@ -28,7 +28,9 @@ + + diff --git a/PlanGrid.Api/PlanGridClient.cs b/PlanGrid.Api/PlanGridClient.cs index 455021b..bb05fff 100644 --- a/PlanGrid.Api/PlanGridClient.cs +++ b/PlanGrid.Api/PlanGridClient.cs @@ -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(new[] { new StringEnumConverter() diff --git a/PlanGrid.Api/RfiStatusUpdate.cs b/PlanGrid.Api/RfiStatusUpdate.cs new file mode 100644 index 0000000..1eea9eb --- /dev/null +++ b/PlanGrid.Api/RfiStatusUpdate.cs @@ -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; } + } +} diff --git a/PlanGrid.Api/RfiUpsert.cs b/PlanGrid.Api/RfiUpsert.cs new file mode 100644 index 0000000..18c5ed9 --- /dev/null +++ b/PlanGrid.Api/RfiUpsert.cs @@ -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; } + } +}