diff --git a/Dapplo.Jira/Entities/BaseId.cs b/Dapplo.Jira/Entities/BaseId.cs index 3d5b14d..fe9f0cb 100644 --- a/Dapplo.Jira/Entities/BaseId.cs +++ b/Dapplo.Jira/Entities/BaseId.cs @@ -21,6 +21,7 @@ #region using +using System.ComponentModel; using System.Runtime.Serialization; #endregion @@ -36,7 +37,7 @@ public class BaseId /// /// Id of this entity /// - [DataMember(Name = "id", EmitDefaultValue = false)] + [DataMember(Name = "id", EmitDefaultValue = false), ReadOnly(true)] public TId Id { get; set; } } } \ No newline at end of file diff --git a/Dapplo.Jira/Entities/BaseProperties.cs b/Dapplo.Jira/Entities/BaseProperties.cs index 1b71f15..0e3d68e 100644 --- a/Dapplo.Jira/Entities/BaseProperties.cs +++ b/Dapplo.Jira/Entities/BaseProperties.cs @@ -22,6 +22,7 @@ #region using using System; +using System.ComponentModel; using System.Runtime.Serialization; #endregion @@ -37,7 +38,7 @@ public class BaseProperties : BaseId /// /// Link to itself /// - [DataMember(Name = "self", EmitDefaultValue = false)] + [DataMember(Name = "self", EmitDefaultValue = false), ReadOnly(true)] public Uri Self { get; set; } } } \ No newline at end of file diff --git a/Dapplo.Jira/Entities/Comment.cs b/Dapplo.Jira/Entities/Comment.cs index 5115416..fc4c3b5 100644 --- a/Dapplo.Jira/Entities/Comment.cs +++ b/Dapplo.Jira/Entities/Comment.cs @@ -22,6 +22,7 @@ #region using using System; +using System.ComponentModel; using System.Runtime.Serialization; #endregion @@ -38,7 +39,7 @@ public class Comment : BaseProperties /// /// Who created the comment /// - [DataMember(Name = "author", EmitDefaultValue = false)] + [DataMember(Name = "author", EmitDefaultValue = false), ReadOnly(true)] public User Author { get; set; } /// @@ -50,19 +51,19 @@ public class Comment : BaseProperties /// /// When was the comment created /// - [DataMember(Name = "created", EmitDefaultValue = false)] + [DataMember(Name = "created", EmitDefaultValue = false), ReadOnly(true)] public DateTimeOffset Created { get; set; } /// /// Who updated the comment /// - [DataMember(Name = "updateAuthor", EmitDefaultValue = false)] + [DataMember(Name = "updateAuthor", EmitDefaultValue = false), ReadOnly(true)] public User UpdateAuthor { get; set; } /// /// When was the comment updated /// - [DataMember(Name = "updated", EmitDefaultValue = false)] + [DataMember(Name = "updated", EmitDefaultValue = false), ReadOnly(true)] public DateTimeOffset Updated { get; set; } /// diff --git a/Dapplo.Jira/IssueExtensions.cs b/Dapplo.Jira/IssueExtensions.cs index 9274248..761e952 100644 --- a/Dapplo.Jira/IssueExtensions.cs +++ b/Dapplo.Jira/IssueExtensions.cs @@ -58,7 +58,8 @@ public static class IssueExtensions /// the body of the comment /// optional visibility role /// CancellationToken - public static async Task AddCommentAsync(this IIssueDomain jiraClient, string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken)) + /// Comment + public static async Task AddCommentAsync(this IIssueDomain jiraClient, string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken)) { if (issueKey == null) { @@ -76,7 +77,8 @@ public static async Task AddCommentAsync(this IIssueDomain jiraClient, string is }; jiraClient.Behaviour.MakeCurrent(); var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment"); - await attachUri.PostAsync(comment, cancellationToken).ConfigureAwait(false); + var response = await attachUri.PostAsync>(comment, cancellationToken).ConfigureAwait(false); + return response.HandleErrors(HttpStatusCode.Created); } /// @@ -195,7 +197,8 @@ public static async Task> GetPossibleTransitionsAsync(this IIs /// jira key to which the comment belongs /// Comment to update /// CancellationToken - public static async Task UpdateCommentAsync(this IIssueDomain jiraClient, string issueKey, Comment comment, CancellationToken cancellationToken = default(CancellationToken)) + /// Comment + public static async Task UpdateCommentAsync(this IIssueDomain jiraClient, string issueKey, Comment comment, CancellationToken cancellationToken = default(CancellationToken)) { if (issueKey == null) { @@ -207,7 +210,8 @@ public static async Task UpdateCommentAsync(this IIssueDomain jiraClient, string jiraClient.Behaviour.MakeCurrent(); var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment", comment.Id); - await attachUri.PutAsync(comment, cancellationToken).ConfigureAwait(false); + var response = await attachUri.PutAsync>(comment, cancellationToken).ConfigureAwait(false); + return response.HandleErrors(); } /// @@ -241,7 +245,7 @@ public static async Task CreateAsync(this IIssueDomain jiraClient, Issue jiraClient.Behaviour.MakeCurrent(); var issueUri = jiraClient.JiraRestUri.AppendSegments("issue"); var response = await issueUri.PostAsync>(issue, cancellationToken).ConfigureAwait(false); - return response.HandleErrors(); + return response.HandleErrors(HttpStatusCode.Created); } /// @@ -265,12 +269,7 @@ public static async Task DeleteAsync(this IIssueDomain jiraClient, string issueK issueUri = issueUri.ExtendQuery("deleteSubtasks", true); } var response = await issueUri.DeleteAsync(cancellationToken).ConfigureAwait(false); - if (response.StatusCode != HttpStatusCode.NoContent) - { - var message = response.StatusCode.ToString(); - Log.Warn().WriteLine("Http status code: {0}. Response from server: {1}", response.StatusCode, message); - throw new Exception($"Status: {response.StatusCode} Message: {message}"); - } + response.HandleStatusCode(HttpStatusCode.NoContent); } ///