Skip to content

Commit dac1749

Browse files
committed
Fix #371
1 parent 21a6baf commit dac1749

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/redmine-net-api/Net/RedmineApiUrls.cs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ public string CreateEntityFragment<T>(string ownerId = null)
112112
{
113113
var type = typeof(T);
114114

115+
return CreateEntityFragment(type, ownerId);
116+
}
117+
public string CreateEntityFragment<T>(RequestOptions requestOptions)
118+
{
119+
var type = typeof(T);
120+
121+
return CreateEntityFragment(type, requestOptions);
122+
}
123+
internal string CreateEntityFragment(Type type, RequestOptions requestOptions)
124+
{
125+
string ownerId = null;
126+
if (requestOptions is { QueryString: not null })
127+
{
128+
ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ??
129+
requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID);
130+
}
131+
132+
return CreateEntityFragment(type, ownerId);
133+
}
134+
internal string CreateEntityFragment(Type type, string ownerId = null)
135+
{
115136
if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
116137
{
117138
return ProjectParentFragment(ownerId, TypeUrlFragments[type]);
@@ -129,7 +150,7 @@ public string CreateEntityFragment<T>(string ownerId = null)
129150

130151
if (type == typeof(Upload))
131152
{
132-
return RedmineKeys.UPLOADS;
153+
return $"{RedmineKeys.UPLOADS}.{Format}";
133154
}
134155

135156
if (type == typeof(Attachment) || type == typeof(Attachments))
@@ -144,13 +165,21 @@ public string CreateEntityFragment<T>(string ownerId = null)
144165
{
145166
var type = typeof(T);
146167

168+
return GetFragment(type, id);
169+
}
170+
internal string GetFragment(Type type, string id)
171+
{
147172
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
148173
}
149174

150175
public string PatchFragment<T>(string ownerId)
151176
{
152177
var type = typeof(T);
153178

179+
return PatchFragment(type, ownerId);
180+
}
181+
internal string PatchFragment(Type type, string ownerId)
182+
{
154183
if (type == typeof(Attachment) || type == typeof(Attachments))
155184
{
156185
return IssueAttachmentFragment(ownerId);
@@ -163,13 +192,21 @@ public string DeleteFragment<T>(string id)
163192
{
164193
var type = typeof(T);
165194

195+
return DeleteFragment(type, id);
196+
}
197+
internal string DeleteFragment(Type type,string id)
198+
{
166199
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
167200
}
168201

169202
public string UpdateFragment<T>(string id)
170203
{
171204
var type = typeof(T);
172205

206+
return UpdateFragment(type, id);
207+
}
208+
internal string UpdateFragment(Type type, string id)
209+
{
173210
return $"{TypeFragment(TypeUrlFragments, type)}/{id}.{Format}";
174211
}
175212

@@ -179,8 +216,27 @@ public string UpdateFragment<T>(string id)
179216

180217
return GetListFragment(type, ownerId);
181218
}
219+
220+
public string GetListFragment<T>(RequestOptions requestOptions) where T : class, new()
221+
{
222+
var type = typeof(T);
223+
224+
return GetListFragment(type, requestOptions);
225+
}
226+
227+
internal string GetListFragment(Type type, RequestOptions requestOptions)
228+
{
229+
string ownerId = null;
230+
if (requestOptions is { QueryString: not null })
231+
{
232+
ownerId = requestOptions.QueryString.Get(RedmineKeys.PROJECT_ID) ??
233+
requestOptions.QueryString.Get(RedmineKeys.ISSUE_ID);
234+
}
235+
236+
return GetListFragment(type, ownerId);
237+
}
182238

183-
public string GetListFragment(Type type, string ownerId = null)
239+
internal string GetListFragment(Type type, string ownerId = null)
184240
{
185241
if (type == typeof(Version) || type == typeof(IssueCategory) || type == typeof(ProjectMembership))
186242
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Specialized;
2+
using Padi.DotNet.RedmineAPI.Tests.Infrastructure;
3+
using Redmine.Net.Api.Extensions;
4+
using Redmine.Net.Api.Net;
5+
using Redmine.Net.Api.Types;
6+
using Xunit;
7+
8+
namespace Padi.DotNet.RedmineAPI.Tests.Bugs;
9+
10+
public sealed class RedmineApi371 : IClassFixture<RedmineFixture>
11+
{
12+
private readonly RedmineFixture _fixture;
13+
14+
public RedmineApi371(RedmineFixture fixture)
15+
{
16+
_fixture = fixture;
17+
}
18+
19+
[Fact]
20+
public void Should_Return_IssueCategories()
21+
{
22+
var result = _fixture.RedmineManager.Get<IssueCategory>(new RequestOptions()
23+
{
24+
QueryString = new NameValueCollection()
25+
{
26+
{ "project_id", 1.ToInvariantString() }
27+
}
28+
});
29+
}
30+
}

0 commit comments

Comments
 (0)