diff --git a/src/redmine-net-api/Net/RedmineApiUrls.cs b/src/redmine-net-api/Net/RedmineApiUrls.cs index 60788877..493bfa6a 100644 --- a/src/redmine-net-api/Net/RedmineApiUrls.cs +++ b/src/redmine-net-api/Net/RedmineApiUrls.cs @@ -112,6 +112,27 @@ public string CreateEntityFragment(string ownerId = null) { var type = typeof(T); + return CreateEntityFragment(type, ownerId); + } + public string CreateEntityFragment(RequestOptions requestOptions) + { + var type = typeof(T); + + return CreateEntityFragment(type, requestOptions); + } + internal string CreateEntityFragment(Type type, RequestOptions requestOptions) + { + string ownerId = null; + if (requestOptions is { QueryString: not null }) + { + ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ?? + requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID); + } + + return CreateEntityFragment(type, ownerId); + } + internal string CreateEntityFragment(Type type, string ownerId = null) + { if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership)) { return ProjectParentFragment(ownerId, TypeUrlFragments[type]); @@ -129,7 +150,7 @@ public string CreateEntityFragment(string ownerId = null) if (type == typeof(Upload)) { - return RedmineKeys.UPLOADS; + return $"{RedmineKeys.UPLOADS}.{Format}"; } if (type == typeof(Attachment) || type == typeof(Attachments)) @@ -144,6 +165,10 @@ public string CreateEntityFragment(string ownerId = null) { var type = typeof(T); + return GetFragment(type, id); + } + internal string GetFragment(Type type, string id) + { return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}"; } @@ -151,6 +176,10 @@ public string PatchFragment(string ownerId) { var type = typeof(T); + return PatchFragment(type, ownerId); + } + internal string PatchFragment(Type type, string ownerId) + { if (type == typeof(Attachment) || type == typeof(Attachments)) { return IssueAttachmentFragment(ownerId); @@ -163,6 +192,10 @@ public string DeleteFragment(string id) { var type = typeof(T); + return DeleteFragment(type, id); + } + internal string DeleteFragment(Type type,string id) + { return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}"; } @@ -170,6 +203,10 @@ public string UpdateFragment(string id) { var type = typeof(T); + return UpdateFragment(type, id); + } + internal string UpdateFragment(Type type, string id) + { return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}"; } @@ -179,8 +216,27 @@ public string UpdateFragment(string id) return GetListFragment(type, ownerId); } + + public string GetListFragment(RequestOptions requestOptions) where T : class, new() + { + var type = typeof(T); + + return GetListFragment(type, requestOptions); + } + + internal string GetListFragment(Type type, RequestOptions requestOptions) + { + string ownerId = null; + if (requestOptions is { QueryString: not null }) + { + ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ?? + requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID); + } + + return GetListFragment(type, ownerId); + } - public string GetListFragment(Type type, string ownerId = null) + internal string GetListFragment(Type type, string ownerId = null) { if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership)) { diff --git a/tests/redmine-net-api.Tests/Bugs/RedmineApi-371.cs b/tests/redmine-net-api.Tests/Bugs/RedmineApi-371.cs new file mode 100644 index 00000000..c77ac1c1 --- /dev/null +++ b/tests/redmine-net-api.Tests/Bugs/RedmineApi-371.cs @@ -0,0 +1,30 @@ +using System.Collections.Specialized; +using Padi.DotNet.RedmineAPI.Tests.Infrastructure; +using Redmine.Net.Api.Extensions; +using Redmine.Net.Api.Net; +using Redmine.Net.Api.Types; +using Xunit; + +namespace Padi.DotNet.RedmineAPI.Tests.Bugs; + +public sealed class RedmineApi371 : IClassFixture +{ + private readonly RedmineFixture _fixture; + + public RedmineApi371(RedmineFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void Should_Return_IssueCategories() + { + var result = _fixture.RedmineManager.Get(new RequestOptions() + { + QueryString = new NameValueCollection() + { + { "project_id", 1.ToInvariantString() } + } + }); + } +} \ No newline at end of file